Linux cluster overview and highly available software keepalived configuration, testing

Source: Internet
Author: User
Tags iptables

First, Linux cluster overview

1), according to the function divided into two categories: high availability and load balancing
High-availability cluster-pass
Often two servers, one work, and the other as redundancy, redundancy will take over as the service machine goes down.

2), the realization of high availability of open source software is:
Heartbeat, keepalived

Heartbeat: There are a lot of bugs, there is a long time not updated, not recommended.
3), load Balancing cluster
There needs to be a server as a dispatcher, which is responsible for distributing the user's request to the backend server, where in addition to the distributor, it is the server that serves the user, the number of which is at least 2
The open source software for load balancing is:
LVS, keepalived, Haproxy, Nginx,
Business has F5, Netscaler cost high, advantages: higher concurrency, good stability.

Second, high-availability open source software keepalived Introduction

1), we use keepalived to achieve high-availability clusters, because heartbeat has some problems on CENTOS6, affecting the experimental results;
2), keepalived through VRRP (Virtual Router redundancy Protocl) to achieve high availability.
3), in this protocol will be more than the same function of the router to form a team, the team will have 1 master roles and N (n>=1) backup roles.
Master sends the VRRP protocol packets to each backup through multicast, and when backup does not receive the VRRP packets from master, it is considered master down. At this point, you need to decide who will be the new master based on the priority of each backup.
4),keepalived to have three modules, namely core, check and VRRP.
Core module is the kernel of keepalived, which is responsible for initiating and maintaining the main process and loading and settling the global configuration files.
Check module is responsible for health inspection;
The VRRP module is to implement the VRRP protocol.

Iii. Configuring high Availability with keepalived

1), prepare two machines A and b,a as master,b as backup; both machines perform Yum install-y keepalived
2), two machines are installed Nginx, installation Nginx:yum install-y Nginx (let which service to achieve high availability of our experimental nginx, and nginx can be used to do load balancing)
3), change the configuration file
Set VIP to 100
Edit keepalived configuration file on a
[Email protected] ~]# >/etc/keepalived/keepalived.conf
Clear the contents of the inside

/etc/keepalived/keepalived.conf Add the following content:

global_defs {                      #全局定义参数notification_email {            #定义邮箱[email protected]}notification_email_from [email protected]       #用哪一个邮箱发送smtp_server 127.0.0.1smtp_connect_timeout 30router_id LVS_DEVEL}

Vrrp_script Chk_nginx {#检测服务是否正常
Script "/usr/local/sbin/check_ng.sh" #shell要自己定
Interval 3 #检测间断时间3S
}

Vrrp_instance Vi_1 {#定义master
State MASTER
Interface Ens33 #指定网卡发广播
virtual_router_id Wuyi #定义路由ID
Priority #定义权重
Advert_int 1 #
Authentication {
Auth_type PASS #认证相关信息
Auth_pass aminglinux>com
}
virtual_ipaddress {#公有IP, master and slave are used.
192.168.188.100
}

track_script {                        #加载    chk_nginx}

}

     内容放也可以从https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D21Z/master_keepalived.conf获取 编辑a机器的监控脚本: vi /usr/local/sbin/check_ng.sh 定入以下内容:

#!/bin/bash
#时间变量, for logging
D=date --date today +%Y%m%d_%H:%M:%S
#计算nginx进程数量
n=ps -C nginx --no-heading|wc -l
#如果进程为0, the Nginx is started and the number of nginx processes is detected again.
#如果还为0, stating that Nginx could not start, you need to close keepalived
If [$n-eq "0"]; Then
/etc/init.d/nginx start
N2=ps -C nginx --no-heading|wc -l
If [$n 2-eq "0"]; Then
echo "$d Nginx down,keepalived'll Stop" >>/var/log/check_ng.log
Systemctl Stop keepalived
Fi
Fi

 内容也可以从https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D21Z/master_check_ng.sh获取 给检查脚本755权限: chmod 755 /usr/local/sbin/check_ng.sh systemctl start  keepalived a机器启动服务查看服务是否启动 pa aux |grep keep它的日志文件在:    /var/logs/messages 然后再查看它的IP地址: ip add 查看防火墙是不是开启,我们需要把它们关闭。iptables -nvLgetenforcesystemctl stop firewalld4)、配置从B机器从上编辑配置文件:清空原keepalived.conf文件内容:>/etc/keepalived/keepalived.conf编辑:vi /etc/keepalived/keepalived.conf  加入以下内容:

Global_defs {
Notification_email {br/>[email protected]

Notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Lvs_devel
}

Vrrp_script Chk_nginx {
Script "/usr/local/sbin/check_ng.sh"
Interval 3
}

Vrrp_instance Vi_1 {
State BACKUP
Interface Ens33
VIRTUAL_ROUTER_ID 51
Priority 90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass aminglinux>com
}
virtual_ipaddress {
192.168.188.100
}

track_script {    chk_nginx}

}

内容也可以从https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D21Z/backup_keepalived.conf获取我们要修改的地方有:权重改成90,让它变成从,虚拟IP改成跟主上一样的100,id保持一置。B机器从上编辑监控脚本,vi /usr/local/sbin/check_ng.sh加入以下内容:

#时间变量 for logging
d= date--date today +%y%m%d_%h:%m:%s
#计算nginx进程数量
n= ps-c nginx-- No-heading|wc-l
#如果进程为0, the Nginx is started, and the number of nginx processes is detected again,
#如果还为0, stating that Nginx cannot start, you need to close keepalived
If [$n-eq "0"]; Then
Systemctl start Nginx
n2= ps-c nginx--no-heading|wc-l
If [$n 2-eq "0"], then
echo "$d ng Inx down,keepalived would stop ">>/var/log/check_ng.log
Systemctl stop keepalived
Fi
Fi

内容从https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D21Z/backup_check_ng.sh获取 给脚本755权限 B从上也启动服务 systemctl start keepalived ps aux |grep keep6)、用yum安装的nginx访问页面目录在:/usr/share/nginx/html/index.html# 四、测试高可用先确定好两台机器上nginx差异,比如可以通过curl -I 来查看nginx版本 测试1:关闭master上的nginx服务: 开启了keepalived服务,nginx是关不掉的。 因为检测脚本: 测试2:在master上增加iptabls规则  iptables -I OUTPUT -p vrrp -j DROP不能测试到机器的切换服务 测试3:关闭master上的keepalived服务 访问IP100 ,直接跳到了从上。 测试4:启动master上的keepalived服务 访问IP100 ,直接跳到了主上。除了nginx可以配置高可用,mysql等都可以。

Linux cluster overview and highly available software keepalived configuration, testing

Related Article

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.