项目要求:
(1) lvs 调度两台 nginx+php-fpm real-server,采用 dr 模型,调度算法为 rr
(2) mariadb 为 real-server 提供数据库,nfs 挂载至 2 台 real-server 提供文件
服务
项目环境:
LVS-SERVER( CentOS 7 )
DIP:172.18.99.6
VIP:172.18.99.66
PHP+REAL-SERVER1( CentOS 7 )
RIP:172.18.99.10
VIP:172.18.99.66
PHP+REAL-SERVER2( CentOS 7 )
RIP:172.18.99.11
VIP:172.18.99.66
MariaDB+NFS-SERVER( CentOS 6 )
IP:172.18.99.7
项目步骤:
一、配置 MariaDB+NFS-SERVER
(1)安装所需软件包
[root@node1 ~]# yum install -y nfs-utils rpcbind mysql-server nginx
[root@node1 ~]# mysql ## 创建数据库和授权用户
mysql> create database wpdb;
mysql> grant all on wpdb.* to ‘wpuser’@’172.18.99.%’ identified by ‘wppass’
mysql> exit
[root@node1 ~]# mkdir /data/
[root@node1 ~]# cd /data/
wget ftp://172.18.0.1/pub/Sources/sources/httpd/wordpress-4.3.1-zh_CN.zip
[root@node1 data]# unzip wordpress-4.3.1-zh_CN.zip
[root@node1 data]# chown -R nginx.nginx /data/wordpress
[root@node1 data]# vim /etc/exports
/data/wordpress 172.18.99.101
[root@node1 ~]# service nfs start
[root@node1 ~]# showmount -e 172.18.99.7 ## 查看 nfs 共享目录
二、配置 PHP+REAL-SERVER1
[root@centos7 ~]# yum install -y nginx php-fpm php-mysql nfs-utils
[root@centos7 ~]# mkdir -p /data/wordpress
[root@centos7 ~]# vim /etc/nginx/conf.d/wps.conf
server {
listen 80 default_server;
server_name www.magedu.com;
root /data/wordpress/;
index index.php index.html index.html;
location / {
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/data/wordpress/$fastcgi_script_name;
include fastcgi_params;
}
}
[root@centos7 nginx]# vim nginx.conf
default server ##注释或删除主配置文件里的 default server
[root@centos7 conf.d]# nginx
[root@centos7 conf.d]# systemctl start php-fpm
[root@centos7 conf.d]# mount 172.18.99.7:/data/wordpress /data/wordpress
[root@centos7 conf.d]# scp wps.conf 172.18.99.11:/etc/nginx/conf.d/wps.conf
[root@centos7 ~]# vim dr.sh ## 为 real-server 配置 vip
!/bin/bash
VIP=172.18.99.66
case “$1” in
start)
echo “配置 lvs Real Server 开始…”
ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up ## 配置 VIP
route add -host $VIP dev lo:0 ## 添加主机路由
限制响应和通告级别
echo “1” >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo “1” >/proc/sys/net/ipv4/conf/all/arp_ignore
echo “2” >/proc/sys/net/ipv4/conf/lo/arp_announce
echo “2” >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
echo “正在关闭 lvs Real server”
ifconfig lo:0 down
echo “0” >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo “0” >/proc/sys/net/ipv4/conf/all/arp_ignore
echo “0” >/proc/sys/net/ipv4/conf/lo/arp_announce
echo “0” >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo “用法:$0 {start|stop}”
exit 1
esac
[root@centos7 ~]# bash dr.sh start
配置 lvs Real Server 开始…
[root@centos7 ~]# scp dr.sh 172.18.99.11:/root/
[root@centos7 ~]# ip a
三、配置 PHP+REAL-SERVER2
[root@centos7 ~]# yum install -y nginx php-fpm php-mysql nfs-utils
[root@centos7 ~]# mkdir -p /data/wordpress
[root@centos7 ~]# mount 172.18.99.7:/data/wordpress /data/wordpress
[root@centos7 ~]# vim /etc/nginx/nginx.conf
default server ##注释或删除主配置文件里的 default server
[root@centos7 ~]# systemctl start php-fpm nginx
[root@centos7 ~]# bash dr.sh start
配置 lvs Real Server 开始…
四、配置 LVS-SERVER
[root@node2 ~]# yum install ipvsadm -y
[root@node2 ~]# ip addr add 172.18.99.66/16 dev eno16777736
[root@node2 ~]# ip a
[root@node2 ~]# ipvsadm -A -t 172.18.99.66:80 -s rr ##新增一个集群服务
[root@node2 ~]# ipvsadm -a -t 172.18.99.66:80 -r 172.18.99.10:80 -g
为集群添加 real-server
[root@node2 ~]# ipvsadm -a -t 172.18.99.66:80 -r 172.18.99.11:80 -g
[root@node2 ~]# ipvsadm -Ln ## 查看集群规则
原创文章,作者:mujianguo,如若转载,请注明出处:http://www.178linux.com/75966