centos7+pacemaker+corosync+haproxy实现高可用

1.架构准备

系统是centos7-1511,实验需要准备4台主机,虚拟机也行,架构如下:

2 .系统环境配置

ha1:192.168.0.11

ha2:192.168.0.12

以下的安装配置分别在这2台机器上进行。

1.关闭防火墙和SELinux

systemctl disable firewalld
systemctl stop firewalld
iptables –F
 
修改配置文件vim /etc/selinux/config,将SELINU置为disabled
也可使用命令:
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

2.2台主机分别修改hostname为ha1和ha2
hostnamectl --static --transient  set-hostname ha1
hostnamectl --static --transient  set-hostname ha2

3.配置主机名节点名称很关键,集群每个节的名称都得能互相解析。/etc/hosts中的主机名配置结果必须跟”uname -n”的解析的结果一致。
vim /etc/hosts 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.11 ha1
192.168.0.12 ha2

4.同步时间
yum install ntp -y
ntpdate cn.pool.ntp.org

5.双机互信
ha1:
ssh-keygen  -t rsa -f ~/.ssh/id_rsa  -P ''
scp /root/.ssh/id_rsa.pub root@ha2:/root/.ssh/authorized_keys
ha2:
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
scp /root/.ssh/id_rsa.pub root@ha1:/root/.ssh/authorized_keys
 
 

3.安装配置pacemaker+corosync

1.安装pacemaker+corosync

在主机192.168.0.11和192.168.0.12上分别安装相关服务,以下步骤分别在2台机器上执行:

yum install pcs pacemaker corosync fence-agents-all -y
 

2.启动pcsd服务(开机自启动)

systemctl start pcsd.service
systemctl enable pcsd.service

3.创建集群用户

passwdhacluster(此用户在安装pcs时候会自动创建)


以上都是在2台主机上执行


4.集群各节点之间认证

pcs cluster auth ha1 ha2(此处需要输入的用户名必须为pcs自动创建的hacluster,其他用户不能添加成功


5.创建并启动名为my_cluster的集群,其中ha1 ha2为集群成员

pcs cluster setup --start --name my_cluster ha1 ha2

6.设置集群自启动
pcs cluster enable --all

7.查看集群状态

pcs cluster status


psaux|greppacemaker


检验Corosync的安装及当前corosync状态:

corosync-cfgtool-s

corosync-cmapctl| grep members

pcs status corosync

检查配置是否正确(假若没有输出任何则配置正确):

crm_verify -L -V

此错误,禁用STONITH:

pcs property set stonith-enabled=false

无法仲裁时候,选择忽略:

pcs property set no-quorum-policy=ignore


配置VIP资源:

pcs resource create vip ocf:heartbeat:IPaddr2 params ip=192.168.0.98 nic='enp0s3' cidr_netmask='23' broadcast='192.168.1.255' op monitor interval=5s timeout=20s on-fail=restart

配置HAProxy

pcs resource create haproxy systemd:haproxy op monitor interval="5s"
 

如果为找到资源,先安装,然后再创建

yum install haproxy -y
pcs resource create haproxy systemd:haproxy op monitor interval="5s"
 
 
 
 

定义运行的HAProxy和VIP必须在同一节点上:

pcs constraint colocation add vip haproxy INFINITY

定义约束,先启动VIP之后才启动HAProxy:

pcs constraint order vip then haproxy

备注:配置资源多节点启动,添加--clone

4.配置haproxy

 vim /etc/haproxy/haproxy.cfg

这里的配置就不详细说了,本环境配置如下:
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid    
	maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

listen admin_stats
        stats   enable
        bind    *:8080    #监听的ip端口号
        mode    http    #开关
        option  httplog
        log     global
        stats   refresh 30s   #统计页面自动刷新时间
        stats   uri /haproxy    #访问的uri   ip:8080/haproxy
        stats   realm haproxy
        stats   auth admin:admin  #认证用户名和密码
        stats   hide-version   #隐藏HAProxy的版本号
        stats   admin if TRUE   #管理界面,如果认证成功了,可通过webui管理节点


listen galera_cluster
  bind *:8888
  balance  roundrobin
  option  tcpka
  option  httpchk
  option  tcplog
  server controller1 192.168.0.21:80 check port 80 inter 2000 rise 2 fall 5
  server controller2 192.168.0.22:80 check port 80 inter 2000 rise 2 fall 5

haprxy服务不用启动,会随着corosync一起启动。
最后2台的server自己安装个httpd(yum install httpd -y)就可以了。

最后查看集群状态
pcs status


UI查看集群状态
https:192.168.0.10:2224
使用集群的账号hacluster登录,然后Add Existing

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


#使用军哥的lnmp配置虚拟主机,需要注意的是要配置hosts文件(这一点官方没有讲到)具体方法:1、修改hosts文件sudo vim /etc/hosts2、在hosts文件中新增一行(这里类似于windows上配置hosts文件)127.0.0.1 www.baidu.com3、保存并重启网络
一、配置编译环境 yum update && yum upgrade yum groupinstall "Development Tools" yum install gcc gcc-c++ pcre* openssl* gd-devel* zlib-devel
一、下载repo文件 二、备份并替换系统的repo文件 三、执行yum源更新操作
LAMP -- Linux Apache MySQL PHP 在CentOS安装的顺序,我一般是Apache -> MySQL -> PHP 第一步、安装并配置Apache 1、使用yum安装 [plain] view plaincopy
一、下载nginx安装包,官网下载中心http://nginx.org/download [root@localhost software]# wget http://nginx.org/download/nginx-1.10.1.tar.gz 二、解压nginx安装包 [root@localhos
1.下载composer curl -sS https://getcomposer.org/installer | php ps:如果出现php无法运行的情况,请先把PHP加入环境变量,具体操作参考《centOS安装PHP》 2.移动或复制composer到环境下可执行 cp composer.ph
一、卸载旧版本的vim 二、安装终端字符处理库ncurses 三、下载Vim8 四、编译安装 五、添加到系统环境变量 六、安装成功
引言 我们在日常的开发过程中,很多时候需要连接服务器查看日志或者在服务器上调试代码。但是,使用 ssh 命令登录服务器每次都需要输出密码,就比较繁琐。因此我们可以使用 sshpass 通过参数指定密码进行登录。解决了这个问题之后,我发现登录服务器之后,还需要手动 cd 切换到项目目录或者日志目录。为
iptables basics Introduction iptables 是一个配置 Linux 防火墙的工具,是 netfilter 项目的一部分。 在 Linux Kernel 3.13 及以上版本中, nftables 将作为后继者取代 iptables 以成为更强大易用的防火墙工具 Bas
一、下载tengine 二、安装tenginx(nginx)的模块依赖库 三、解压并指定安装路径 四、编译安装 五、启动(tengine)nginx 六、访问(tengine)nginx
这篇文章介绍了如何快速部署一套Kubernetes集群,下面就快速开始吧! 准备工作 机器部署规划 主机 | IP | 部署组件 | | master主节点 | 192.168.199.206 | etcd、kube apiserver、kube controller manager、kube sc
一、pip下载 二、解压安装 三、安装完成
1、WebBench安装: yum install ctags(先安装依赖库) mkdir /usr/local/man (创建一个目录不然会报错) wget http://home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz tar zxv
1:查看环境: [root@10-4-14-168 html]# cat /etc/redhat-release CentOS release 6.5 (Final) 2:关掉防火墙 [root@10-4-14-168 html]# chkconfig iptables off 3:配置CentOS
安装 1.检查当前是否有安装php rpm -qa|grep php 如果有安装PHP,那么请先删除这些安装包: yum remove php* 2.安装php源 Centos 5 安装php源: rpm -ivh http://mirro
一、安装 二、配置 三、修改配置文件 四、program 配置 五、启动
Sed 日常使用介绍 简介 是 环境下常用的流处理工具, 可以处理字符流, 文件或者二进制文件流。 各个 发行版都会配备 及其衍生的命令工具, 因此, 掌握该工具的基本用法, 足以满足我们日常的许多文本处理的任务。 以下采用示例的方式对 进行基本用法介绍. 如果有兴趣了解更高级的使用技巧, 本文采用
linux下开机自启: 在/etc/init.d目录下新建文件elasticsearch 并敲入shell脚本: 注意, 前两行必须填写,且要注释掉。 第一行为shell前行代码,目的告诉系统使用shell。 第二行分别代表运行级别、启动优先权、关闭优先权,且后面添加开机服务会用到。 shell脚本
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权 chmod +x /etc/rc.d/rc.local 2、赋予脚本可执行权限假设/usr/local/script/autostart.sh是你的脚本路径,给予执行权限 chmod +x /usr
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用ls -ll,会显示成字节大小,而ls- lh会以KB、MB等为单位进行显示,这样比较直观一些。 通过命令du -h –max-depth=1 *,可以查看当前目录下各文件、文件夹的大小,这个比较实用。 查询当前目录总大小可以使用d