#!/bin/bash
# BY kerryhu
# Please manual operation yum of before Operation.....
系統情況`:CentOS 5.5(定制安裝)
組件:
Base
Development Libraries
Development Tools
Editors
Text-based Internet
lvs-master:192.168.9.201
lvs-backup:192.168.9.202
vip:192.168.9.200
web1:192.168.9.203
web2:192.168.9.204
netmask:255.255.255.0
gateway:192.168.9.1
網絡拓撲:
echo "============================ 更新系統時間 ======================"
yum install -y ntp
ntpdate time.nist.gov
echo "00 01 * * * /usr/sbin/ntpdate time.nist.gov" /etc/crontab
echo “============================ 封鎖不消處事 =======================”
/root/del_servcie.sh # 附件中自界說劇本
echo “========================= 安裝ipvsadm、keepalived ==================”
[[email protected] ~]# cd /usr/local/src
[[email protected] ~]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
[[email protected] ~]# wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz
[[email protected] ~]# ln -sv /usr/src/kernels/2.6.18-194.el5-i686/ /usr/src/linux
[[email protected] ~]# tar -zxvf ipvsadm-1.24.tar.gz
[[email protected] ~]# cd ipvsadm-1.24
[[email protected] ~]# make;make install
[[email protected] ~]# cd ..
[[email protected] ~]# tar -zxvf keepalived-1.1.17.tar.gz
[[email protected] ~]# cd keepalived-1.1.17
[[email protected] ~]# ./configure
configure: error:
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files.
辦理步伐:
[[email protected] ~]# yum -y install openssl-devel
[[email protected] ~]# ./configure
[[email protected] ~]# make;make install
編譯的時候呈現這個提示,說明keepalived和內核團結了,假如不是這樣的,需要加上這個參數./configure --with-kernel-
dir=/kernel/path
Keepalived configuration
------------------------
Keepalived version : 1.1.17
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use LinkWatch : No
Use Debug flags : No
echo “======================= 設置keepalived ===========================”
[[email protected] ~]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
[[email protected] ~]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[[email protected] ~]# mkdir /etc/keepalived
[[email protected] ~]# cp /usr/local/sbin/keepalived /usr/sbin/
[[email protected] ~]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server smtp.163.com
# smtp_connect_timeout 30
router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
state MASTER #備份處事器大將MASTER改為BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 100 # 備份處事大將100改為90
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.9.200
#(假如有多個VIP,繼承換行填寫.)
}
}
virtual_server 192.168.9.200 80 {
delay_loop 6 #(每隔10秒查詢realserver狀態)
lb_algo wlc #(lvs 算法)
lb_kind DR #(Direct Route)
persistence_timeout 60 #(同一IP的毗連60秒內被分派到同一臺realserver)
protocol TCP #(用TCP協議查抄realserver狀態)
real_server 192.168.9.203 80 {
weight 100 #(權重)
TCP_CHECK {
connect_timeout 10 #(10秒無響應超時)
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.9.204 80 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
[[email protected] ~]# service keepalived start|stop
[[email protected] ~]# chkconfig –level 2345 keepalived on