1、集群配置的前提:
一、時間同步(ntpdate做crontab定時任務)
二、主機名和IP相互解析
三、基于ssh密鑰主機互信
#ssh-keygen -t rsa
#ssh-copy-id -i
集群的全生命周期管理工具:
pcs: agent(pcsd)
crmsh: agentless (pssh)
2、安裝corosync pacemaker
centos7 epel源提供了corosync和pacemaker
# yum install epel-release -y
#yum install corosync pacemaker -y
3、安裝pcs并啟動集群(每個節點都需要)
# yum install pcs
# systemctl start pcsd
#給hacluster用戶增加密碼 echo 123 | passwd --stdin hacluster
#認證節點身份,用戶名和密碼為上面設置的hacluster和123 # pcs?cluster?auth?ha1.lewis.com ha2.lewis.com
#配置集群,集群名字為mycluster # pcs cluster setup --name mycluster ha1.lewis.com ha2.lewis.com #具體配置文件的信息
# cat /etc/corosync/corosync.conf
totem {
version: 2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #版本
secauth: off ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#安全功能是否開起
cluster_name: mycluster ? ? ? ? ? ? ? ? ?#集群名稱
transport: udpu
}
nodelist {
node {
ring0_addr: ha1.lewis.com
nodeid: 1
}
node {
ring0_addr: ha2.lewis.com
nodeid: 2
}
}
quorum {
provider: corosync_votequorum ? ? ? ? ? ? ? ? ? ? ? ?#投票系統
two_node: 1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#是否為2節點集群
}
logging {
to_logfile: yes ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #是否記錄日志
logfile: /var/log/cluster/corosync.log ? ? ? ? ? ? ? ? #日志文件位置
to_syslog: yes ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #是否記錄系統日志
}
#啟動集群 # pcs cluster start --all #集群查看 # pcs status 具體pcs的用法 # pcs -h 或者 # man pcs
crmsh是opensuse源提供?http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/
# cd /etc/yum.repos.d/
#wget?http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/network:ha-clustering:Stable.repo
#yum install crmsh -y
(注意:2017/11/15 出現python-parallax包缺失,需自行下載rpm包安裝)
pacemaker配置集群資源,需注意設置的默認全局屬性如下:
一、默認資源粘性
crm(live)configure# rsc_defaults resource-stickiness=50
二、without-quorum時執行資源忽略(ignore)
property no-quorum-policy=ignore
三、關閉stonith
property stonith-enabled=false
啟動和開機啟動corosync pacemaker服務;
# systemctl start corosync pacemaker
# systemctl enable corosync pacemaker
查看集群狀態:
#crm_mon
#crm status
示例:基于NAS(nfs)做LAMP的(discuz)高可用
VIP:
nfs節點:172.20.121.243
ha1節點:172.20.121.241
ha2節點:172.20.121.242
nfs節點配置:
# yum install nfs-utils -y
# vim /etc/exports
/mydata 172.20.120.0/23(rw,no_root_squash)
# systemctl start nfs
ha1、ha2節點配置:
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/88410