wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
tar zxvf keepalived-1.1.19.tar.gz
cd keepalived-1.1.19
./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cd /etc/keepalived/
配置Keepalived
接下来, 是最重要的修改配置文件/etc/keepalived/keepalived.conf.
global_defs {
notification_email {
baowei@srt.com.cn }
notification_email_from baowei@srt.com.cn smtp_server 211.155.225.210
smtp_connect_timeout 30
router_id srtweb}vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass srt_L7switch
}
virtual_ipaddress {
192.168.200.100
}
}vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 52
priority 50
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass srt_L7switch
}
virtual_ipaddress {
192.168.200.200
}
}
执行 /etc/rc.d/init.d/keepalived start 启动keepalived后, 执行ip a, 你将看到类似的信息:
[root@node1 ~]# ip a
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:01:11:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.200.128/24 brd 192.168.200.255 scope global eth0
inet 192.168.200.100/32 scope global eth0
inet 192.168.200.200/32 scope global eth0
inet6 fe80::20c:29ff:fe01:112a/64 scope link可以看到, ServerA的网卡绑定了两个虚IP 192.168.200.100和192.168.200.200, 这时在第3台机器上ping这两个IP, 是可以通的.
然后, 按上面的方法安装ServerB. ServerB的keepalived.conf配置和ServerA基本相同, 但是, 把state MASTER和state BACKUP调换, priority 100和priority 50调换,router_id改为srtedu. 启动ServerB后, 再到ServerA上运行ip a, 你将看到
[root@node1 ~]# ip a
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:01:11:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.200.128/24 brd 192.168.200.255 scope global eth0
inet 192.168.200.100/32 scope global eth0
inet6 fe80::20c:29ff:fe01:112a/64 scope link192.168.200.200已经不见了, 因为被ServerB使用了, ServerB是这个IP的MASTER, 它有优先使用权. 这样, 两个IP的网络数据分别被两台服务器处理. 现在验证ServerB在出故障的情况, 将ServerB的网线拔掉, 然后在ServerA上执行ip a, 你将看到
[root@node1 ~]# ip a
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:01:11:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.200.128/24 brd 192.168.200.255 scope global eth0
inet 192.168.200.100/32 scope global eth0
inet 192.168.200.200/32 scope global eth0
inet6 fe80::20c:29ff:fe01:112a/64 scope link192.168.200.200又被ServerA使用了.
安装Nginx
1、创建供Nginx使用的组和帐号:
/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
2、编译安装rewrite模块支持包
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz
tar zxvf pcre-7.7.tar.gz
cd pcre-7.7/
./configure
make && make install
cd ../
3、编译安装Nginx
wget http://sysoev.ru/nginx/nginx-0.7.64.tar.gz
tar zxvf nginx-0.7.64.tar.gz
cd nginx-0.7.64/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module
make && make install
cd ../
4、备份默认nginx.conf配置文件
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.old
5、创建Nginx配置文件
#vi /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes 8;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
charset gb2312;