您好,登錄后才能下訂單哦!
環境:
主keepalived服務器:192.168.80.100
從keepalived服務器: 192.168.80.101
Web服務器:192.168.80.102
192.168.80.103
在80.100虛擬機上:
systemctl stop firewalld //關閉防火墻
setenforce 0 //關閉監控
yum install lrz* -y //安裝上傳軟件
把keepalived包拉入
tar xf keepalived-1.4.2.tar.gz -C /opt/ //解壓keepalived-1.4.2文件到/opt
cd /opt/keepalived-1.4.2/
yum install gcc gcc-c++ make popt-devel kernel-devel openssl-devel -y
./configure --prefix=/
make && make install
cd /
cd /etc/
ls | grep keepalived
cd keepalived/
vi keepalived.conf //進入keepalived刪除所有內容并添加以下內容:
! Configuration File for keepalived
global_defs {
router_id LVS_01 //本服務器的名稱
}
vrrp_instance VI_1 { //定義VRRP熱備實例
state MASTER //熱備狀態,MASTER表示主服務器,BACKUP表示從服務器
interface ens32 //承載VIP地址的物理接口
virtual_router_id 51 //虛擬路由器的ID號,每個熱備組保持一致
priority 110 //優先級,數值越大優先級越高
advert_int 1 //通告間隔秒數(心跳頻率)
authentication { //熱備認證信息,每個熱備組保持一致
auth_type PASS //認證類型
auth_pass 6666 //密碼字符串
}
virtual_ipaddress { //指定漂移地址(VIP),可以有多個
192.168.80.188
}
}
virtual_server 192.168.80.188 80 { //虛擬服務器地址(VIP)、端口
delay_loop 6 //健康檢查的間隔時間(秒)
lb_algo rr //輪詢(rr)調度算法
lb_kind DR //直接路由(DR)群集工作模式
persistence_timeout 60 //連接保持時間(秒)
protocol TCP //應用服務器采用的是TCP協議
real_server 192.168.80.102 80 { //第一個Web服務器節點的地址、端口
weight 1 //節點的權重
TCP_CHECK { //健康檢查方式
connect_port 80 //檢查的目標端口
connect_timeout 3 //連接超時(秒)
nb_get_retry 3 //連接超時(秒)
delay_before_retry 3 //重試間隔
}
}
real_server 192.168.80.103 80 { //第二個Web服務器節點的地址、端口
weight 1 //節點的權重
TCP_CHECK { //健康檢查方式
connect_port 80 //檢查的目標端口
connect_timeout 3 //連接超時(秒)
nb_get_retry 3 //連接超時(秒)
delay_before_retry 3 //重試間隔
}
}
}
:wq //保存退出
service keepalived start
systemctl status keepalived //查看keepalived狀態
ip addr show dev ens32
modprobe ip_vs
yum install ipvsadm -y
service keepalived restart
ipvsadm -Ln //查看LVS虛擬服務器
在80.101虛擬機上:
systemctl stop firewalld //關閉防火墻
setenforce 0 //關閉監控
yum install lrz* -y //安裝上傳軟件
把keepalived包拉入
tar xf keepalived-1.4.2.tar.gz -C /opt/ //解壓keepalived-1.4.2文件到/opt
cd /opt/keepalived-1.4.2/
yum install gcc gcc-c++ make popt-devel kernel-devel openssl-devel -y
./configure --prefix=/
make && make install
modprobe ip_vs
yum install ipvsadm -y
vi /etc/keepalived/keepalived.conf //刪除所有內容并添加以下內容:
! Configuration File for keepalived
global_defs {
router_id LVS_02
}
vrrp_instance VI_1 {
state BACKUP
interface ens32
virtual_router_id 51
priority 105
advert_int 1
authentication {
auth_type PASS
auth_pass 6666
}
virtual_ipaddress {
192.168.80.188
}
}
virtual_server 192.168.80.188 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.80.102 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.80.103 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
:wq //保存退出
service keepalived start
systemctl status keepalived //查看keepalived狀態
————————————————————————————
在80.102虛擬機上:
systemctl stop firewalld
setenforce 0
yum install httpd -y //安裝httpd
vi /etc/httpd/conf/httpd.conf
ServerName www.example.com.80 前面的#去掉
cd /var/www/html/ //進入目錄
echo "<h2>SERVER AA</h2>" > index.html //在index.html添加內容
ls
cat index.html
systemctl start httpd
cd
ls
./web.sh
ifconfig //查找IP地址
在虛擬機80.103上:
systemctl stop firewalld
setenforce 0
yum install httpd -y //安裝httpd
vi /etc/httpd/conf/httpd.conf
ServerName www.example.com.80 前面的#去掉
cd /var/www/html/ //進入目錄
echo "<h2>SERVER BB</h2>" > index.html //在index.html添加內容
ls
cat index.html
systemctl start httpd
vi web.sh
里面添加以下內容
#!/bin/bash
#haha
ifconfig lo:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 dev lo:0
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
sysctl -p &>/dev/null
:wq //保存退出
chmod +x web.sh //設置權限
./web.sh
ifconfig //查找IP地址
scp web.sh root@192.168.80.102:/root/ //把地址傳送過去
yes
root密碼
網頁上輸入http:192.168.80.188
在80.103中
systemctl stop httpd //關閉httpd
在頁面上刷新成下面情況:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。