Centos7 HA操作指南

本教程是基于CENTOS7 的WEB负载与数据库高可用方案
本方案采用主主模式

首先进行系统的初步设置,这对整个集群有特别重要的作用
1.修改主机名称
2.关停NetworkManager服务
systemctl stop NetworkManager
systemclt disable NetworkManager
3.修改网卡名称,这个设置是可选的,我喜欢用eth0来表示网卡。
vi /etc/sysconfig/grub
在“GRUB_CMDLINE_LINUX=”这行最后
添加 net.ifnames=0 biosdevname=0
修改后:GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto vconsole.keymap=us rhgb quiet net.ifnames=0 biosdevname=0"
然后执行:grub2-mkconfig -o /boot/grub2/grub.cfg
然后修改 /etc/sysconfig/network-scripts/ifcfg-*
为想要的名称 ifcfg-eth0 ,修改配置文件里面的名称 NAME=eth0
重启操作系统,即可将网卡名称修改为 eth0
4.关停防火墙
systemctl stop firewalld
systemctl disable firewalld
5.设置selinux配置选项
/etc/selinux/config
把enforcing 改为:disabled
6.给集群内的所有主机添加主机列表
/etc/hosts
122.0.113.142 website01
122.0.113.143 website02
122.0.113.144 website03
这项操作是在所有机器上进行的
7.设置ssh无密码访问
ssh-keygen
一路回车,完成后做如下操作:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 644 ~/.ssh/authorized_keys
chmod 755 ~/.ssh
vi ~/.ssh/config (加入如下一行)
StrictHostKeyChecking no
chmod 600 config
然后赋予相应的权限
chmod 755 ~/.ssh/
chmod 600 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
操作完毕后,要把/root/.ssh内的密钥及配置文件全部下载到本地,然后在其它节点上进行ssh-keygen的操作。完成后,进到/root/.ssh目当,清除目录里的内容,把本地的文件上传上去。
然后执行:
chmod 755 ~/.ssh/
chmod 600 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub

前面的准备工作完成后,开始LAMP的操作
先要在/etc/yum.repo.d/目录下创建yum源
[mariadb]
name = MariaDB Galera Cluster
baseurl = http://yum.mariadb.org/5.5.48/centos7-amd64/
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck = 1
进行数据库的安装
yum install MariaDB-Galera-server MariaDB-client galera
service mysql start
chkconfig mysql on
mysql_secure_installation 进行root密码的设置
安装apache
yum install -y httpd
systemctl start httpd
systemctl enable httpd
安装php
yum install -y php
安装php扩展
yum install -y php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

现在进行基于Pacemake corosync的操作
yum install pacemaker pcs corosync fence-agnets resource-agents -y 三个节点都需要安装
开启pcs服务并设置为自启动
systemctl start pcsd
systemctl enable pcsd 三个节点都需要这样操作
设置两个控制节点的hacluster用户名和密码,两个节点都要操作
echo my-secret-password-no-dont-use-this-one | passwd –stdin hacluster #website01
echo my-secret-password-no-dont-use-this-one | passwd –stdin hacluster #website02
echo my-secret-password-no-dont-use-this-one | passwd –stdin hacluster #website03
设置集群密码
passwd hacluster
1qaz2wsx,./
配置corosync
[root@controller01 ~]# pcs cluster auth website01 website02 website03
创建一个集群,并设置命令,启用服务
[root@controller01 ~]# pcs cluster setup --name my-cluster website01 website02 website03
启动集群
pcs cluster start --all
systemctl start corosync
systemctl enable corosync
systemctl start pacemaker
systemctl enable pacemaker
检查pcs status 输出
WARNING: no stonith devices and stonith-enabled is not false 会有这样一个警告信息
这个是没有Fencing设备时,没有禁用stonith功能,禁用就可以了
pcs property set stonith-enabled=false
设置基本的群集属性
pcs property set pe-warn-series-max=1000 \

pe-input-series-max=1000 \
pe-error-series-max=1000 \
cluster-recheck-interval=3min
设置资源默认粘性(防止资源回切)
pcs resource defaults resource-stickiness=100
pcs resource defaults
设置资源超时时间
pcs resource op defaults timeout=90s
pcs resource op defaults
配置集群的VIP
pcs resource create vip ocf:heartbeat:IPaddr2 params ip="122.0.113.146" cidr_netmask="25" op monitor interval="30s"
VIP已经能Ping通了
配置Haporxy
安装haproxy 用yum
yum install haproxy -y
添加haproxy日志
cd /var/log
mkdir haproxy
cd haproxy
touch haproxy.log
chmod a+w haproxy.log
vi /etc/rsyslog.conf
$ModLoad imudp
$UDPServerRun 514
两行前的#去掉

#Save boot messages also to boot.log
local7. /var/log/boot.log
local3.
/var/log/haproxy/haproxy.log
修改/etc/sysconfig/rsyslog 文件
SYSLOGD_OPTIONS=""
改为
SYSLOGD_OPTIONS="-r -m 0 -c 2"
配置haproxy
修改/etc/haproxy/haproxy.cfg文件,在global区段添加 #我会准备好haproxy的配置文件
log 127.0.0.1 local3
systemctl restart rsyslog
然后进行下面的操作
pcs resource create lb-haproxy systemd:haproxy --clone
pcs constraint order start vip then lb-haproxy-clone kind=Optional
pcs constraint colocation add vip with lb-haproxy-clone
echo net.ipv4.ip_nonlocal_bind=1 >> /etc/sysctl.d/haproxy.conf
echo 1 > /proc/sys/net/ipv4/ip_nonlocal_bind
还需要在三个控制节点里,把haproxy设置为自启动。systemctl enable haproxy
进行重启操作,重启完成后,用pcs status 查看集群状态
[root@website01 ~]# pcs status
Cluster name: my-cluster
Last updated: Tue Apr 19 20:15:20 2016 Last change: Tue Apr 19 18:11:30 2016 by root via cibadmin on website01
Stack: corosync
Current DC: website01 (version 1.1.13-10.el7_2.2-44eb2dd) - partition with quorum
3 nodes and 4 resources configured

Online: [ website01 website02 website03 ]

Full list of resources:

vip (ocf::heartbeat:IPaddr2): Started website01
Clone Set: lb-haproxy-clone [lb-haproxy]
Started: [ website01 website02 website03 ]

PCSD Status:
website01: Online
website02: Online
website03: Online

Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
当所有这些状态显示后,会发现httpd服务与mariadb没有启来,我们需要做一些操作
在/etc/httpd/conf/httpd.conf配置文件里修改
Listen website01:80
保存退出,systemctl restart httpd 重启服务
在/etc/my.cnf.d/server.cnf 配置文件里修改
在mysqld 选项里添加相应的节点主机名称
bind_address = website01
保存退出,service mysql restart 重启服务
以上操作都需要在三个节点上进行
下面进行mariadb基于galera做的主主数据库集群,我们需要把三个节点的mariadb服务给停掉,service mysql stop
设置群集配置文件
vi /etc/my.cnf.d/server.cnf
在[mariadb-5.5]选项下面添加配置内容
query_cache_size=0
binlog_format=ROW
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://website01,website02,website03
wsrep_cluster_name='websitecluster'
wsrep_node_address='122.0.113.142'
wsrep_node_name='webstie01'
wsrep_sst_method=rsync
完成后,以上操作还需要在其它两个节点进行,需要修改wsrep_node_address='122.0.113.142'的ip为当前的节点ip wsrep_node_name='webstie01' 为当前的主机名称
现在开始启动集群
在主服务器上运行:service mysql start --wsrep-new-cluster
在从服务器上运行:service mysql start
登陆到任意一台节点,进到数据库里
mysql -uroot -p
输入SHOW STATUS LIKE 'wsrep%'; 回车
wsrep_incoming_addresses | website01:3306,website02:3306,website03:3306 看到有如下信息,说明我们的集群配置正常
最后在每个节点上设置数据库健康检测
/etc/sysconfig/clustercheck:
MYSQL_USERNAME="clustercheck"
MYSQL_PASSWORD="my_clustercheck_password"
MYSQL_HOST="localhost"
MYSQL_PORT="3306"
在数据库里创建检测账号
GRANT PROCESS ON . TO 'clustercheck'@'localhost'IDENTIFIED BY 'my_clustercheck_password';
FLUSH PRIVILEGES;
设置galera检测文件
/etc/xinetd.d/galera-monitor:# 这点非常的重要,如果格式不对,9200端口会不通的。
service galera-monitor
{
port = 9200
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
group = root
groups = yes
server = /usr/bin/clustercheck
type = UNLISTED
per_source = UNLIMITED
log_on_success =
log_on_failure = HOST
flags = REUSE
}
由于系统本身没有clustercheck文件的,我们需要在/usr/bin/clustercheck里新建一个,我已经创建好了,直接上传到目录就可以了。
然后给文件权限 chmod -R a+x /usr/bin/clustercheck
检查状态信息,执行如下命令:/usr/bin/clustercheck
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 32

Galera cluster node is synced.
安装xinetd服务
yum install xinetd
启动xinetd服务
systemctl daemon-reload
systemctl enable xinetd
systemctl start xinetd
最后,我们需要允许VIP能够访问到我们的数据库,因此,要在三个节点的数据库里进行操作
update mysql.user set Host = '%' where Host = 'localhost' and User = 'root';
flush privileges;
到这里,一个稳定的集群服务就配置完成了。

centos安装ab工具给网站进行压力测试
使用方法(直接输入ab命令查看参数)
ab -c 10 -n 1000 http://www.test.com/
上条命令的意思是,对test.com的首页进行压力测试,模拟同时10个用户总共进行1000个请求
测试完成后会显示报告,会显示一些参数供我们判断

转载于:https://blog.51cto.com/mycnarms/2300538

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值