[root@VM-node4 ~]# drbdadm create-md mysql initializing activity log NOT initializing bitmap Writing meta data... New drbd meta data block successfully created.
两边都要做这样的操作,接着就可以启动服务了:
1 2 3 4 5 6 7 8
[root@VM-node3 ~]# service drbd start Starting DRBD resources: [ create res: mysql prepare disk: mysql adjust disk: mysql adjust net: mysql ] ......
[root@VM-node3 ~]# mke2fs -t ext4 /dev/drbd0 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 196608 inodes, 786143 blocks 39307 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=805306368 24 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@VM-node3 ~]# mount /dev/drbd0 /mnt/ [root@VM-node3 ~]# ls /mnt/ lost+found
[root@VM-node3 ~]# pcs status Cluster name: Stack: classic openais (with plugin) Current DC: VM-node3 (version 1.1.15-5.el6-e174ec8) - partition with quorum Last updated: Tue Oct 31 19:09:26 2017 Last change: Mon Oct 30 23:24:09 2017 by root via cibadmin on VM-node4 , 2 expected votes 2 nodes and 0 resources configured
[root@VM-node3 ~]# crm crm(live)# configure crm(live)configure# primitive drbd_mysql ocf:linbit:drbd drbd_resource="mysql" op monitor role="Slave" interval=20s timeout=20s op monitor role="Master" interval=10s timeout=20s crm(live)configure# verify WARNING: drbd_mysql: default timeout 20s for start is smaller than the advised 240 WARNING: drbd_mysql: default timeout 20s for stop is smaller than the advised 100 crm(live)configure# delete drbd_mysql crm(live)configure# primitive drbd_mysql ocf:linbit:drbd drbd_resource="mysql" op monitor role="Slave" interval=20s timeout=20s op monitor role="Master" interval=10s timeout=20s op start timeout=240s op stop timeout=100 crm(live)configure# verify crm(live)configure# ms ms_drbd_mysql drbd_mysql meta clone-max="2" clone-node-max="1" master-max="1" master-node-max="1" notify="true" crm(live)configure# commit crm(live)configure# cd crm(live)# status Stack: classic openais (with plugin) Current DC: VM-node3 (version 1.1.15-5.el6-e174ec8) - partition with quorum Last updated: Tue Oct 31 22:54:17 2017 Last change: Tue Oct 31 22:54:14 2017 by root via cibadmin on VM-node3 , 2 expected votes 2 nodes and 2 resources configured
[root@VM-node3 ~]# crm status Stack: classic openais (with plugin) Current DC: VM-node3 (version 1.1.15-5.el6-e174ec8) - partition with quorum Last updated: Wed Nov 1 11:56:45 2017 Last change: Wed Nov 1 11:56:43 2017 by root via crm_attribute on VM-node4 , 2 expected votes 2 nodes and 3 resources configured
Online: [ VM-node3 VM-node4 ]
Full list of resources:
Master/Slave Set: ms_drbd_mysql [drbd_mysql] Masters: [ VM-node3 ] Slaves: [ VM-node4 ] drbd_fs (ocf::heartbeat:Filesystem): Started VM-node3 [root@VM-node3 ~]# groupadd -r -g 306 mysql [root@VM-node3 ~]# useradd -r -g 306 -u 306 mysql [root@VM-node3 mariadb55]# chown root:mysql -R mysql [root@VM-node3 mysql]# bash scripts/mysql_install_db --user=mysql --datadir=/data/db_data/ [root@VM-node3 db_data]# cp /usr/local/src/mariadb55/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld [root@VM-node3 db_data]# chkconfig --add mysqld [root@VM-node3 db_data]# chkconfig mysqld off [root@VM-node3 db_data]# mkdir /etc/mysql [root@VM-node3 db_data]# cp /usr/local/src/mariadb55/mysql/support-files/my-large.cnf /etc/mysql/my.cnf [root@VM-node3 db_data]# vim /etc/mysql/my.cnf ---(In Vim) [mysqld] ...(omitted) datadir = /data/db_data innodb_file_per_table = on skip_name_resolve = on ---(Quit) [root@VM-node3 db_data]# service mysqld start Starting MySQL.171101 13:29:07 mysqld_safe Logging to '/data/db_data/VM-node3.err'. 171101 13:29:07 mysqld_safe Starting mysqld daemon with databases from /data/db_data . SUCCESS! [root@VM-node3 db_data]# /usr/local/src/mariadb55/mysql/bin/mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.58-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> GRANT ALL ON *.* TO 'root'@'192.168.206.%' IDENTIFIED BY 'cluster'; Query OK, 0 rows affected (0.02 sec)
crm(live)# configure crm(live)configure# primitive ip ocf:heartbeat:IPaddr params ip="192.168.206.20" op monitor interval=10s timeout=20s crm(live)configure# verify crm(live)configure# primitive mysql lsb:mysqld op monitor interval=20s timeout=20s crm(live)configure# verify crm(live)configure# colocation ip_with_drbd_Master inf: ip ms_drbd_mysql:Master crm(live)configure# colocation mysql_with_drbd_Master inf: mysql ms_drbd_mysql:Master crm(live)configure# show crm(live)configure# order mysql_after_drbd Mandatory: drbd_fs ip ms_drbd_mysql mysql crm(live)configure# order mysql_after_drbd Mandatory: drbd_fs:start mysql:start crm(live)configure# verify crm(live)configure# order mysql_after_ip Mandatory: ip:start mysql:start crm(live)configure# verify crm(live)configure# commit crm(live)configure# cd crm(live)# status Stack: classic openais (with plugin) Current DC: VM-node3 (version 1.1.15-5.el6-e174ec8) - partition with quorum Last updated: Wed Nov 1 21:34:04 2017 Last change: Wed Nov 1 21:33:58 2017 by root via cibadmin on VM-node3 , 2 expected votes 2 nodes and 5 resources configured
Node VM-node4: standby Online: [ VM-node3 ]
Full list of resources:
Master/Slave Set: ms_drbd_mysql [drbd_mysql] Masters: [ VM-node3 ] Stopped: [ VM-node4 ] drbd_fs (ocf::heartbeat:Filesystem): Started VM-node3 ip (ocf::heartbeat:IPaddr): Started VM-node3 mysql (lsb:mysqld): Started VM-node3
[root@VM-node0 ~]# mysql -uroot -h192.168.206.20 -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 7 Server version: 5.5.58-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | testdb | +--------------------+ 5 rows inset (0.01 sec)
MariaDB [(none)]> show databasesl; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.206.20' (111) ERROR: Can't connect to the server
unknown [(none)]> show databases; No connection. Trying to reconnect... ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.206.20' (111) ERROR: Can't connect to the server
unknown [(none)]> show databases; No connection. Trying to reconnect... Connection id: 2 Current database: *** NONE ***