Nginx安装
1.环境准备
yum insatall -y make gcc gcc-c++ pcre-devel
#pcre-devel -- pcre库
#安装openssl-devel
yum install -y openssl-devel
2.tar安装包
3.解压软件包并创建软连接
tar -xf nginx-1.22.0.tar.gz -C /usr/local/
ln -s /usr/local/nginx-1.22.0/ /usr/local/nginx
4、创建用户和组
groupadd -r nginx
useradd nginx -u 996 -r -g 996 -c "nginx user"
5.安装
cd /usr/local/nginx-1.22.0/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
6.创建服务脚本
#vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#systemctl daemon-reload
7.开启nginx
LVS-DR集群搭建
1.环境规划
node1 | 192.168.227.134 | lsv服务器 |
node2 | 192.168.227.135 | RS1 |
node3 | 192.168.227.137 | RS2 |
node4 | 192.168.227.138 | 测试主机 |
2.LSV配置
1. 安装ipvsadm:
[root@node1 ~]# yum install ipvsadm -y
2. 添加虚拟IP(vip):
[root@node1 ~]# nmcli con modify ens33 +ipv4.addresses 192.168.227.100/24
3. 重启网卡ens33:
[root@node1 ~]# nmcli con up ens33
4. ipvsadm命令操作:
[root@node1 ~]# ipvsadm -C ##清空ipvsadm配置
[root@node1 ~]# ipvsadm -At 192.168.227.100:80 -s rr [-p 20] ##配置LVS虚拟IP(VIP)
-p表示设置会话保持时间为20秒
[root@node1 ~]# ipvsadm -at 192.168.227.100:80 -r 192.168.227.135:80 -g [-w 2]
##配置后端真实服务器
[root@node1 ~]# ipvsadm -at 192.168.227.100:80 -r 192.168.227.137:80 -g
##配置后端真实服务器
[root@node1 ~]# ipvsadm -Ln ##查看ipvsadm配置
[root@node1 ~]# ipvsadm -D -t 192.168.227.100:80 -s wrr ##删除LVS虚拟IP配置
[root@node1 ~]# ipvsadm -d -t 192.168.227.100:80 -r 192.168.227.135:80
[root@node1 ~]# ipvsadm -d -t 192.168.227.100:80 -r 192.168.227.137:80
##删除后端真实服务器配置
3. 真实服务器配置:node2和node3两台真实服务器都要配置
1. 配置web页面:
[root@node2 ~]# yum install httpd
[root@node2 ~]# echo "`hostname -I`" > /var/www/html/index.html
[root@node3 ~]# echo "`hostname -I`" > /var/www/html/index.html
[root@node2 ~]# systemctl start httpd
2. 手工在RS端绑定VIP:将vip绑定在lo的子接口上:
[root@node2 ~]# ifconfig lo:100 192.168.227.100 netmask 255.255.255.255 up
3. 添加本机访问VIP的路由
[root@node2 ~]# route add -host 192.168.227.100 dev lo:100
4. 配置arp抑制:
[root@node2 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@node2 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@node2 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@node2 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
4.测试
[root@node4 ~]# for ((i=0;i<10;i++));
do
curl 192.168.227.100;
done;
192.168.227.13
192.168.227.12
192.168.227.13
192.168.227.12
192.168.227.13