目录
一、基于 CentOS 7 构建 LVS-DR 群集
1、前期准备
1、关闭防火墙
2、安装ifconfig
3、准备四台虚拟机
2、在DS上
2.1、配置LVS虚拟IP
2.2、手工执行配置添加LVS服务并增加两台RS
2.3、查看配置
3、在RS端(第三台、第四台) 上
3.1、配置Web服务器
3.2、配置默认主页
3.3、启动服务
3.4、测试:在客户端访问web服务器
3.5、绑定VIP
3.6、配置主机路由
3.7、抑制ARP响应
4、在客户端上测试
二、配置nginx负载均衡
1、安装部署nginx
2、内网服务器151
3、内网服务器152
4、代理服务器150
5、客户端
[root@localhost ~]# systemctl stop firewalld
yum install net-tools.x86_64 -y
ip | 用途 |
192.168.226.150 | 客户端 |
192.168.226.151 | lvs |
192.168.226.152 | RS |
192.168.226.153 | RS |
安装ipvsadm
yum install ipvsadm -y
增加IP
ifconfig ens33:200 192.168.226.200 netmask 255.255.255.255 up
[root@localhost ~]# ipvsadm -C
[root@localhost ~]# ipvsadm -A -t 192.168.226.200:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.226.200:80 -r 192.168.226.151:80 -g
[root@localhost ~]# ipvsadm -a -t 192.168.226.200:80 -r 192.168.226.152:80 -g
yum install httpd -y
hostname -I 取地址
[root@backup ~]# echo "web test page, ip is `hostname -I`." > /var/www/html/index.html
[root@backup ~]# systemctl start httpd
[root@localhost ~]# curl 192.168.226.147
web test page, ip is 192.168.226.147 .
[root@localhost ~]# curl 192.168.226.148
web test page, ip is 192.168.226.148 .
ifconfig lo:200 192.168.226.200 netmask 255.255.255.255 up
route add -host 192.168.226.200 dev lo
调整内核参数,关闭arp响应
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
在linux系统上部署Nginx_搞笑狗的博客-CSDN博客
[root@localhost ~]# vim /etc/nginx/conf.d/vhost.conf
server {
listen 80;
server_name web1.yunjisuan.com;
location / {
root /usr/share/nginx/html/web1;
index index.html index.htm;
}
access_log /usr/share/nginx/html/web1/logs/access_bbs.log main;
}
[root@localhost ~]# mkdir -p /usr/share/nginx/html/web1/logs
[root@localhost ~]# echo "`hostname -I `web1" > /usr/share/nginx/html/web1/index.html
[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# vim /etc/nginx/conf.d/vhost.conf
server {
listen 80;
server_name web1.yunjisuan.com;
location / {
root /usr/share/nginx/html/web1;
index index.html index.htm;
}
access_log /usr/share/nginx/html/web1/logs/access_bbs.log main;
}
[root@localhost ~]# mkdir -p /usr/share/nginx/html/web1/logs
[root@localhost ~]# echo "`hostname -I `web1" > /usr/share/nginx/html/web1/index.html
[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# vim /etc/nginx/conf.d/lb_test.conf
upstream www_server_pools {
server 192.168.226.151:80 weight=1;
server 192.168.231.152:80 weight=1;
}
server {
listen 80;
server_name web1.haha.com;
location / {
proxy_pass http://www_server_pools;
proxy_set_header Host $host;
}
}
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.226.150 web1.haha.com
[root@localhost ~]# for ((i=1;i<=6;i++)); do curl web1.haha.com; done
192.168.226.152 web1
192.168.226.151 web1
192.168.226.152 web1
192.168.226.151 web1
192.168.226.152 web1
192.168.226.151 web1