设为首页 收藏本站
查看: 1178|回复: 0

[经验分享] 基于lvs-dr模型的discuz负载均衡实现

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-5-30 09:08:20 | 显示全部楼层 |阅读模式
前言:
lvs-dr模型与之前的lvs-nat模型情况基本差不多,只是网络拓扑结构不同。

HostVS

OS:CentOS-7-x86_64
hostname:ws1
eno16777736: 10.0.0.60/8(DIP)
eno167777336:0: 10.0.0.61/32(VIP)
gateway:10.0.0.254

HostRS1
OS:CentOS-7-x86_64
hostname:ws2
eno16777736:10.0.0.101/8 (RIP1)
lo:0 10.0.0.61/32 (VIP)
gateway:10.0.0.254

HostRS2
OS:CentOS-7-x86_64
hostname:ws3
eno16777736:10.0.0.102/8(RIP2)
lo:0 10.0.0.61/32(VIP)
gateway:10.0.0.254

HostDB
OS:CentOS-7-x86_64
hostname:ws4
eno16777736: 10.0.0.202/8
gateway:10.0.0.254


时间同步:
1
2
# ntpdate cn.pool.ntp.org
# hwclock --sysohc




安装软件:
HostDB


安装二进制mariadb-5.5.46


安装NFS
1
# yum install -y nfs-utils




HostRS2

安装nginx,注意nginx属于epel源
1
# yum install-y nginx php-fpm php-mbstring php-mysql nfs-utils mariadb




HostRS1
安装nginx,注意nginx属于epel源
1
# yum install-y nginx php-fpm php-mbstring php-mysql nfs-utils mariadb




HostVS
安装LVS的cli接口程序ipvsadm
1
# yum install -y ipvsadm




配置集群

HostDB
配置mariadb
安全初始化完成后,创建discuz数据库和discuz用户,并授权其可远程操作数据库
1
2
3
4
5
6
7
# mysql_secure_installation
# mysql -u root -p

> create database discuz;
> create user 'discuz'@'lodalhost' identified by '123456';
> grant all privileges on discuz.* to 'discuz'@'%' identified by '123456';
> flush privileges;




配置NFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# mkdir /nfshare/
# ls -ld /nfshare/
drwxr-xr-x 2 root root 6 May 9 17:01 /nfshare/
# echo "/nfshare/ 10.0.0.101(rw,no_root_squash,async) 10.0.0.102(rw,no_root_squash,async)" > /etc/exports
# /etc/init.d/rpcbind start
Starting rpcbind:                        [  OK  ]
# /etc/init.d/nfs start
Starting NFS services:                      [  OK  ]
Starting NFS quotas:                      [  OK  ]
Starting NFS mountd:                        [  OK  ]
Starting NFS daemon:                       [  OK  ]
Starting RPC idmapd:                      [  OK  ]
# chkconfig rpcbind on
# chkconfig nfs on
# chkconfig rpcbind --list
rpcbind            0:off    1:off    2:on    3:on    4:on    5:on    6:off
# chkconfig nfs --list
nfs                0:off    1:off    2:on    3:on    4:on    5:on    6:off
# showmount -e 127.0.0.1
Export list for 127.0.0.1:
/nfshare/ 10.0.0.101,10.0.0.102

exportfs -avr  检查设置是否正确



注意:rpcbind和nfs两个服务启动顺序不能更换,否则会出问题

解压discuz的程序包至/nfsshare/目录
1
2
3
4
# mkdir /nfshare/discuz
# unzip /Discuz_X3.2_SC_UTF8.zip -d /nfshare/discuz/
# ls /nfshare/discuz/
readme  upload  utility




HostRS1


给RS配置VIP之前先要禁止RS响应VIP的ARP请求
1
2
3
4
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce




在本地回环接口别名lo:0上配置VIP,并增添路由

1
2
ifconfig lo:0 10.0.0.61 broadcast 10.0.0.61 netmask 255.255.255.255
route add -host 10.0.0.61 dev lo:0




测试链接HostDB上的mariadb
1
# mysql -h 10.0.0.202 -u discuz -p




挂载HostDB上的NFS共享存储目录,属主属组修改为apache
1
2
3
4
5
6
7
8
9
10
# showmount -e 172.18.64.202
Export list for 172.18.64.202:
/nfshare/ 10.0.0.101,10.0.0.102
# mkdir /htdocs
# ls -ld /htdocs/
drwxr-xr-x 2 root root 6 May 9 17:05 /htdocs/
# mount -t nfs 172.18.64.202:/nfshare /htdocs
# ls /htdocs/
discuz
# chown -R apache:apache /htdocs/discuz/




启动php-fpm
1
2
# systemctl start php-fpm.service
# ss -tnl | grep 9000




配置nginx的配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# vim /etc/nginx/nginx.conf
server {
        listen     80;
        server_name  ws2

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            root    /htdocs/discuz/upload;
            index index.html index.htm index.php;
        }

        location ~ \.php$ {
            root  /htdocs/discuz/upload;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;

            include /etc/nginx/fastcgi.conf;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# nginx
# ss -tnl | grep 80
LISTEN     0      128          *:80                       *:*




测试访问discuz安装页面主机加上最后的/
1
2
3
4
5
6
7
# curl -I http://10.0.0.101/install/
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Mon, 09 May 2016 10:23:50 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.16




HostRS2
配置同上

HostVS
配置VIP地址,并打开核心转发功能。
1
2
# ifconfig eno16777736:0 10.0.0.61 broadcast 10.0.0.61 netmask 255.255.255.255 up
# echo 1 > /proc/sys/net/ipv4/ip_forward




先使用rr调度算法,期望会话丢失情况出现,若出现会话丢失情况,改用sh调度算法再做测试,期望会话能够保持。
1
2
3
4
# ipvsadm -A -t 10.0.0.61:80 -s rr
# ipvsadm -a -t 10.0.0.61:80 -r 10.0.0.101:80 -g
# ipvsadm -a -t 10.0.0.61:80 -r 10.0.0.102:80 -g
# ipvsadm -Ln




测试验证:




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-223686-1-1.html 上篇帖子: LVS-NAT基于NFS存储部署Discuz 下篇帖子: 基于Lvs-nat模型的discuz负载均衡实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表