corosync+pacemaker+nfs提供mysql高可用

corosync/openais+pacemaker+nfs提供mariadb高可用

节点一, one, 172.16.249.122/16, 172.16.0.1, CentOS6.6, mariadb
节点二, two, 172.16.249.123/16, 172.16.0.1, CentOS6.6, mariadb
节点三, three, 172.16.249.124/16, 172.16.0.1, CentOS6.6, NFS
VIP: 172.16.249.121

节点一: one 172.16.249.122
setup #设定ip
hostname one.centos
sed -i s@HOSTNAME=.*@HOSTNAME=one.centos@g /etc/sysconfig/network
vim /etc/hosts
172.16.249.122    one.centos    one
172.16.249.123    two.centos    two
======
ssh-keygen -t rsa -P '' -f '/root/.ssh/id_rsa'
ssh-copy-id -i ./.ssh/id_rsa.pub root@two
ntpdate -u 202.112.10.60
date ; ssh two 'date'

节点二: two 172.16.249.123
setup #设定ip
hostname two.centos
sed -i s@HOSTNAME=.*@HOSTNAME=two.centos@g /etc/sysconfig/network
vim /etc/hosts
172.16.249.122    one.centos    one
172.16.249.123    two.centos    two
======
ssh-keygen -t rsa -P '' -f '/root/.ssh/id_rsa'
ssh-copy-id -i ./.ssh/id_rsa.pub root@one
ntpdate -u 202.112.10.60
date ; ssh one 'date'


节点三: three 172.16.249.124
cfdisk -Ps /dev/sda
cfdisk /dev/sda
创建两个大小为20G,类型为8e的分区,分区文件分别为/dev/sda3和/dev/sda4 (过程略)
partx -a /dev/sda  (执行两次)
pvcreate /dev/sda{3,4}
pvs
vgcreate myvg /dev/sda{3,4}
lvcreate -L 20G -n mydata myvg
mke2fs -j -L MYDATA /dev/myvg/mydata
blkid /dev/myvg/mydata

mkdir -pv /sharedata
vim /etc/fstab
追加如下内容
LABEL=MYDATA      /sharedata   ext3    defaults  0 0  
mount -a
mount
>/dev/mapper/myvg-mydata on /sharedata type ext3 (rw)
df -h /sharedata/
/dev/mapper/myvg-mydata  20G  173M   19G   1% /sharedata

useradd -r -u 150 mysql
chown -R mysql:mysql /sharedata/
vim /etc/exports
/sharedata  172.16.249.122(rw,no_root_squash) 172.16.249.123(rw,no_root_squash)
==============
service nfs start
chkconfig nfs on
showmount -e localhost
>Export list for localhost:
>/sharedata 172.16.249.122,172.16.249.123


节点一: one 172.16.249.122
useradd -r -u 150 mysql
mkdir -pv /data/mydata
mount -t nfs 172.16.249.124:/sharedata /data/mydata
ls /data/mydata/
>lost+found
df -h /data/mydata/
>Filesystem                    Size  Used Avail Use% Mounted on
>172.16.249.124:/sharedata    20G  172M   19G   1% /data/mydata
su - mysql
cd /data/mydata/    #确认mysql用户对改目录有读写权限
touch onefile   
rm onefile
exit


节点二: two 172.16.249.123
useradd -r -u 150 mysql
mkdir -pv /data/mydata
mount -t nfs 172.16.249.124:/sharedata /data/mydata
ls /data/mydata/
>lost+found
df -h /data/mydata/
>Filesystem                    Size  Used Avail Use% Mounted on
>172.16.249.124:/sharedata    20G  172M   19G   1% /data/mydata
su - mysql
cd /data/mydata/    #确认mysql用户对改目录有读写权限
touch twofile   
rm twofile
exit



节点一: one 172.16.249.122
安装mariadb
ls
>mariadb-5.5.43-binary-linux-x86_64.tar.gz
tar xf mariadb-5.5.43-binary-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mariadb-5.5.43-linux-x86_64 mysql
cd mysql
chown -R root:mysql .
scripts/mysql_install_db --datadir=/data/mydata/ --user=mysql
\cp support-files/my-large.cnf /etc/my.cnf
vim /etc/my.cnf
thread_concurrency = 2    #修改
datadir = /data/mydata        #添加
=========
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start
vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin/:$PATH
===========
export PATH=/usr/local/mysql/bin/:$PATH
mysql        #连接数据库
show databases;
quit           #退出数据库
service mysqld stop
chkconfig mysqld off
chkconfig mysqld --list
umount /data/mydata/


节点二: two 172.16.249.123
安装mariadb
ls
>mariadb-5.5.43-binary-linux-x86_64.tar.gz
tar xf mariadb-5.5.43-binary-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mariadb-5.5.43-linux-x86_64 mysql
cd mysql
chown -R root:mysql .
\cp support-files/my-large.cnf /etc/my.cnf
vim /etc/my.cnf
thread_concurrency = 2    #修改
datadir = /data/mydata        #添加
=========
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start
vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin/:$PATH
===========
export PATH=/usr/local/mysql/bin/:$PATH
mysql        #连接数据库
show databases;
quit           #退出数据库
service mysqld stop
chkconfig mysqld off
chkconfig mysqld --list    #确保开机不自启
umount /data/mydata/



节点一: one 172.16.249.122
准备yum源
wget -O /etc/yum.repos.d/epel6.repo http://mirrors.aliyun.com/repo/epel-6.repo
mount /dev/cdrom  /mnt/cdrom
cat /etc/yum.repos.d/c6cdrom.repo
[CentOS6.6]
name=dvd1
baseurl=file:///mnt/cdrom
gpgcheck=0
cost=1
===========
yum repolist
yum -y install corosync corosynclib  pacemaker pacemaker-cts pacemaker-libs cluster-glue cluster-glue-libs resource-agents libesmtp heartbeat heartbeat-libs




节点二: two 172.16.249.123
准备yum源
wget -O /etc/yum.repos.d/epel6.repo http://mirrors.aliyun.com/repo/epel-6.repo
mount /dev/cdrom  /mnt/cdrom
cat /etc/yum.repos.d/c6cdrom.repo
[CentOS6.6]
name=dvd1
baseurl=file:///mnt/cdrom
gpgcheck=0
cost=1
===========
yum repolist
yum -y install corosync corosynclib  pacemaker pacemaker-cts pacemaker-libs cluster-glue cluster-glue-libs resource-agents libesmtp heartbeat heartbeat-libs




节点一: one 172.16.249.122
cd /etc/corosync/
cp corosync.conf.example corosync.conf
vim corosync.conf
修改如下选项
secauth: on  
bindnetaddr: 172.16.249.121         #vip
mcastaddr: 226.100.7.1
to_syslog: no
添加如下内容:    这两段内容作用什么是?
service {
ver:  0
name: pacemaker
}
aisexec {
user:   root
group:  root
}
==============
corosync-keygen  
(如果卡住执行\cp /mnt/cdrom/Packages/c*.rpm /tmp/,磁盘读写可生成随机数)
mkdir -pv /var/log/cluster/
service corosync start
查看corosync引擎是否正常启动:
grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log
查看初始化成员节点通知是否正常发出:
grep  TOTEM  /var/log/cluster/corosync.log
检查启动过程中是否有错误产生:
grep ERROR: /var/log/cluster/corosync.log | grep -v unpack_resources
查看pacemaker是否正常启动:
grep pcmk_startup /var/log/cluster/corosync.log



ssh two 'mkdir -pv /var/log/cluster/'
scp authkey corosync.conf two:/etc/corosync/
ssh two '/etc/rc.d/init.d/corosync start'


节点一: one 172.16.249.122
下载三个和相关crmsh的rpm包
python-pssh-2.3.1-4.2.x86_64
pssh-2.3.1-4.2.x86_64
crmsh-2.1-1.6.x86_64
cd
wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/crmsh-2.1-1.6.x86_64.rpm
wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/pssh-2.3.1-4.2.x86_64.rpm
wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/python-pssh-2.3.1-4.2.x86_64.rpm
yum -y install *.rpm
crm status
>Online: [ one.centos two.centos ]

scp *.rpm two
ssh two 'yum -y install *.rpm'




节点一: one 172.16.249.122
添加集群资源
禁用stonith:
# crm configure property stonith-enabled=false
修改忽略quorum不能满足的集群状态检查:
# crm configure property no-quorum-policy=ignore
为资源指定默认黏性值:
# crm configure rsc_defaults resource-stickiness=100

添加访问mariadb的ip资源
crm configure primitive vip ocf:heartbeat:IPaddr params ip=172.16.249.121
添加nfs文件系统资源
crm configure primitive mynfs ocf:heartbeat:Filesystem params device="172.16.249.124:/sharedata" directory="/data/mydata" fstype="nfs" op start timeout=60s op stop timeout=60s
查看定义的资源
crm configure show
crm status
>vip    (ocf::heartbeat:IPaddr):    Started one
>mynfs  (ocf::heartbeat:Filesystem):    Started two

ip addr show
>inet 172.16.249.122/16
>inet 172.16.249.121/16
ssh two 'ls /data/mydata/'

ssh two 'crm node standby'    #必须滴,让两个资源运行在one.centos上

crm status  
>Node two.centos: standby
>Online: [ one.centos ]
> vip    (ocf::heartbeat:IPaddr):    Started one.centos
> mynfs    (ocf::heartbeat:Filesystem):    Started one.centos


添加mysqld服务资源
crm configure primitive mysqld lsb:mysqld

vip、mynfs和mysqld资源的启动顺序为vip-->mynfs-->mysqld
定义排列约束
crm configure collocation mysqld_with_mynfs_vip inf: vip mynfs mysqld

定义顺序约束
crm configure order mysqld_after_mynfs_after_vip Mandatory: vip mynfs mysqld

crm configure show

查看集群信息库中定义的collocation和order约束
crm configure show xml
    //collocation约束配置信息//
     <rsc_colocation id="mysqld_with_mynfs_vip" score="INFINITY">
            <resource_set id="mysqld_with_mynfs_vip-0">
              <resource_ref id="vip"/>
              <resource_ref id="mynfs"/>
              <resource_ref id="mysqld"/>
    //order约束配置信息//
    <rsc_order id="mysqld_after_mynfs_after_vip" score="INFINITY">     #INFINITY=>Mandatory(强制的)
            <resource_set id="mysqld_after_mynfs_after_vip-0">
              <resource_ref id="vip"/>
              <resource_ref id="mynfs"/>
              <resource_ref id="mysqld"/>



crm status
>Online: [ one.centos two.centos ]

> vip    (ocf::heartbeat:IPaddr):    Started two.centos
> mynfs    (ocf::heartbeat:Filesystem):    Started two.centos
> mysqld    (lsb:mysqld):    Started two.centos
===================

ssh two 'crm node online'
crm status
>Online: [ one.centos two.centos ]
crm node standby
crm status
>Node one.centos: standby
>Online: [ two.centos ]
> vip    (ocf::heartbeat:IPaddr):    Started two.centos
> mynfs    (ocf::heartbeat:Filesystem):    Started two.centos
> mysqld    (lsb:mysqld):    Started two.centos
=================




节点二: two 172.16.249.123
mysql
mysql> show databases;
mysql> create database twodb;
mysql> quit;

ssh one 'crm node online'
crm status
>Online: [ one.centos two.centos ]
> vip    (ocf::heartbeat:IPaddr):    Started two.centos
> mynfs    (ocf::heartbeat:Filesystem):    Started two.centos
> mysqld    (lsb:mysqld):    Started two.centos
=============

crm node standby
>Node two.centos: standby
>Online: [ one.centos ]
> vip    (ocf::heartbeat:IPaddr):    Started one.centos
> mynfs    (ocf::heartbeat:Filesystem):    Started one.centos
> mysqld    (lsb:mysqld):    Started one.centos
===============



节点一: one 172.16.249.122
mysql
mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| information_schema  |
| #mysql50#lost+found |
| mysql               |
| performance_schema  |
| test                |
| twodb               |                 ---看到此数据库,说明高可用服务配置成功
+---------------------+
mysql> quit;

你可能感兴趣的:(mysql,nfs,pacemaker,corosync)