您好,登錄后才能下訂單哦!
這篇文章主要介紹“LINUX中Keepalive+lvs主從dr負載均衡怎么實現”,在日常操作中,相信很多人在LINUX中Keepalive+lvs主從dr負載均衡怎么實現問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”LINUX中Keepalive+lvs主從dr負載均衡怎么實現”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
1.1.1配置本地yum源
#mkdir /media/cdrom //創建cdrom目錄
#mkdir /etc/yum.repo.d/a //在yum源目錄中創建a目錄
#mv /etc/yum.repo.d/Cent* /etc/yum.repo.d/a //將以Cent開頭的所有文件拷貝到a目錄
#mount /dev/cdrom /media/cdrom //將光盤掛載到/media/cdrom/目錄下
#vim /etc/yum.repo.d/local.repo //編輯本地yum源文件
[base]
name=cets
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
#yum –y install openssl-devel //使用yum源安裝openssl-devel軟件
#yum –y install popt-devel //使用yum源安裝popt-devel軟件
#tar zxf keepalived-1.2.13.tar.gz //解壓keepalived軟件包
#cd keepalived-1.2.13 //進入解壓的文件夾中
#./configure -prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64 //編譯指定安裝路徑
#make && make install //編譯和安裝keepalived
本機ip 192.168.1.1
#cd /etc/keepalived/ //進入keepalived軟件主目錄
#cp keepalived.conf keepalived.conf.bak //備份keepalived主配置文件
#vim keepalived.conf //編輯keepalived主配置文件
router_id r1 //給該keepalived主機取名
state MASTER //該keepalived主機類型為主
priority 100 //優先級100
virtual_ipaddress {
192.168.1.254} //虛擬ip地址
#service keepalived restart //重啟服務
#service iptables stop //關閉防火墻
#service network restart //重啟網卡
本機ip 192.168.1.5
router_id r2
state SL**E 備注:也可以使用BACKUP
priority 99
virtual_ipaddress {
192.168.1.254}
Ip地址192.168.1.110
Service iptables stop
測試登陸192.168.1.25
關閉防火墻
開啟httpd
重啟keepalive
編輯測試網頁#vim /var/www/html/index.html
<h2>192.168.1.1<h2>
down掉主服務在測試機在訪問 192.168.1.254
關閉防火墻
開啟httpd
重啟keepalive
#ip addr show dev eth0 查看虛擬接口
編輯測試網頁#vim /var/www/html/index.html
<h2>192.168.1.5<h2>
router_id r1
state MASTER
priority 100
virtual_ipaddress {
192.168.1.254}
virtual_server 192.168.1.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.11 80 {
weight 1
TCP_CHECK {
connect-port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}}
}
virtual_server 192.168.1.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.22 80 {
weight 1
TCP_CHECK {
connect-port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}}
}
1.本地yum
2.安裝支持keepalive軟件包
3.編譯安裝keepalive
4.修改配置文件并啟用keepalive
復制備份 cp keepalive.conf keepalive.conf.bak
本機ip 192.168.1.5
router_id r2
state SL**E
priority 99
virtual_ipaddress {
192.168.1.254}
virtual_server 192.168.1.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.11 80 {
weight 1
TCP_CHECK {
connect-port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}}
}
5.安裝ipvsadm
yum –y install ipvsadm
ipvsadm –Lnc /Ln
192.168.1.11
#cd /etc/sysconfig/network-scripts
#cp ifcfg-lo ifcfg-lo:0
#vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.254
NETMASK=255.255.255.255
ONBOOT=yes
重啟服務service network restart
酌情添加
vi /etc/rc.local //添加VIP本地訪問路由
/sbin/route add -host 192.168.1.254 dev lo:0
# route add -host 192.168.1.254 dev lo:0
vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
sysctl -p
vi /var/www/html/index.html
<h2>192.168.1.11——測試網頁/<h2>
# service httpd start
# chkconfig httpd on
192.168.1.22
#cd /etc/sysconfig/network-scripts
#cp ifcfg-lo ifcfg-lo:0
#vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.254
NETMASK=255.255.255.255
ONBOOT=yes
重啟服務service network restart
酌情添加
vi /etc/rc.local //添加VIP本地訪問路由
/sbin/route add -host 192.168.1.254 dev lo:0
# route add -host 192.168.1.254 dev lo:0
vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
sysctl -p
vi /var/www/html/index.html
<h2>192.168.1.22/<h2>
# service httpd start
# chkconfig httpd on
配置ip 192.168.1.110
關閉防火墻能與其他主機通信
登陸192.168.1.254
主 ipvsadm -Ln
Down掉主keepalive
在登陸
登陸成功節點1 down點 在測試節點2
到此,關于“LINUX中Keepalive+lvs主從dr負載均衡怎么實現”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。