基于lvs-dr模型的discuz负载均衡实现

前言:

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



时间同步:

# ntpdate cn.pool.ntp.org
# hwclock --sysohc


安装软件:

HostDB


安装二进制mariadb-5.5.46

详细配置请入传送门:http://wscto.blog.51cto.com/11249394/1783131


安装NFS

# yum install -y nfs-utils


HostRS2


安装nginx,注意nginx属于epel源

# yum install-y nginx php-fpm php-mbstring php-mysql nfs-utils mariadb


HostRS1

安装nginx,注意nginx属于epel源

# yum install-y nginx php-fpm php-mbstring php-mysql nfs-utils mariadb


HostVS

安装LVS的cli接口程序ipvsadm

# yum install -y ipvsadm


配置集群


HostDB

配置mariadb

安全初始化完成后,创建discuz数据库和discuz用户,并授权其可远程操作数据库

# 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

# 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/目录

# 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请求

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,并增添路由

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

# mysql -h 10.0.0.202 -u discuz -p


挂载HostDB上的NFS共享存储目录,属主属组修改为apache

# 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

# systemctl start php-fpm.service
# ss -tnl | grep 9000


配置nginx的配置文件

# 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安装页面主机加上最后的/

# 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地址,并打开核心转发功能。

# 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调度算法再做测试,期望会话能够保持。

# 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


测试验证:




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章