server3上安装
yum install -y scsi-*
vim /etc/tgt/targets.conf #编写配置文件,设置磁盘共享
/etc/init.d/tgtd start ##打开服务
server2和server3
1 yum install -y iscsi-*
2 iscsiadm -m discovery -t st -p 172.25.61.3 ##发现设备
3 iscsiadm -m node -l ##激活设备
yum install -y mysql-server
fdisk -l ##查看设备
Disk /dev/sdb: 8589 MB, 8589934592 bytes
64 heads, 32 sectors/track, 8192 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
mkfs.ext4 /dev/sdb ##格式化
mount /dev/sdb /var/lib/mysql/
chown mysql.mysql /var/lib/mysql/
ll -d /var/lib/mysql/
[root@server2 ~]# ll -d /var/lib/mysql/
drwxr-xr-x 5 mysql mysql 4096 Apr 25 00:35 /var/lib/mysql/
[root@server1 mysql]# ll -d /var/lib/mysql/
drwxr-xr-x 3 mysql mysql 4096 Apr 25 00:31 /var/lib/mysql/
[root@server2 mysql]# /etc/init.d/mysqld start
Starting mysqld: [ OK ]
[root@server2 mysql]# /etc/init.d/mysqld stop
Stopping mysqld: [ OK ]
[root@server1 ~]# clustat
Cluster Status for redhat_ha @ Thu Apr 25 01:19:14 2019
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, Local, rgmanager
server2 2 Online, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:apache (server1) disabled
service:mysql server2 started
[root@server1 ~]#
[root@server2 ~]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.71 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+---------------------+
| Database |
+---------------------+
| information_schema |
| #mysql50#lost+found |
| mysql |
| test |
+---------------------+
4 rows in set (0.00 sec)
mysql> quit
Bye
[root@server2 ~]# clusvcadm -e apache ##启动apache
[root@server2 ~]# clusvcadm -r apache -m server1 ##将apache服务组切换到server1
[root@server2 ~]# clustat
Cluster Status for redhat_ha @ Thu Apr 25 01:32:16 2019
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
server1 1 Online, rgmanager
server2 2 Online, Local, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:apache (server1) disabled
service:mysql (server2) disabled
[root@server1 ~]# cat /etc/lvm/lvm.conf | grep locking_type
locking_type = 3
# NB. This option only affects locking_type = 1 viz. local file-based
# The external locking library to load if locking_type is set to 2.
[root@server1 ~]# lvmconf --enable-cluster
pvcreate /dev/sdb
vgcreate clustervg /dev/sdb
lvcreate -L 4G -n demo clustervg
[root@server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 8.54g
lv_swap VolGroup -wi-ao---- 992.00m
demo clustervg -wi-a----- 4.00g
[root@server1 ~]# mkfs.gfs2 -t redhat_ha:mygfs2 -p lock_dlm -j 2 /dev/clustervg/demo
-t ##
This will destroy any data on /dev/clustervg/demo.
It appears to contain: symbolic link to `../dm-2'
Are you sure you want to proceed? [y/n] y
Device: /dev/clustervg/demo
Blocksize: 4096
Device Size 4.00 GB (1048576 blocks)
Filesystem Size: 4.00 GB (1048575 blocks)
Journals: 2
Resource Groups: 16
Locking Protocol: "lock_dlm"
Lock Table: "redhat_ha:mygfs2"
UUID: 14354369-3ca3-afbc-c7c2-e006bd041615
[root@server1 ~]# gfs2_tool sb /dev/clustervg/demo all
mh_magic = 0x01161970
mh_type = 1
mh_format = 100
sb_fs_format = 1801
sb_multihost_format = 1900
sb_bsize = 4096
sb_bsize_shift = 12
no_formal_ino = 2
no_addr = 23
no_formal_ino = 1
no_addr = 22
sb_lockproto = lock_dlm
sb_locktable = redhat_ha:mygfs2
uuid = 14354369-3ca3-afbc-c7c2-e006bd041615
mkfs.gfs2
-j #: 指定日志区域的个数,有几个就能够被几个节点所挂载;
-J #: 指定日志区域的大小,默认为128MB;
-p {lock_dlm|lock_nolock}:所使用的锁协议名称,集群需要使用lock_dlm;
-t : 锁表的名称
格式为clustername:fsname, clustername为当前节点所在的集群的名称
这也是为什么要使用RHCS;fsname文件系统名称,自定义,要在当前集群惟一,这也叫锁表名称,表明是分布式锁的范围
。
mount /dev/clustervg/demo /var/lib/mysql/
chown mysql.mysql /var/lib/mysql/
[root@server1 ~]# blkid
/dev/sda1: UUID="4b8f9752-ef3c-47e6-813a-f647f7bfa318" TYPE="ext4"
/dev/sda2: UUID="lqGEmr-XkCp-DUOw-j9Ub-vhH8-u8s7-ccfVfG" TYPE="LVM2_member"
/dev/mapper/VolGroup-lv_root: UUID="5b621447-7a69-47ee-a135-42145ab6dd35" TYPE="ext4"
/dev/mapper/VolGroup-lv_swap: UUID="901affb4-d7b8-465d-9c33-05d048acce68" TYPE="swap"
/dev/mapper/clustervg-demo: LABEL="redhat_ha:mygfs2" UUID="14354369-3ca3-afbc-c7c2-e006bd041615" TYPE="gfs2"
/dev/sdb: UUID="MTLgBz-XZ7z-CcWM-fvhg-8tAo-x8rq-EUPvK8" TYPE="LVM2_member"
[root@server1 ~]# /etc/init.d/mysqld start
Initializing MySQL database: Installing MySQL system tables...
[root@server1 ~]# cd /var/lib/mysql/
[root@server1 mysql]# cp /etc/passwd .
[root@server1 mysql]# ls
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock passwd test
[root@server1 mysql]# ls
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock passwd test
[root@server1 mysql]#
[root@server2 ~]# cd /var/lib/mysql/
[root@server2 mysql]# ls
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock passwd test
[root@server2 mysql]#
vim /etc/fstab
[root@server1 mysql]# umount /var/lib/mysql/
umount: /var/lib/mysql: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@server1 mysql]# mount -a
[root@server1 mysql]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 8813300 1113412 7252196 14% /
tmpfs 510200 31816 478384 7% /dev/shm
/dev/sda1 495844 33431 436813 8% /boot
/dev/mapper/clustervg-demo 4193856 286520 3907336 7% /var/lib/mysql
[root@server1 mysql]#