• dwz.cn,dwz.cn唯一官网

  • 发布时间:2016-01-13 02:17 | 作者:yc | 来源:互联网 | 浏览:1200 次
  • dwz.cn,dwz.cn唯一官网

    Keepalived双主互备模型完成

    试验拓扑概述

    650) this.width=650;" src="/html/uploads/allimg/160113/021IIK7-0.jpg" title="1.png" width="755" height="434" border="0" hspace="0" vspace="0" style="width:755px;height:434px;" alt="wKioL1Yh9kiikMvFAAGsjRD3MxE742.jpg" />

    本次试验所触及的体系发行版别为:CentOS6.6-64bit;内核版别:2.6.32-504.el6.x86_64

    (nod1)Nginx署理1:设置设备摆设有nginx效劳,向外部声称一个公网ip回收外部客户端请求,网卡eth0桥接形式,设置设备摆设有内网ip172.16.13.11;eth1(1.1.1.2/24)仅主机形式,仿照与出口路由器通讯接口,nod1为VIP1的MASTER时,VIP(1.1.1.100/32)设置设备摆设于eth1的别号eth1:1上,若BACKUP节点搭档,将VIP2搬运到eth1:2上

    (nod22)nginx署理2:设置设备摆设nginx效劳,向外部声称一个公网ip回收外部客户端请求,网卡eth0桥接形式,设置设备摆设有内网ip172.16.13.22;eth1(1.1.1.3/24)仅主机形式,仿照与出口路由器通讯接口,nod22为VIP2的MASTER时,VIP(1.1.1.200/32)设置设备摆设于eth1的别号eth1:1上,若BACKUP节点搭档,将VIP1搬运到eth1:2上

    (nod33)web1:设置设备摆设有httpd效劳,担负回收前端署理效劳器的调整回收,网卡eth0桥接形式,设置设备摆设有内网ip172.16.13.33

    (nod44)web2:设置设备摆设有httpd效劳,担负回收前端署理效劳器的调整回收,网卡eth0桥接形式,设置设备摆设有内网ip172.16.13.44

    (nod55)仿照出口路由器,eth1(1.1.1.1/24)仅主机形式,eth0自定义收集vmnet10

    客户端网卡也毗连vmnet10

    试验道理

    Nod1和nod22上分袂向互联网声称一个公网IP(VIP1和VIP2)提供web效劳颠末DNS的轮询解析道理,会将来自不相同IP客户真个请求分袂分发至nod1和nod22上,当nod1或nod22中任意一个节点搭档停机,设置设备摆设在响应节点上的VIP地址会主动搬运到另一节点,然后确保了对外的效劳提供还是正常

    试验设置设备摆设:

    对付keepalived设置设备摆设参数先容,请访候http://imsupeng.blog.51cto.com//

    (nod33)设置设备摆设:IP 172.16.13.33/16,无需指定网关

    >>>封闭selinux,清空防火墙规矩

    [root@nod33 ~]# setenforce 0

    [root@nod33 ~]# iptables –F

    >>>装配httpd,提供网页文件

    [root@nod33 ~]# yum install -y httpd

    [root@nod33 ~]# echo "web on nod33" > /var/www/html/index.html

    [root@nod33 ~]# service httpd start

    (nod44)设置设备摆设:IP 172.16.13.44/16,无需指定网关

    >>>封闭selinux,清空防火墙规矩

    [root@nod44 ~]# setenforce 0

    [root@nod44 ~]# iptables –F

    >>>装配httpd,提供网页文件

    [root@nod44 ~]# yum install -y httpd

    [root@nod44 ~]# echo "web on nod44" > /var/www/html/index.html

    [root@nod44 ~]# service httpd start

    (nod1)设置设备摆设

    >>>封闭selinux,清空防火墙规矩

    [root@nod1 ~]# setenforce 0

    [root@nod1 ~]# iptables –F

    >>>洞开中间转发功用

    [root@nod1 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

    >>>网卡设置设备摆设如下————把稳:若虚拟机设置设备摆设前就把IP设置成如下,很大概致使收集yum源无法运用,能够将后边设置设备摆设完成后再修正网卡

    650) this.width=650;" src="/html/uploads/allimg/160113/021IIT3-1.jpg" title="2.png" alt="wKiom1Yh9leww3W8AAN9HaNtcgU087.jpg" />

    >>>由于keepalive的设置设备摆设前提有需要(1、主备节点时候同步;2、主备节点主机名有需如果运用hostname或uname –r指令获取的一贯,并且能互相解析);因而,需求修正主机名并增添主备节点的hosts文件解析

    [root@nod1 ~]# sed-I's/\(HOSTNAME=\).*/\1nod1/' /etc/sysconfig/network && hostname nod1

    [root@nod1 ~]# echo -e '127.0.0.1 nod1\n172.16.13.22 nod22' >> /etc/hosts

    [root@nod1 ~]# crontab -e

    ##修正crontab任务规划,增添如下内容,完成每3分钟主动时候同步

    */3 * * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn &> /dev/null && /sbin/hwclock -w

    >>>装配keepalived并设置设备摆设

    [root@nod1 ~]# yum install keepalived –y

    ##需事前设置设备摆设好yum源

    [root@nod1 ~]# vim /etc/keepalived/keepalived.conf

    ! Configuration File for keepalived

    global_defs {

    notification_email {

    root@localhost

    }

    notification_email_from kaadmin@nod1

    smtp_server 127.0.0.1

    smtp_connect_timeout 30

    router_id nod1

    }

    vrrp_instance VI_1 {##第一个为主

    state MASTER##VIP1的MASTER

    interface eth1

    virtual_router_id 13##两个实例此处有需要不相同

    priority 100##优先级应大年夜于MASTER

    advert_int 1

    authentication {

    auth_type PASS

    auth_pass 281fd7d6##两个实例的暗码也不能相同

    }

    virtual_ipaddress {

    1.1.1.100/32 dev eth1 label eth1:1

    }

    }

    vrrp_instance VI_2 {

    state BACKUP ##VIP2为BACKUP

    interface eth1

    virtual_router_id 23##两个实例此处有需要不相同

    priority 99##把稳优先级小于MASTER

    advert_int 1

    authentication {

    auth_type PASS

    auth_pass 1fd7d6##两个实例的暗码也不能相同

    }

    virtual_ipaddress {

    1.1.1.200/32 dev eth1 label eth1:2

    }

    }

    >>>将keepalived设置开机自启并发动

    [root@nod1 ~]# vim /etc/keepalived/keepalived.conf

    [root@nod1 ~]# chkconfig --add keepalived

    [root@nod1 ~]# chkconfig keepalived on

    [root@nod1 ~]# service keepalived start

    >>>编译装配nginx(需事前下载源码包,我已下载至/root目录下)

    1增添nginx组及nginx用户

    [root@nod1 ~]# groupadd -r nginx

    [root@nod1 ~]# useradd -r -M -g nginx -s /sbin/nologinnginx

    2解压源码包至/usr/local/src目录下并装配

    [root@nod1 ~]# tar xf /root/nginx-1.8.0.tar.gz -C /usr/local/src/

    [root@nod1 ~]# yum install gcc pcre-devel openssl openssl-devel

    ##装配gcc编译器,并事前处置惩罚寄托联系(nginx装配时所寄托的软件开拓包)

    [root@nod1 ~]# cd /usr/local/src/nginx-1.8.0/##切换至nginx打开目录

    [root@nod1 nginx-1.8.0]# ./configure --prefix=/usr/local/nginx \

    --error-log-path=/var/log/nginx/error.log \

    --http-log-path=/var/log/nginx/access.log \

    --pid-path=/var/run/nginx/nginx.pid \

    --lock-path=/var/lock/nginx.lock \

    --with-http_mp4_module --user=nginx \

    --group=nginx \

    --with-http_ssl_注册就送无需申请module \

    --with-http_flv_module \

    --with-http_stub_status_module \

    --with-http_gzip_static_module \

    --with-http_realip_module \

    --http-client-body-temp-path=/var/tmp/nginx/client/ \

    --http-proxy-temp-path=/var/tmp/nginx/proxy/ \

    --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

    --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

    --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre

    [root@nod1 nginx-1.8.0]# mkdir -pv /var/tmp/nginx/{client,proxy,fcgi,uwsgi,scgi}

    [root@nod1 nginx-1.8.0]# make && make install

    >>>设置设备摆设nginx反向负载均衡署理

    [root@nod1 ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

    ##备份设置设备摆设文件

    [root@nod1 ~]# vim /usr/local/nginx/conf/nginx.conf

    在http高低文中增添

    upstream httpdsrvs {

    server 172.16.13.33:80 weight=1;

    server 172.16.13.44:80 weight=1;

    }

    将默许server段的location删去,增添:

    location / {

    proxy_pass http://httpdsrvs/;

    }

    如图:

    650) this.width=650;" src="/html/uploads/allimg/160113/021IGX5-2.jpg" title="3.png" alt="wKioL1Yh9ouyUvgdAAJ5Rfronco715.jpg" />

    查看设置设备摆设文件,并发动nginx

    [root@nod1 ~]# /usr/local/nginx/sbin/nginx -t

    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

    [root@nod1 ~]# /usr/local/nginx/sbin/nginx

    ######运用物理机的浏览器测验负载均衡是不是见效(把稳测验时大概浏览器本身缓存致使测验有误,改写时需按住shift+F5)

    650) this.width=650;" src="/html/uploads/allimg/160113/021IG2H-3.jpg" title="4.png" alt="wKioL1Yh9peR-f6EAABbtZOswE0340.jpg" />650) this.width=650;" src="/html/uploads/allimg/160113/021IM437-4.jpg" title="5.png" alt="wKiom1Yh9nvS1JLVAABYII7m26Y386.jpg" />

    (nod22)设置设备摆设

    >>>封闭selinux,清空防火墙规矩

    [root@nod22 ~]# setenforce 0

    [root@nod22 ~]# iptables –F

    >>>洞开中间转发功用

    [root@nod22 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

    >>>网卡设置设备摆设如下————把稳:若虚拟机设置设备摆设前就把IP设置成如下,很大概致使收集yum源无法运用,能够将后边设置设备摆设完成后再修正网卡

    650) this.width=650;" src="/html/uploads/allimg/160113/021IH557-5.jpg" title="6.png" alt="wKiom1Yh9oXh-vnmAAOd7Ou6E40632.jpg" />

    >>>由于keepalive的设置设备摆设前提有需要(1、主备节点时候同步;2、主备节点主机名有需如果运用hostname或uname –r指令获取的一贯,并且能互相解析);因而,需求修正主机名并增添主备节点的hosts文件解析

    [root@nod22 ~]# sed-I's/\(HOSTNAME=\).*/\1nod22/' /etc/sysconfig/network && hostname nod22

    [root@nod22 ~]# echo -e '127.0.0.1 nod22\n172.16.13.11 nod2' >> /etc/hosts

    [root@nod1 ~]# crontab -e

    ##修正crontab任务规划,增添如下内容,完成每3分钟主动时候同步

    */3 * * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn &> /dev/null && /sbin/hwclock -w

    >>>装配keepalived并设置设备摆设

    [root@nod22 ~]# yum install keepalived –y

    [root@nod22 ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

    ##备份设置设备摆设文件,若设置设备摆设同伴可随时康复

    [root@nod22 ~]# vim /etc/keepalived/keepalived.conf

    ##修正设置设备摆设文件

    ! Configuration File for keepalived

    global_defs {

    notification_email {

    root@localhost

    }

    notification_email_from kaadmin@nod22

    smtp_server 127.0.0.1

    smtp_connect_timeout 30

    router_id nod22##把稳修正

    }

    vrrp_instance VI_1 {

    state BACKUP ##把稳修正

    interface eth1

    virtual_router_id 13

    priority 99##把稳修正

    advert_int 1

    authentication {

    auth_type PASS

    auth_pass 281fd7d6##把稳修正,与此实例的MASTER维持同等

    }

    virtual_ipaddress {

    1.1.1.100/32 dev eth1 label eth1:1

    }

    }

    vrrp_instance VI_2 {

    state MASTER ##把稳修正

    interface eth1

    virtual_router_id 23

    priority 100##把稳修正

    advert_int 1

    authentication {

    auth_type PASS

    auth_pass 1fd7d6##把稳修正,与此实例的MASTER维持同等

    }

    virtual_ipaddress {

    1.1.1.200/32 dev eth1 label eth1:2

    }

    }

    >>>将keepalived设置开机自启并发动

    [root@nod22 ~]# vim /etc/keepalived/keepalived.conf

    [root@nod22 ~]# chkconfig --add keepalived

    [root@nod22 ~]# chkconfig keepalived on

    [root@nod22 ~]# service keepalived start

    >>>编译装配nginx(需事前下载源码包,我已下载至/root目录下)

    1增添nginx组及nginx用户

    [root@nod22 ~]# groupadd -r nginx

    [root@nod22 ~]# useradd -r -M -g nginx -s /sbin/nologinnginx

    2解压源码包至/usr/local/src目录下并装配

    [root@nod22 ~]# tar xf /root/nginx-1.8.0.tar.gz -C /usr/local/src/

    [root@nod22 ~]# yum install gcc pcre-devel openssl openssl-devel

    ##装配gcc编译器,并事前处置惩罚寄托联系(nginx装配时所寄托的软件开拓包)

    [root@nod22 ~]# cd /usr/local/src/nginx-1.8.0/##切换至nginx打开目录

    [root@nod22 nginx-1.8.0]# ./configure --prefix=/usr/local/nginx \

    --error-log-path=/var/log/nginx/error.log \

    --http-log-path=/var/log/nginx/access.log \

    --pid-path=/var/run/nginx/nginx.pid \

    --lock马会免费资料-path=/var/lock/nginx.lock \

    --with-http_mp4_module --user=nginx \

    --group=nginx \

    --with-http_ssl_module \

    --with-http_flv_module \

    --with-http_stub_status_module \

    --with-http_gzip_static_module \

    --with-http_realip_module \

    --http-client-body-temp-path=/var/tmp/nginx/client/ \

    --http-proxy-temp-path=/var/tmp/nginx/proxy/ \

    --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

    --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

    --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre

    Keepalived+nginx双主互备模型实现

    [root@nod22 nginx-1.8.0]# mkdir -pv /var/tmp/nginx/{client,proxy,fcgi,uwsgi,scgi}

    [root@nod22 nginx-1.8.0]# make && make install

    >>>设置设备摆设nginx反向负载均衡署理

    [root@nod22 ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

    ##备份设置设备摆设文件

    [root@nod22 ~]# vim /usr/local/nginx/conf/nginx.conf

    在http高低文中增添

    upstream httpdsrvs {

    server 172.16.13.33:80 weight=1;

    server 172.16.13.44:80 weight=1;

    }

    将默许server段的location删去,增添:

    location / {

    proxy_pass http://httpdsrvs/;

    }

    查看设置设备摆设文件,并发动nginx

    [root@nod22 ~]# /usr/local/nginx/sbin/nginx -t

    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

    [root@nod22 ~]# /usr/local/nginx/sbin/nginx##发动nginx

    ######运用物理机的浏览器测验负载均衡是不是见效(把稳测验时大概浏览器本身缓存致使测验有误,改写时需按住shift+F5)

    650) this.width=650;" src="/html/uploads/allimg/160113/021IM106-7.jpg" title="7.png" alt="wKioL1Yh9rmRtDjCAABuRQxnIdc418.jpg" />650) this.width=650;" src="/html/uploads/allimg/160113/021IM3H-8.jpg" title="8.png" alt="wKioL1Yh9sGyxh4HAABxOX-RCpk817.jpg" />

    (nod55)的设置设备摆设

    >>>封闭selinux,清空防火墙规矩

    [root@nod55 ~]# setenforce 0

    [root@nod55 ~]# iptables –F

    Keepalived+nginx双主互备模型实现

    >>>洞开中间转发功用

    [root@nod55 ~]#echo 1 > /proc/sys/net/ipv4/ip_forward

    网卡设置设备摆设

    650) this.width=650;" src="/html/uploads/allimg/160113/021IK324-10.jpg" title="9.png" alt="wKiom1Yh9qazm0UIAADdcs9451k784.jpg" />

    测验

    第一步:测验节点搭档后,VIP能否主动搬运

    650) this.width=650;" src="/html/uploads/allimg/160113/021IK445-11.jpg" title="10.png" alt="wKiom1Yh9q7hKCR_AAMn6_l-wis330.jpg" />

    650) this.width=650;" src="/html/uploads/allimg/160113/021IG349-12.jpg" title="11.png" alt="wKioL1Yh9t2RuucNAANx1IZPKew571.jpg" />

    650) this.width=650;" src="/html/uploads/allimg/160113/021IMb5-13.jpg" title="12.png" alt="wKioL1Yh9uexv78-AAZmple_SwA277.jpg" />

    第二步:客户端测验网站是不是能正常负载均衡

    650) this.width=650;" src="/html/uploads/allimg/160113/021IJQ0-14.jpg" title="13.png" alt="wKiom1Yh9sygrzq8AAH4dxC6hAI420.jpg" />

    这篇文章出自 “Linux低级” 博客,请必须保存此出处http://imsupeng.blog.51cto.com//

  • 相关内容

友情链接: