32饿312 发表于 2016-9-26 10:32:54

HA Cluster基础及heartbeat实现HA

HA Cluster基础及heartbeat实现HA

配置环境
node1:192.168.1.121        CentOS6.7
node2:192.168.1.122        CentOS6.7
node3:192.168.1.123        CentOS6.7
vip 192.168.1.80

配置前准备
   # cat /etc/hosts
                127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
                ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
                192.168.1.121         node1
                192.168.1.122         node2
                192.168.1.123         node3
   #ssh-keygen -t rsa -P ''
   #ssh-copy-id -i ~/.ssh/id_rsa.pub node1
   #ssh-copy-id -i ~/.ssh/id_rsa.pub node2
   #ssh-copy-id -i ~/.ssh/id_rsa.pub node3               
   #rpm -ivh epel-release-latest-6.noarch.rpm
   #yum -y ansible
   #yum -y install ansible
   # cat /etc/ansible/hosts
               
                192.168.1.121
                192.168.1.122
                192.168.1.123
   #ansible ha -m copy -a 'src=/etc/hosts dest=/etc'               
   #ansible ha -m shell -a 'ntpdate 192.168.1.62'
   # ansible ha -m cron -a 'minute="*/3" job="/usr/sbin/ntpdate 192.168.1.62" name="ntpdate"'
   # ansible ha -m copy -a 'src=/root/heartbeat2 dest=/root'

   node1、node2和node3
   #yum -y install net-snmp-libs libnet PyXML perl-Time-Date
   # ls heartbeat2/
                heartbeat-2.1.4-12.el6.x86_64.rpm                                #主程序包
                heartbeat-debuginfo-2.1.4-12.el6.x86_64.rpm               
                heartbeat-devel-2.1.4-12.el6.x86_64.rpm                       
                heartbeat-gui-2.1.4-12.el6.x86_64.rpm                #提供hb-gui的包,可以先不装
                heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm        #后端健康检测的工具
                heartbeat-pils-2.1.4-12.el6.x86_64.rpm
                heartbeat-stonith-2.1.4-12.el6.x86_64.rpm        #提供仲裁设备,节点隔离的包       

        # cd heartbeat2/
        # rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm


        # cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,haresources,authkeys} /etc/ha.d/
        # cd /etc/ha.d/
        # chmod 600 authkeys
        # openssl rand -base64 4
                nuGXcw==
        # vim authkeys
        修改
                #auth 1
                #2 sha1 HI!
        为
                auth 2
                2 sha1 nuGXcw==
        # vim ha.cf
        修改
                #logfile    /var/log/ha-log
        为
                logfile    /var/log/ha-log
        修改
                logfacility local0
        为
                #logfacility    local0
        修改
                #mcast eth0 225.0.0.1 694 1 0
        为
                mcast eth0 225.23.190.1 694 1 0
        在node   kathy(212行左右)下添加
                node node1                #指明所有的node结束
                node node2
                node node3
        在#ping 10.10.10.254(223行左右)下添加
                ping 192.168.1.1                #仲裁设备
        修改
                #compression    bz2                        #是否压缩
                #compression_threshold 2        #多大的文件才压缩
        为
                compression bz2
                compression_threshold 2
        # vim haresources
        在末尾添加
                node1   192.168.1.80/16/eth0/192.168.255.255 httpd
        # scp -p authkeys ha.cf haresources node2:/etc/ha.d
        # scp -p authkeys ha.cf haresources node3:/etc/ha.d
        # vim /var/www/html/index.html
                <h1>node1.magedu.com</h1>
        # service httpd stop
        Stopping httpd:                                          
        # chkconfig httpd off
        # vim /var/www/html/index.html
                <h1>node2.magedu.com</h1>
        # service httpd stop
        Stopping httpd:                                          
        # chkconfig httpd off       
        # vim /var/www/html/index.html
                <h1>node3.magedu.com</h1>
        # service httpd stop
        Stopping httpd:                                          
        # chkconfig httpd off       
        # ansible ha -m service -a 'name=heartbeat state=started'

03        HA Cluster概念扩展及heartbeat实现
        使自己变成备用结点
                # /usr/lib64/heartbeat/hb_standby
        使用变回主结点
                # /usr/lib64/heartbeat/hb_takeover

        # mkdir /web/htdocs -pv
        # vim /web/htdocs/index.html
                <h1>Page On NFS Server</h1>
        # vim /etc/exports
                /web/htdocs   192.168.1.0/24(rw,no_root_squash)
        # service nfs start
        # service heartbeat stop;ssh node2 'service heartbeat stop'
        # cd /etc/ha.d/
        # vim haresources
        在末尾添加
                node1   192.168.1.80/16/eth0/192.168.255.255 Filesystem::192.168.1.123::/web/htdocs::/var/www/htm::nfs httpd
        # service heartbeat start;ssh node2 'service heartbeat start'


页: [1]
查看完整版本: HA Cluster基础及heartbeat实现HA