我们使用最新的 ipvsadm-1.24.tar.gz,下载安装。 tar zxvf ipvsadm-1.24.tar.gz cd ipvsadm-1.24 make make install
第三步,安装keepalived 从http://www.keepalived.org上下载最新的keepalived-1.2.2.tar.gz。 tar zxvf keepalived-1.2.2.tar.gz cd keepalived-1.2.2 ./configure make make install 安装完毕。配置 (1): cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/ mkdir /etc/keepalived cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/ ln -s /usr/local/sbin/keepalived /usr/sbin/ service keepalived start 如果安装时的编译参数为: ./configure --prefix=/usr/local/keepalived 则操作步骤如下: cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ mkdir /etc/keepalived cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/ service keepalived start
以下为详细的配置文件
二、haproxy (1)、haproxy配置文件 haproxy.cfg global daemon chroot /usr/local/haproxy maxconn 256 user haproxy group haproxy log-send-hostname xiaokk.com log-tag my_xiaokk nbproc 1 pidfile /var/run/haproxy.pid log 127.0.0.1 local0 info defaults maxconn 256 mode http timeout connect 5000ms timeout client 50000ms timeout server 50000ms timeout check 2000 retries 3 option httpclose option httplog option dontlognull option forwardfor option redispatch option abortonclose frontend http-www bind 192.168.1.100:80 acl ha_policy hdr_reg(host) -i ^(www.test-haproxy.com|test-haproxy.com|demo.test-haproxy.com|www.hellobaby.com) acl ha_baby hdr_dom(host) -i hellobaby.com use_backend ha_www if ha_policy use_backend ha_www if ha_baby log 127.0.0.1 local0 info listen admin_status bind 192.168.1.100:1080 mode http log 127.0.0.1 local0 info stats uri /admin?status stats refresh 30s stats realm Haproxy/ Admin/ Center stats auth admin:admin stats hide-version backend ha_www mode http balance source cookie SERVERID option httpchk HEAD /index.html server w1 192.168.1.235:80 cookie 1 check inter 1500 rise 3 fall 3 weight 1 server w2 192.168.1.236:85 cookie 1 check inter 1500 rise 3 fall 3 weight 2 (2)、haproxy启却脚本 haproxy.sh
#!/bin/sh # # chkconfig: - 85 15 # description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly / # suited for high availability environments. # # processname: haproxy # config: /usr/local/haproxy/conf/haproxy.cfg # pidfile: /var/run/haproyx.pid #
# Source function library. if [ -f /etc/init.d/functions ]; then . /etc/init.d/functions elif [ -f /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions else exit 0 fi
# restart Haproxy restart() { /usr/local/haproxy/sbin/haproxy -c -q -f /usr/local/haproxy/conf/haproxy.cfg if [ $? -ne 0 ]; then echo "ERR found in configuration file, check it with 'haproxy check'." return 1 fi stop start }