实验环境:
[root@vm3 ~]# fdisk -l
[root@vm3 ~]# yum install iscsi-* -y
[root@vm1 ~]# yum install iscsi-* -y
[root@vm2 ~]# yum install iscsi-* -y
[root@vm3 ~]# vim /etc/tgt/targets.conf
[root@vm3 ~]# /etc/init.d/tgtd start
[root@vm3 ~]# tgt-admin -s ##查看状态
[root@vm1 ~]# iscsiadm -m discovery -t st -p 172.25.254.3
172.25.254.3:3260,1 iqn.2018-12.com.example:server.target1
[root@vm1 ~]# iscsiadm -m node -l
[root@vm1 ~]# fdisk -l
[root@vm2 cluster]# iscsiadm -m discovery -t st -p 172.25.254.3
Starting iscsid: [ OK ]
172.25.254.3:3260,1 iqn.2018-12.com.example:server.target1
[root@vm2 cluster]# iscsiadm -m node -l
[root@vm2 ~]# fdisk -l
[root@vm1 ~]# fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x2f2ec414.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f2ec414
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f2ec414
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 8e Linux LVM
Command (m for help): wq
The partition table has been altered!
[root@vm1 ~]# partprobe
[root@vm1 ~]# cat /proc/partitions
major minor #blocks name
8 0 10485760 sda
8 1 512000 sda1
8 2 9972736 sda2
253 0 8953856 dm-0
253 1 1015808 dm-1
8 16 10485760 sdb
8 17 10484736 sdb1
[root@vm2 cluster]# partprobe
[root@vm2 cluster]# cat /proc/partitions
major minor #blocks name
8 0 10485760 sda
8 1 512000 sda1
8 2 9972736 sda2
253 0 8953856 dm-0
253 1 1015808 dm-1
8 16 10485760 sdb
8 17 10484736 sdb1
[root@vm1 ~]# pvcreate /dev/sdb1
[root@vm1 ~]# vgcreate dangdang /dev/sdb1
[root@vm1 ~]# lvcreate -L 4G -n dd dangdang
[root@vm1 ~]# mkfs.ext4 /dev/dangdang/dd ###格式化为ext4文件系统
[root@vm1 ~]# mount /dev/dangdang/dd /mnt/
[root@vm1 ~]# cd /mnt/
[root@vm1 mnt]# ls
lost+found
[root@vm1 mnt]# vim index.html
设置Resources:
ServiceGroup设置:
依次添加三个资源:ip、文件系统、脚本
三、测试
[root@vm1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 8813300 1083332 7282276 13% /
tmpfs 251136 25656 225480 11% /dev/shm
/dev/sda1 495844 33455 436789 8% /boot
/dev/mapper/dangdang-dd 4128448 139260 3779476 4% /var/www/html
[root@vm1 ~]# clusvcadm -r apache -m vm2
Trying to relocate service:apache to vm2...Success
service:apache is now running on vm2
[root@vm2 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 8813300 1026036 7339572 13% /
tmpfs 251136 25656 225480 11% /dev/shm
/dev/sda1 495844 33455 436789 8% /boot
/dev/mapper/dangdang-dd 4128448 139260 3779476 4% /var/www/html
为了实现多个节点对于一个文件系统同时读写操作,GFS使用锁管理器来管理 I/O操作,当一个写进程操作一个文件时,这个文件就被锁定,此时不允许其它进 程进行读写操作,直到这个写进程正常完成才释放锁,只有当锁被释放后,其它读 写进程才能对这个文件进行操作,另外,当一个节点在GFS文件系统上修改数据 后,这种修改操作会通过RHCS底层通信机制立即在其它节点上可见。 双组模式 , 立刻同步,相当于同时写入,所以比主备的使用率高,两边都在用
[root@vm1 ~]# clusvcadm -d apache
Local machine disabling service:apache...Success
1.创建一个新的lvm并格式化
[root@vm1 ~]# lvcreate -L 4G -n dd2 dangdang
Logical volume "dd2" created
[root@vm1 ~]# mkfs.gfs2 -p lock_dlm -j 3 -t westos_dd:mygfs2 /dev/dangdang/dd2
This will destroy any data on /dev/dangdang/dd2.
It appears to contain: symbolic link to `../dm-3'
Are you sure you want to proceed? [y/n] y
Device: /dev/dangdang/dd2
Blocksize: 4096
Device Size 4.00 GB (1048576 blocks)
Filesystem Size: 4.00 GB (1048575 blocks)
Journals: 3
Resource Groups: 16
Locking Protocol: "lock_dlm"
Lock Table: "westos_dd:mygfs2"
UUID: 34694c38-6da1-262b-b8df-11146bce12c8
2.设置开机挂载
在vm1和vm2共同设置
[root@vm1 ~]# vim /etc/fstab
[root@vm1 ~]# mount -a
3测试:
在/var/lib/mysql里面建立一个文件,另外一边可以进行实时更新显示!!!
4.
5.测试
[root@vm1 ~]# cd /var/www/html/
[root@vm1 html]# vim index.html
[root@foundation12 cluster]# curl 172.25.254.100