Ansible + Corosync + Pacemaker + NFS for http High Availability

Source: Internet
Author: User

Ansible + Corosync + Pacemaker + NFS for http High Availability

Directory:

(1) experiment environment
(2) Preparations
(3) Configure basic configurations for node1 and node2
(4) deploying nfs using ansible
(5) deploying corosync and pacemaker using ansible
(6) Use ansible to install the crmsh Tool
(7) Use crmsh to configure http High Availability
(8) Verification
(9) Notes

(1) experiment environment
1.1 environment Topology

Use Ansible to efficiently deliver Docker containers

Batch manage remote servers using Ansible

Ansible installation configuration and simple use

Install and use the automation tool Ansible in CentOS 7

Functions and usage of Ansible and Docker

Ansible batch build LAMP Environment

1.2 required systems
Four VMS with CentOS6.5 installed

1.3 network, host and other preparation work
Host IP address and Host Name

Disable host firewall and Selinux
1.4 host usage
Node1 and node2: Install corosync + pacemaker to achieve httpd High Availability

Ansible-server: Installs ansible to automatically deploy, install, and configure the basic layer.

Nfs-server: nfs is installed for disk sharing.

(2) Preparations
2.1 install ansible-server
1) configure the epel Source

[Epel]
Name = epel
Using list = http://mirrors.Fedoraproject.org/mirrorlist? Repo = epel-$ releasever & arch = $ basearch
Enabled = 1
Gpgcheck = 0
Note: Because the packages required by ansible are provided in the epel Source

2) install ansible

[Root @ ansible-server ~] # Yum-y install ansible
2.2. directory used to create ansble-playbook
[Root @ ansible-server ~] # Mkdir-pv corosync/roles/{common, ha, crmsh, nfs}/{files, tasks, handlers, templates, vars, meta, default}
Brief descriptions of directories

Common: used for installation and configuration of some basic software, including ntp time synchronization, local source, and disk mounting.

Ha: used to install corosync, httpd, pacemaker packages, and configure corosync authentication and configuration files.

Crmsh: used to install the crmsh and pssh packages

Nfs: used to install nfs and start the nfs service.
2.3 create site. yml and ha. yml files
[Root @ ansible-server ~] # Touch corosync/ha. yml
[Root @ ansible-server ~] # Touch corosync/site. yml
Note: This file is not configured, but it must exist.

2.4 configure the hosts file under ansible.
[Root @ ansible-server ~] # Vim/etc/ansible/hosts
[Hbhosts] # node1 and node2 groups
192.168.80.153
192.168.80.152
[Nfs-Server] # nfs-server group
192.168.80.168
2.5 use the key to allow the two hosts to communicate with each other
[Root @ ansible-server ~] # Ssh-keygen-t rsa-p' # generate a key string
[Root @ ansible-server ~] # Ansible hbhosts-m copy-a 'src =/root /. ssh/id_rsa.pub dest =/root /. ssh/authorized_keys owner = root group = root mode = 600 '-k # copy the key string to each node through ansible

(3) Configure basic configurations for node1 and node2
3.1. Objectives
Attach a local disk
Note: Configure/etc/fstab on each node for automatic mounting.

Remove all yum sources

Configure the local yum source and copy it to each node

Install ntpdate and crontab, and use scheduled tasks to set time synchronization

Copy the local parsing file to/etc/hosts on each node, so that node1 and node2 can be parsed by name

Note: The following operations are performed on ansible-server:
3.2 configure the hosts file for inter-node communication
[Root @ ansible-server ~] # Vim corosync/roles/common/files/hosts
127.0.0.1 localhost. localdomain localhost4 localhost4.localdomain4
: 1 localhost. localdomain localhost6 localhost6.localdomain6
192.168.80.152 node1.windchaser.com node1
192.168.80.153 node2.windchaser.com node2
Used for communication between node1 and node2 hosts

3.3 set the local disc yum Source
[Root @ ansible-server ~] # Vim corosync/roles/common/files/local. repo
[Local]
Name = local repo
Baseurl = file: // mnt
Enabled = 1
Gpgcheck = 0
3.4 define common tasks
Objectives:

Automatic mounting of Optical Drive

Remove all default yum sources and copy the local. repo source to the corresponding directory.

Use scheduled tasks to set time for automatic synchronization
[Root @ ansible-server ~] # Vim corosync/roles/common/tasks/main. yml
-Name: mount media # automatically attach a cd
Mount: name =/mnt src =/dev/sr0 fstype = iso9660 opts = ro state = mounted
-Name: mkdir/tmp/repo
Shell: mkdir/tmp/repo
Args:
Creates:/tmp/repo
-Name: move * repo to/tmp
Shell: mv/etc/yum. repos. d/*/tmp/repo
-Name: copy local. repo to yum
Copy: src = local. repo dest =/etc/yum. repos. d/local. repo
-Name: yum ntpdate and crontab # Install ntpdate and crontab
Yum: name = {item} state = present
With_items:
-Ntp
-Cronie
Tags: inst ntp
-Name: hosts file
Copy: src = hosts dest =/etc/hosts
-Name: sync time # set the time for automatic synchronization
Cron: name = "sync time" minute = "*/3" job = "/usr/sbin/ntpdate ntp. api. bz &>/dev/null"
3.5 define YAML
[Root @ ansible-server ~] # Vim corosync/ha. yml
-Name: install and config corosync
Remote_user: root
Hosts: hbhosts
Roles:
-Common
3.6 run ansible-play to automatically deploy basic configurations
[Root @ ansible-server ~] # Ansible-playbook corosync/ha. yml
The previous operations will be automatically deployed. If all the operations are in the OK status, they will be normal. If an error occurs, check whether the corresponding configuration item has an error.

(4) deploying nfs using ansible
4.1 set the nfs-server shared directory
[Root @ ansible-server ~] # Vim corosync/roles/nfs/files/exports
/Web/htdocs 192.168.80.0/24 (rw)
4.2 create an http###file index.html for subsequent testing.
[Root @ ansible-server ~] # Vim corosync/roles/nfs/files/index.html
<H1> nfs-storage 4.3 define nfs tasks
[Root @ ansible-server ~] # Vim corosync/roles/nfs/tasks/main. yml
-Name: install nfs
Yum: name = nfs-utils state = present
-Name: copy exports
Copy: src = exports dest =/etc/exports
-Shell: mkdir/web/htdocs-pv
Args:
Creates:/web/htdocs
-Name: copy index.html
Copy: src#index.html dest =/web/htdocs
-Service: name = nfs state = started enabled = yes
Tags: start
4.4 define YAML
[Root @ ansible-server ~] # Vim corosync/ha. yml
-Name: install and config corosync
Remote_user: root
Hosts: hbhosts
Roles:
-Common
-Name: install nfs # Add the following items to avoid affecting node1 and node2.
Remote_user: root
Hosts: nfs-Server
Roles:
-Nfs
4.5 run ansible-play to automatically deploy nfs settings.
[Root @ ansible-server ~] # Ansible-playbook corosync/ha. yml

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.