centos7负载均衡配置
现弄了三个虚拟机,ip分别为
从1:192.168.1.101
从2:192.168.1.102
主:192.168.1.104主服务器请求转发到从1,从2
通过文件共享,在windows下弄了两个目录,当做从站的目录
其中均只有一个index.php文件:
sso1输出的是:这是从机1
sso2输出的是:这是从机2
第一步:
三台服务器上均修改/etc/hosts,在其中加入一行:
127.0.0.1 user.yunindex.com
第二步,主服务器站点配置:
upstream sso{ server 192.168.1.101:80; server 192.168.1.102:80; } server { listen 80; server_name user.yunindex.com; location / { proxy_pass http://sso; proxy_set_header Host $host; } }
第三步,从服务器配置
从1:
server { listen 80; server_name user.yunindex.com; location / { root /share/www.sso1.com; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /share/www.sso1.com$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }
从2将上面的sso1改为sso2即可
重启nginx:service nginx restart
如果访问不了站点,记得关闭防火墙:service firewalld stop
第4步测试:
由于两台机器的权重是一样的,可以看到访问被平均分配到两台机器上了
奇怪的是,根据上面的配置,在浏览器中效果不一样:
在ie中是1:1分配的,在chrome中则经常被分配到同一台上,刷新很快则有可能分配到第二台上;
关于ip_hash方法的说明:
https://blog.csdn.net/sd4493091/article/details/54894479?utm_source=itdadao&utm_medium=referral
赞:(0)
踩:(0)
- 相关文章
- windows下使用MongoDB Compass Com
- Oracle VM VirtualBox中设置共享文
- linux安装openvpn并保存密码
- deepin v20深度系统安装docker及do
- 域名在阿里云服务器换成腾讯云后备
- windows下安装VirtualBox增强工具
- 国内访问github慢或打不开的解决方
- linux下安装phpstorm2018及激活码
- vmware中虚拟机上不了网及共享文件
- linux版phpstorm2020.3.3及激活码
- 热门文章
- win7中将文件拷贝到虚拟机linux下
- phpexcel设置行高及列宽,背景颜色,
- rabbitmq无法启动
- intellij idea不显示git push按钮
- php7中使用mongodb的aggregate进行
- laravel页面静态化的方法
- centos7.4 64位下swoole安装及配置
- navicate连接mycat报1184错误
- curl设置超时不起作用(CURLOPT_TIM
- devops-jenkins容器为pending状态
- 好评文章
- phpexcel设置行高及列宽,背景颜色,
- php7中使用mongodb的aggregate进行
- intellij idea打开文件所在文件夹
- windows下使用MongoDB Compass Com
- win7中将文件拷贝到虚拟机linux下
- laravel 中悲观锁 & 乐观锁的使用
- 单点登录sso原理及php实现方式及de
- navicate连接mycat报1184错误
- rabbitmq无法启动
- laravel整合dingo/api方法步骤:jwt
- 我的项目
- 【github】www.github.com/hurong241
- 【码云】gitee.com/hu_rong/projects
- 【docker hub】hub.docker.com/repositories/hurong241
- 【packagist】packagist.org/users/hurong241/packages
- 站点信息
- 建站时间:2011年
- 文章数:623篇
- 浏览数:1303109