pcs pacemaker corosync drbd mysql (存档)

OS:centos6.8

Package:corosync-1.4.7-5.el6.x86_64    

                corosynclib-1.4.7-5.el6.x86_64   

                pacemaker-1.1.15-5.el6.x86_64   

                pacemaker-libs-1.1.15-5.el6.x86_64   

                pacemaker-cli-1.1.15-5.el6.x86_64

                pacemaker-cluster-libs-1.1.15-5.el6.x86_64

                pcs-0.9.155-2.el6.centos.x86_64

                mysql-5.6.40-linux-glibc2.12-x86_64

                drbd84-utils-8.9.8-1.el6.elrepo.x86_64

                kmod-drbd84-8.4.9-1.el6.elrepo.x86_64


节点准备:node1    ipaddress: 192.168.1.10   

                node2    ipaddress: 192.168.1.11

                vip : 192.168.1.8


1.    更新elrepo

登录网站:http://elrepo.org/tiki/tiki-index.php

# rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm


2.    安装配置drbd

# yum install drbd84 kmod-drbd84

# vim /etc/drbd.conf

include "drbd.d/global_common.conf";
include "drbd.d/*.res";

# vim /etc/drbd.d/global_common.conf

# DRBD is the result of over a decade of development by LINBIT.
# In case you need professional services for DRBD or have
# feature requests visit http://www.linbit.com

global {
        usage-count no;
        # minor-count dialog-refresh disable-ip-verification
        # cmd-timeout-short 5; cmd-timeout-medium 121; cmd-timeout-long 600;
}

common {
        handlers {
                # These are EXAMPLE handlers only.
                # They may have severe implications,
                # like hard resetting the node under certain circumstances.
                # Be careful when chosing your poison.

                 pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
                 pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
                 local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
                # fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
                # split-brain "/usr/lib/drbd/notify-split-brain.sh root";
                # out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
                # before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
                # after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
        }

        startup {
                # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
        }

        options {
                # cpu-mask on-no-data-accessible
        }

        disk {
                on-io-error detach;
                # size on-io-error fencing disk-barrier disk-flushes
                #
                # disk-drain md-flushes resync-rate resync-after al-extents
                # c-plan-ahead c-delay-target c-fill-target c-max-rate
                # c-min-rate disk-timeout
        }

        net {
                cram-hmac-alg "sha1";
                shared-secret "mydrbdlab";
                # protocol timeout max-epoch-size max-buffers unplug-watermark
                # connect-int ping-int sndbuf-size rcvbuf-size ko-count
                # allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
                # after-sb-1pri after-sb-2pri always-asbp rr-conflict
                # ping-timeout data-integrity-alg tcp-cork on-congestion
                # congestion-fill congestion-extents csums-alg verify-alg
                # use-rle
        }
}

准备硬盘分区,并添加drbd资源配置文件 。本例子使用/dev/sdb1 分区

# vim /etc/drbd.d/mysql.res

resource mysql {
  on lvs1.test.com {
        device  /dev/drbd0;
        disk    /dev/sdb1;
        address 172.22.202.243:7789;
        meta-disk internal;
  }
  on lvs2.test.com {
        device  /dev/drbd0;
        disk    /dev/sdb1;
        address 172.22.202.244:7789;
        meta-disk internal;
  }
}

拷贝给其他节点

# scp -r /etc/drbd.* node2:/etc/

创建drbd资源命令

# drbdadm create-md mysql

启动两个节点的drbd并检查运行Primary/Secondary情况

# service drbd start

# drbd-overview

设置Primary

# drbdadm -- --overwrite-data-of-peer primary mysql

在Primary状态的节点中挂载drbd0测试

# mkdir /mydata/data

# mkfs.ext4 /dev/drbd0

# mount /dev/drbd0 /mydata/data/

并测试此分区的读写

# touch a.txt


3.    mysql的安装准备 (两个节点)

# 准备mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz

# tar -xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

# ln -s mysql-5.6.40-linux-glibc2.12-x86_64 mysql

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# chkconfig --add mysqld

# chkconfig mysqld off

# echo 'export PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile

# groupadd -r -g 306 mysql

# useradd -r -u 306 -g 306 mysql 

# chown -R mysql.mysql /mydata/data

设置mysq的include的软链接

# ln -sv /usr/local/mysql/include /usr/include/mysql

配置mysql的lib库

# echo "/usr/local/mysql/lib/" > /etc/ld.so.conf.d/mysql.conf

# ldconfig -v

初始化mysql到drbd分区中

# /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mydata/data

# cp -a mysql/my.cnf /etc/my.cnf

修改my.cnf (设置datadir的路径)

# vim /etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
datadir = /mydata/data
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

启动mysqld服务并初始化数据库(设置密码,删除匿名登录,test数据库)

# service mysqld start

# mysql_secure_installation

登录mysql测试

# mysql -uroot -p


4.    集群前准备

1)    关闭drbd mysqld开机启动设置

# chkconfig mysqld off

# chkconfig drbd off

2)    关闭drbd mysqld服务

# service mysqld stop

# umount /mydata/data

# service drbd stop

3)    设置节点的hosts文件与主机名 (两个节点)

# vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=node1.test.com

# echo '192.168.1.10 node1.test.com node1 ' >>/etc/hosts

# echo '192.168.1.11 node2.test.com node2 ' >>/etc/hosts

4)    关闭防火墙与selinux

5)    配置ntp

6)    配置ssh互信(每个节点都需执行)

# ssh-keygen -t rsa -f /root/.ssh/id_rsa -p ''

# ssh-copy-id -i .ssh/id_rsa.pub [email protected]


5.    集群节点配置

1)    安装集群软件

# yum install pcs pacemake corosync

2)    设置开机启动服务

# service pcsd start

# chkconfig pcsd on

3)    修改用户hacluster的密码(各个节点)

# passwd hacluster

4)    认证各个节点,并创建集群

# pcs cluster auth node1.test.com node2.test.com

# pcs cluster setup --name my_cluster node1.test.com node2.test.com

5)    启动集群

# pcs cluster start --all

node1.test.com: Starting Cluster...

node2.test.com: Starting Cluster...

# pcs cluster enable -all

6)    关闭stonith (没有stonith设备)

# pcs property set stonith-enabled=false

7)    设置默认的资源粘性

# pcs resource defaults resource-stickiness=100


6.    集群资源配置

1)    配置vip

# pcs resource create vip ocf:heartbeat:IPaddr2 ip=192.168.1.8 cidr_netmask=24 op monitor interval=30s

2)    配置drbd

# 创建drbd的cib

# pcs cluster cib drbd_cfg

# pcs -f drbd_cfg resource create DRBD ocf:linbit:drbd drbd_resource=mysql op monitor interval=60s

pcs -f drbd_cfg resource master DRBDClone DRBD master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true

# 生效drbd_cfg的配置

# pcs cluster cib-push drbd_cfg

3)   配置FSsystem挂载   

# 创建FSsystem的cib

# pcs cluster cib fs_cfg

pcs -f fs_cfg resource create DBFS ocf:heartbeat:Filesystem device='/dev/drbd0' directory='/mydata/data' fstype='ext4'

# 设置DBFS与DRBDClone的constraint

# pcs -f fs_cfg constraint colocation add DBFS DRBDClone INFINITY with-rsc-role=Master

# 设置DBFS与DRBDClone的order

# pcs -f fs_cfg constraint order promote DRBDClone then start DBFS

# 生效fs_cfg的配置

pcs cluster cib-push  fs_cfg

4)    配置mysqld

# pcs resource create MYSQL service:mysqld

# 设置colocation

# pcs constraint colocation add MYSQL vip INFINITY

# pcs constraint colocation add vip DBFS INFINITY

# 设置order

# pcs constraint order DBFS then MYSQL


7)    至此,集群资料已配置完成,可以使用。

# pcs status

Cluster name: my_cluster
Stack: cman
Current DC: node1.test.com (version 1.1.15-5.el6-e174ec8) - partition with quorum
Last updated: Thu May 31 12:03:22 2018          Last change: Wed May 30 16:45:39 2018 by root via crm_attribute on node2.test.com

2 nodes and 5 resources configured

Online: [ node1.test.com node2.test.com ]

Full list of resources:
 vip    (ocf::heartbeat:IPaddr2):       Started node1.test.com
 Master/Slave Set: DRBDClone [DRBD]
     Masters: [ node1.test.com ]
     Slaves: [ node2.test.com ]
 DBFS   (ocf::heartbeat:Filesystem):    Started node1.test.com
 MYSQL  (service:mysqld):       Started node1.test.com

Daemon Status:
  cman: active/disabled
  corosync: active/disabled
  pacemaker: active/enabled

  pcsd: active/enabled


8)    使用GUI登录集群

# 开启PCSD_GUI

# vim /etc/sysconfig/pcsd

# pcsd configuration file

# Set PCSD_DEBUG to true for advanced pcsd debugging information
PCSD_DEBUG=false
# Set DISABLE_GUI to true to disable GUI frontend in pcsd
PCSD_DISABLE_GUI=false
# Set web UI sesions lifetime in seconds
PCSD_SESSION_LIFETIME=3600
# List of IP addresses pcsd should bind to delimited by ',' character
#PCSD_BIND_ADDR='::'

# SSL settings
# set SSL options delimited by ',' character
# list of valid options can be obtained by running
# ruby -e 'require "openssl"; puts OpenSSL::SSL.constants.grep /^OP_/'
#PCSD_SSL_OPTIONS='OP_NO_SSLv2,OP_NO_SSLv3,OP_NO_TLSv1,OP_NO_TLSv1_1'
# set SSL ciphers
#PCSD_SSL_CIPHERS='DEFAULT:!RC4:!3DES:@STRENGTH!'

# Do not change
RACK_ENV=production

# 使用以下网站登录

https://192.168.1.8:2224

pcs pacemaker corosync drbd mysql (存档)_第1张图片

你可能感兴趣的:(pcs pacemaker corosync drbd mysql (存档))