Chinaunix首页 | 论坛 | 博客
  • 博客访问: 239938
  • 博文数量: 49
  • 博客积分: 246
  • 博客等级: 二等列兵
  • 技术积分: 1034
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-02 13:18
文章分类

全部博文(49)

分类: 系统运维

2015-07-23 12:02:02


点击(此处)折叠或打开

  1. #!/bin/bash

  2. #BY_SA: qq 917611
  3. #2015/07/23
  4. # LVS_Keepalived 安装脚本 DR模式


  5. . /etc/rc.d/init.d/functions

  6. ipvsadm=" />
  7. keepalived=" />
  8. PROC=`grep -c processor /proc/cpuinfo`

  9. function kernel() {
  10.         while true;do
  11.     printf "please input kernel path: path: `ls /usr/src/kernels/`
  12.         /usr/src/kernels/2.6.32-504.30.3.el6.x86_64
  13.     \n"

  14.         read -p "please input Kernel path: " kernel
  15.     
  16.         if [ -z ${kernel} ];then
  17.                 continue
  18.         fi

  19.         if [ ! -d ${kernel} ];then
  20.                 echo "kernel path input error."
  21.                         continue
  22.         fi
  23.             break
  24. done
  25. }
  26. ipvsadm_install() {
  27.     curl -# -O ${ipvsadm}
  28.     tar xf ipvsadm-1.26.tar.gz
  29.     if [ $? -eq 0 ];then
  30.         cd ipvsadm-1.26
  31.         yum install -y gcc gcc-c++ makepcre pcre-devel kernel-devel openssl-devel libnl-devel popt-devel popt-static
  32.         make -j${PROC} && make install
  33.         which ipvsadm > /dev/null 2>&1 && printf "=========================================================
  34.                                         ipvsadm install success
  35.                         ===================================================================" \
  36.          || exit 1
  37.         sleep 2

  38.     else
  39.         echo "ipvsadm download failed."
  40.     fi
  41. }
  42. keepalived_install() {
  43.     curl -# -O ${keepalived}
  44.     tar xvf keepalived-1.2.10.tar.gz > /dev/null 2>&1
  45.     if [ $? -eq 0 ];then
  46.         cd keepalived-1.2.10
  47.          kernel
  48.         ./configure --sysconf=/etc --with-kernel-dir=${kernel}
  49.         make -j${PROC};make install
  50.         ls /etc/keepalived && echo "Keepalived Install success." || exit 1
  51.     else
  52.         echo "keepalived download failed."
  53.         exit 1
  54.     fi
  55. }
  56. keepalived_config() {
  57.     cp -a /etc/keepalived.conf /etc/keepalived.conf.$(date -I)
  58.     cat > /etc/keepalived/keepalived.conf << EOF
  59. ! Configuration File for keepalived

  60. global_defs {
  61.    notification_email {
  62.     917611@qq.com
  63.    }
  64.    notification_email_from Alexandre.Cassen@firewall.loc
  65.    smtp_server 127.0.0.1
  66.    smtp_connect_timeout 30
  67.    router_id LVS_DEVEL
  68. }

  69. vrrp_instance VI_1 {
  70.     state MASTER
  71.     interface eth0
  72.     virtual_router_id 51
  73.     priority 100
  74.     advert_int 1
  75.     authentication {
  76.         auth_type PASS
  77.         auth_pass 1111
  78.     }
  79.     virtual_ipaddress {
  80.         172.20.10.200
  81.     }
  82. }

  83. virtual_server 172.20.10.200 80 {
  84.     delay_loop 6
  85.     lb_algo rr
  86.     lb_kind DR
  87.     nat_mask 255.255.255.0
  88.     persistence_timeout 3
  89.     protocol TCP

  90. real_server 172.20.10.238 80 {
  91.         weight 1
  92.         TCP_CHECK {
  93.            connect_port 80
  94.            connect_timeout 3
  95.            nb_get_retry 3
  96.            delay_before_retry 3
  97.         }
  98. }

  99. real_server 172.20.10.239 80 {
  100.         weight 1
  101.         TCP_CHECK {
  102.            connect_port 80
  103.            connect_timeout 3
  104.            nb_get_retry 3
  105.            delay_before_retry 3
  106.         }
  107.     }
  108. }
  109. EOF
  110. }


  111. function real_server() {
  112.     echo "                ============================                "
  113.     echo "                real_server running script||                "
  114.     echo "                real_server running script||                "
  115.     echo "                real_server running script||                "
  116.     echo "                ===========================                "
  117.     sleep 1

  118. printf '
  119. #!/bin/bash
  120. VIP='172.20.10.200'
  121. . /etc/init.d/functions
  122.     case "$1" in
  123.      start)
  124.      /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
  125.      echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
  126.      echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
  127.      echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
  128.      echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
  129.      echo " LVS Real-Server Start Success"
  130.      ;;
  131.      stop)
  132.      /sbin/ifconfig lo:0 down
  133.      echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore
  134.      echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce
  135.      echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
  136.      echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
  137.      echo " LVS Real-Server Stop Success"
  138.      ;;
  139.      *)
  140.      echo "Usage: $0 ( start | stop )"
  141.      exit 1
  142.     esac\n'
  143.     printf "\n\n"
  144.     printf "======================================================================================\n"
  145. }

  146. #main
  147.     ipvsadm_install
  148.     keepalived_install
  149.     keepalived_config
  150.     real_server
  151. /etc/init.d/keepalived restart
  152. ipvsadm -Ln

阅读(2547) | 评论(0) | 转发(0) |
0

上一篇:python多线程Ping

下一篇:TCP/IP三次握手总结

给主人留下些什么吧!~~