设为首页 收藏本站
查看: 2362|回复: 0

[经验分享] 高可用集群corosync+pacemaker+drbd+httpd----自动配置篇

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-10-14 13:10:36 | 显示全部楼层 |阅读模式
本文结合shell+ansible实现高可用集群
实验拓扑图如下
wKioL1Q7NjnBnONJAAD9tvHTb6A711.jpg

首先利用yum安装ansible

配置过程如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[iyunv@node1 ~]# tree /etc/ansible/
/etc/ansible/
|-- ansible.cfg    ---------------ansible配置文件
|-- deploy.sh     ----------------安装脚本
|-- drbdha_1.yaml   
|-- drbdha_2.yaml
|-- hosts        ----------------ansible配置文件
`-- roles  
    |-- drbdha_1  ------------amsible角色1
    |   |-- files
    |   |   |-- ansible-1.5.4-1.el6.noarch.rpm
    |   |   |-- authkey   ------与手动篇文件相同
    |   |   |-- corosync.conf ------与手动篇文件相同
    |   |   |-- crmdrbd.txt
    |   |   |-- crmsh-1.2.6-4.el6.x86_64.rpm
    |   |   |-- drbd-8.4.3-33.el6.x86_64.rpm
    |   |   |-- drbd-kmdl-2.6.32-431.el6-8.4.3-33.el6.x86_64.rpm
    |   |   |-- global_common.conf  -------与手动篇文件相同
    |   |   |-- hosts
    |   |   |-- pssh-2.3.1-2.el6.x86_64.rpm
    |   |   `-- web.res
    |   |-- handlers
    |   |   `-- main.yaml
    |   |-- tasks
    |   |   `-- main.yaml
    |   |-- templates
    |   `-- vars
`-- drbdha_2  -----------------------ansible角色2
        |-- handlers
        |   `-- main.yaml
        `-- tasks
            `-- main.yaml
  
10 directories, 20 files



各文件内容如下
Ansible.cfg使用默认配置
Hosts文件
1
2
3
[drbdservers]
172.16.34.2 ansible_ssh_user=root ansible_ssh_pass=hzm132
172.16.34.3 ansible_ssh_user=root ansible_ssh_pass=hzm132





deploy.sh 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
#DES:install drbd+corosync
#author:centod
#date:2014-10-12
#ver:0.1
  
ROLEFIL1=./drbdha_1.yaml
ROLEFIL2=./drbdha_2.yaml
ansible-playbook $ROLEFIL1
[ -f /tmp/status.txt ] && rm -rf /tmp/status.txt
until false; do
    ansible-playbook -t filecopy $ROLEFIL1
    sleep 5
    if grep '%' /tmp/status.txt;then
       echo -e "*********************DATE SYNC IS NOT
               OK WAITING ^^********************"
       rm -rf /tmp/status.txt
       continue;
  
    else
       echo -e "*********************DATE SYNC IS
               OK ^^*************************"
       break;
    fi
done
ansible-playbook $ROLEFIL2






drbdha_1.yaml文件

1
2
3
4
5
- name: deploy hadrbd cluster
  remote_user: root
  hosts: drbdservers
  roles:
- drbdha_1






crmdrbd.txt文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
configure property stonith-enabled=false
configure property no-quorum-policy=ignore
configure commit
configure primitive drbd ocf:linbit:drbd
        params drbd_resource="web"
        op monitor role="Master" interval="20s" timeout="30s"
        op monitor role="Slave" interval="40s" timeout="30"
        op start timeout="240s" interval="0"
        op stop timeout="100s" interval="0"
configure primitive httpd lsb:httpd
        op monitor interval="20s" timeout="20s"
        op start timeout="20s" interval="0"
        op stop timeout="20s" interval="0"
        meta target-role="Started"
configure primitive httpd-storage ocf:heartbeat:Filesystem
        params device="/dev/drbd0" directory="/var/www/html" fstype="ext4"
        op monitor interval="20s" timeout="40s"
        op start timeout="60s" interval="0"
        op stop timeout="60s" interval="0"
        meta target-role="Started"
configure primitive vip ocf:heartbeat:IPaddr
        params ip="172.16.101.220"
        meta target-role="Started"
configure ms ms-webdrbd drbd
        meta master-max="1" master-node-max="1" clone-max="2"
        clone-node-max="1" notify="true" target-role="Started"
configure colocation storage-nrbd-master-httpd-vip inf: httpd-storage ms-webdrbd:Master httpd vip
configure order nrbd-storage-vip-httpd inf: ms-webdrbd:promote httpd-storage:start vip httpd
configure commit






web.res文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
resource web {
        on node2.centod.com {
        device /dev/drbd0;
        disk   /dev/sda3;
        address 172.16.34.2:7789;
        meta-disk internal;
        }
        on node3.centod.com {
        device /dev/drbd0;
        disk  /dev/sda3;
        address 172.16.34.3:7789;
        meta-disk internal;
      }
}






handlers-- main.yaml 文件内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
- name: build disk partition
  shell: echo -e "n  p  3   +2G  w " |fdisk /dev/sda || /bin/true
- name: partition flush
  shell: kpartx -af /dev/sda
  shell: partx  -a /dev/sda
  shell: partx  -a /dev/sda
- name: service configure
  copy: src={{ item.conf }} dest={{ item.destdir }}
  with_items:
    - { conf: global_common.conf,destdir: /etc/drbd.d/ }
    - { conf: web.res           ,destdir: /etc/drbd.d/ }
    - { conf: corosync.conf     ,destdir: /etc/corosync/ }
    - { conf: authkey           ,destdir: /etc/corosync  }
    - { conf: crmdrbd.txt       ,destdir: /etc/corosync  }
- name: init drbd device
  shell: drbdadm create-md web
  ignore_errors: True
- name: service restart
  service: name=corosync state=restarted
- name: modprobe
  shell: modprobe drbd
- name: chkconf off
  shell: chkconfig drbd off
  shell: chkconfig httpd off
- name: drbd start
  service: name=drbd state=restarted
- name: drbd promote
  shell: drbdadm primary --force web
  when: ansible_hostname == "node2"





-- tasks-- main.yaml 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
- name: deploy rpm pakages
  copy: src={{ item }} dest=/root/
  with_items:
        - crmsh-1.2.6-4.el6.x86_64.rpm
        - pssh-2.3.1-2.el6.x86_64.rpm
        - drbd-8.4.3-33.el6.x86_64.rpm
        - drbd-kmdl-2.6.32-431.el6-8.4.3-33.el6.x86_64.rpm
  notify:
        - install rpm
        - build disk partition
        - partition flush
        - service configure
        - init drbd device
        - service restart
        - modprobe
        - chkconf off
        - drbd start
        - drbd promote
- name: status file copy
  fetch: src=/proc/drbd dest=/tmp/status.txt flat=yes validate_md5=no
  when: ansible_hostname == "node2"
  tags: filecopy






drbdha_2.yaml文件


1
2
3
4
5
- name: deploy hadrbd cluster
  remote_user: root
  hosts: drbdservers
  roles:
- drbdha_2






handlers-- main.yaml文件
1
2
3
4
5
6
7
8
9
10
11
12
13
- name: mke2fs
  shell: mke2fs -t ext4 /dev/drbd0
  when: ansible_hostname == "node2"
- name: stop service
  service: name={{ item }} state=stopped
  with_items:
  - httpd
  - drbd
- name: configure corosync
  shell: crm -f /etc/corosync/crmdrbd.txt
  when: ansible_hostname == "node2"
- name: service restart
  service: name=corosync state=restarted







tasks-- main.yaml 文件内容


1
2
3
4
5
6
7
- name: part2
  shell: echo "part2 is start"
  notify:
    - mke2fs
    - stop service
    - configure corosync
- service restart




下面执行安装脚本
Bash deploy.sh
执行内容如下图

wKioL1Q7N0LgVNcDAARZEkjod8M128.jpg
wKiom1Q7NwvA7uo_AAVp14pRfVM360.jpg
wKioL1Q7N0LQJAMzAAPKltBo3lo993.jpg
wKiom1Q7NwzDE2WrAAPLrQiw27I594.jpg
wKioL1Q7N0OC8qB0AAODdwZQIFc817.jpg
wKioL1Q7N0PhVElxAAKXFM6VEHE088.jpg

执行结束后到部署的节点查看结果
wKioL1Q7N2Xj8uwYAALCDm0SPbo892.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-25970-1-1.html 上篇帖子: 基于Corosync和Pacemaker实现Web服务的高可用 下篇帖子: 高可用集群corosync+pacemaker+drbd+httpd----手动配置篇
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表