DRBD + GFS2 + PaceMaker + cLVM構成を構築する
今回もLPIC/Lunuc304勉強がてら構築しました。 以下を参考にしたのですが、そのままやるとどハマりポイントが2点あります。このどハマりポイントでかなりの時間を浪費しました。。。
CentOS 7 : Pacemaker : CLVM + GFS2 設定 : Server World
Redhat公式:
第5章 クラスターでの GFS2 ファイルシステムの設定 Red Hat Enterprise Linux 7 | Red Hat Customer Portal
構成
iSCSIターゲット名:
iqn.2020-07.mukkun.test:storage.target01(ストレージデバイス用)
iqn.2020-07.mukkun.test:storage.target02(フェンスデバイス用)
iSCSIイニシエータ名:
iqn.2020-07.mukkun.test:www.mukkun-clvm1
iqn.2020-07.mukkun.test:www.mukkun-clvm2
+--------------+ +---------------+ | mukkun-clvm1 |192.168.0.75/24|192.168.0.180/24 | mukkun-clvm2 | | pacemaker +---------------+-----------------+ pacemaker | | clvm |eth0 | eth0 | clvm | +--------------+ | +---------------+ | | +------------+ | +------------+ | mukkun- | | | mukkun- | | backend-1 |192.168.0.62/24 | 192.168.0.243/24| backend-2 | | DRBD Pri +-----------------+-----------------+ DRBD Sec | | |eth0 eth0 | | +------------+ +------------+
どハマりポイント
どハマりポイント(1)
iSCSIの設定でtargetcliで設定するのですが、何度やってもaclの認証のところが突破できず、iscsiログインしたデバイスがRead Onlyになってしまいました。 泣く泣く今回はauthのところを飛ばして対応しました。
コンフィグファイルのIDとパスワードはあっているはずなのに謎でした。
どハマりポイント(2)
私は CentOS Linux release 7.8.2003 (Core)
の環境で試したのですが、参考リンクの、フェンスデバイスを作成するコマンドが利用できないということに気がつかず、
何回やり直してもNo Such Device
のエラーが出て、フェンスデバイスのstonithのリソースがエラーで立ち上がらないという現象が起きました。
参考サイトのようにノード名を入れないとエラーになります。この pcmk_host_list=
が超重要です。ちなみにRedhatの公式ドキュメントにも書いてません。
pcs stonith create scsi-shooter fence_scsi devices=/dev/disk/by-id/wwn-[uuid] meta provides=unfencing pcmk_host_list='mukkun-clvm1 mukkun-clvm2' meta provides=unfencing
正しいコマンドは以下です。
pcs stonith create scsi-shooter fence_scsi devices=/dev/disk/by-id/wwn-[uuid] meta provides=unfencing
DRBDの設定
[root@mukkun-backend-2 ~]# drbdmanage add-resource resource02 Operation completed successfully [root@mukkun-backend-2 ~]# drbdmanage add-volume resource02 22GB Operation completed successfully [root@mukkun-backend-2 ~]# drbdmanage list-resources +------------------------------------------------------------------------------------------------------------+ | Name | | State | |------------------------------------------------------------------------------------------------------------| | resource01 | | ok | | resource02 | | ok | +------------------------------------------------------------------------------------------------------------+ [root@mukkun-backend-2 ~]# drbdmanage list-volumes +------------------------------------------------------------------------------------------------------------+ | Name | Vol ID | Size | Minor | | State | |------------------------------------------------------------------------------------------------------------| | resource01 | 0 | 1.86 GiB | 100 | | ok | | resource02 | 0 | 20.49 GiB | 101 | | ok | +------------------------------------------------------------------------------------------------------------+ [root@mukkun-backend-2 ~]# [root@mukkun-backend-2 ~]# drbdmanage deploy-resource resource02 2 Operation completed successfully [root@mukkun-backend-2 ~]# mkfs.xfs /dev/drbd104 [root@mukkun-backend-2 ~]# mkdir /drbd_disk1 [root@mukkun-backend-2 ~]# mount /dev/drbd104 /drbd_disk1 [root@mukkun-backend-2 ~]# df -TH ファイルシス タイプ サイズ 使用 残り 使用% マウント位置 devtmpfs devtmpfs 503M 0 503M 0% /dev tmpfs tmpfs 515M 0 515M 0% /dev/shm tmpfs tmpfs 515M 7.1M 508M 2% /run tmpfs tmpfs 515M 0 515M 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 19G 2.7G 17G 15% / /dev/xvda1 xfs 521M 230M 292M 45% /boot tmpfs tmpfs 103M 0 103M 0% /run/user/0 /dev/drbd104 xfs 22G 34M 22G 1% /drbd_disk1
PaceMakerの設定
両方のノードで設定を行う
yum -y install pacemaker pcs systemctl start pcsd systemctl enable pcsd systemctl stop firewalld.service systemctl disable firewalld.service cat << EOT >> /etc/hosts 192.168.0.75 mukkun-clvm1 192.168.0.180 mukkun-clvm2 EOT
いずれか一方のノードでクラスターの設定
pcs cluster auth mukkun-clvm1 mukkun-clvm2 Username: hacluster Password: mukkun-clvm2: Authorized mukkun-clvm1: Authorized [root@mukkun-clvm1 ~]# pcs cluster setup --name ha_cluster mukkun-clvm1 mukkun-clvm2 [root@mukkun-clvm1 ~]# pcs cluster start --all [root@mukkun-clvm1 ~]# pcs cluster enable --all [root@mukkun-clvm1 ~]# pcs status corosync Membership information ---------------------- Nodeid Votes Name 1 1 mukkun-clvm1 (local) 2 1 mukkun-clvm2 [root@mukkun-clvm1 ~]# pcs status cluster Cluster Status: Stack: corosync Current DC: mukkun-clvm1 (version 1.1.21-4.el7-f14e36fd43) - partition with quorum Last updated: Sun Aug 2 21:59:34 2020 Last change: Sun Aug 2 21:59:05 2020 by hacluster via crmd on mukkun-clvm1 2 nodes configured 0 resources configured PCSD Status: mukkun-clvm2: Online mukkun-clvm1: Online
iSCSIの設定(ターゲット側 )
mukkun-backend-1、mukkun-backend-2でインストールしておく
yum -y install targetcli
今ディスクがあるmukkun-backend-2でiSCSIの設定をする。まずはストレージボリューム用のディスク設定
[root@mukkun-backend-2 ~]# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb49 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> cd backstores/fileio /backstores/fileio> create disk00 /drbd_disk1/disk00.img 19G Created fileio disk00 with size 20401094656 /backstores/fileio> create disk01 /drbd_disk1/disk01.img 1G Created fileio disk01 with size 1073741824 /backstores/fileio> cd /iscsi /iscsi> create iqn.2020-07.mukkun.test:storage.target01 Created target iqn.2020-07.mukkun.test:storage.target01. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /iscsi> cd iqn.2020-07.mukkun.test:storage.target01/tpg1/luns /iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/disk00 Created LUN 0. /iscsi/iqn.20...t01/tpg1/luns> cd ../acls /iscsi/iqn.20...t01/tpg1/acls> create iqn.2020-07.mukkun.test:www.mukkun-clvm1 Created Node ACL for iqn.2020-07.mukkun.test:www.mukkun-clvm1 Created mapped LUN 0. /iscsi/iqn.20...t01/tpg1/acls> create iqn.2020-07.mukkun.test:www.mukkun-clvm2 Created Node ACL for iqn.2020-07.mukkun.test:www.mukkun-clvm2 Created mapped LUN 0. /iscsi/iqn.20...t01/tpg1/acls> cd ../ /iscsi/iqn.20...target01/tpg1> set attribute generate_node_acls=1 Parameter generate_node_acls is now '1'. /backstores/fileio> cd /iscsi /iscsi> create iqn.2020-07.mukkun.test:storage.target02 Created target iqn.2020-07.mukkun.test:storage.target02. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /iscsi> cd iqn.2020-07.mukkun.test:storage.target02/ /iscsi/iqn.20...rage.target02> cd tpg1/ tpg1/acls/ tpg1/luns/ tpg1/portals/ /iscsi/iqn.20...rage.target02> cd tpg1/luns /iscsi/iqn.20...t02/tpg1/luns> create /backstores/fileio/disk01 Created LUN 0. /iscsi/iqn.20...t02/tpg1/luns> cd ../acls /iscsi/iqn.20...t02/tpg1/acls> create iqn.2020-07.mukkun.test:www.mukkun-clvm1 Created Node ACL for iqn.2020-07.mukkun.test:www.mukkun-clvm1 Created mapped LUN 0. /iscsi/iqn.20...t02/tpg1/acls> create iqn.2020-07.mukkun.test:www.mukkun-clvm2 Created Node ACL for iqn.2020-07.mukkun.test:www.mukkun-clvm2 Created mapped LUN 0. /iscsi/iqn.20...t02/tpg1/acls> cd ../ /iscsi/iqn.20...target02/tpg1> set attribute generate_node_acls=1 Parameter generate_node_acls is now '1'. /iscsi/iqn.20...target02/tpg1> cd /
リッスンしているか確認、起動設定
[root@mukkun-backend-2 ~]# ss -napt | grep 3260 LISTEN 0 256 *:3260 *:* [root@mukkun-backend-2 ~]# systemctl enable target Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
確認
[root@mukkun-backend-2 ~]# ls -lh /drbd_disk1/ 合計 0 -rw-r--r-- 1 root root 19G 8月 5 09:28 disk00.img -rw-r--r-- 1 root root 1.0G 8月 5 09:28 disk01.img
[root@mukkun-backend-2 ~]# targetcli targetcli shell version 2.1.fb49 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. ls o- / ......................................................................................................................... [...] o- backstores .............................................................................................................. [...] | o- block .................................................................................................. [Storage Objects: 0] | o- fileio ................................................................................................. [Storage Objects: 2] | | o- disk00 ............................................................ [/drbd_disk1/disk00.img (19.0GiB) write-back activated] | | | o- alua ................................................................................................... [ALUA Groups: 1] | | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized] | | o- disk01 ............................................................. [/drbd_disk1/disk01.img (1.0GiB) write-back activated] | | o- alua ................................................................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized] | o- pscsi .................................................................................................. [Storage Objects: 0] | o- ramdisk ................................................................................................ [Storage Objects: 0] o- iscsi ............................................................................................................ [Targets: 2] | o- iqn.2020-07.mukkun.test:storage.target01 .......................................................................... [TPGs: 1] | | o- tpg1 .................................................................................................. [gen-acls, no-auth] | | o- acls .......................................................................................................... [ACLs: 2] | | | o- iqn.2020-07.mukkun.test:www.mukkun-clvm1 ............................................................. [Mapped LUNs: 1] | | | | o- mapped_lun0 ............................................................................... [lun0 fileio/disk00 (rw)] | | | o- iqn.2020-07.mukkun.test:www.mukkun-clvm2 ............................................................. [Mapped LUNs: 1] | | | o- mapped_lun0 ............................................................................... [lun0 fileio/disk00 (rw)] | | o- luns .......................................................................................................... [LUNs: 1] | | | o- lun0 ...................................................... [fileio/disk00 (/drbd_disk1/disk00.img) (default_tg_pt_gp)] | | o- portals .................................................................................................... [Portals: 1] | | o- 0.0.0.0:3260 ..................................................................................................... [OK] | o- iqn.2020-07.mukkun.test:storage.target02 .......................................................................... [TPGs: 1] | o- tpg1 .................................................................................................. [gen-acls, no-auth] | o- acls .......................................................................................................... [ACLs: 2] | | o- iqn.2020-07.mukkun.test:www.mukkun-clvm1 ............................................................. [Mapped LUNs: 1] | | | o- mapped_lun0 ............................................................................... [lun0 fileio/disk01 (rw)] | | o- iqn.2020-07.mukkun.test:www.mukkun-clvm2 ............................................................. [Mapped LUNs: 1] | | o- mapped_lun0 ............................................................................... [lun0 fileio/disk01 (rw)] | o- luns .......................................................................................................... [LUNs: 1] | | o- lun0 ...................................................... [fileio/disk01 (/drbd_disk1/disk01.img) (default_tg_pt_gp)] | o- portals .................................................................................................... [Portals: 1] | o- 0.0.0.0:3260 ..................................................................................................... [OK] o- loopback ......................................................................................................... [Targets: 0] />
iSCSIの設定(イニシエーター側)
clvm1、clvm2で双方で設定しておく
まずclvm1側
# yum -y install iscsi-initiator-utils ターゲットで設定したiqnにする [root@mukkun-clvm1 ~]# vi /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2020-07.mukkun.test:www.mukkun-clvm1 # iscsiadm -m discovery -t sendtargets -p 192.168.0.243 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target01 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target02 # iscsiadm -m node 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target01 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target02 # iscsiadm -m node -T iqn.2020-07.mukkun.test:storage.target01 --login Logging in to [iface: default, target: iqn.2020-07.mukkun.test:storage.target01, portal: 192.168.0.243,3260] (multiple) Login to [iface: default, target: iqn.2020-07.mukkun.test:storage.target01, portal: 192.168.0.243,3260] successful. # iscsiadm -m node -T iqn.2020-07.mukkun.test:storage.target02 --login Logging in to [iface: default, target: iqn.2020-07.mukkun.test:storage.target02, portal: 192.168.0.243,3260] (multiple) Login to [iface: default, target: iqn.2020-07.mukkun.test:storage.target02, portal: 192.168.0.243,3260] successful. [root@mukkun-clvm1 ~]# iscsiadm -m node 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target01 [root@mukkun-clvm1 ~]# iscsiadm -m session tcp: [7] 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target01 (non-flash) [root@mukkun-clvm1 ~]# [root@mukkun-clvm1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 19G 0 disk sdb 8:16 0 1G 0 disk sr0 11:0 1 1024M 0 rom xvda 202:0 0 20G 0 disk ├─xvda1 202:1 0 500M 0 part /boot └─xvda2 202:2 0 19.5G 0 part ├─centos-root 253:0 0 17.5G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP]
次にmukkun-clvm2側
[root@mukkun-clvm2 ~]# vi /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2020-07.mukkun.test:www.mukkun-clvm2 [root@mukkun-clvm2 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.243 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target01 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target02 [root@mukkun-clvm2 ~]# iscsiadm -m node 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target01 192.168.0.243:3260,1 iqn.2020-07.mukkun.test:storage.target02 [root@mukkun-clvm2 ~]# iscsiadm -m node -T iqn.2020-07.mukkun.test:storage.target01 --login Logging in to [iface: default, target: iqn.2020-07.mukkun.test:storage.target01, portal: 192.168.0.243,3260] (multiple) Login to [iface: default, target: iqn.2020-07.mukkun.test:storage.target01, portal: 192.168.0.243,3260] successful. [root@mukkun-clvm2 ~]# iscsiadm -m node -T iqn.2020-07.mukkun.test:storage.target02 --login Logging in to [iface: default, target: iqn.2020-07.mukkun.test:storage.target02, portal: 192.168.0.243,3260] (multiple) Login to [iface: default, target: iqn.2020-07.mukkun.test:storage.target02, portal: 192.168.0.243,3260] successful. [root@mukkun-clvm2 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 19G 0 disk sdb 8:16 0 1G 0 disk sr0 11:0 1 1024M 0 rom xvda 202:0 0 20G 0 disk ├─xvda1 202:1 0 500M 0 part /boot └─xvda2 202:2 0 19.5G 0 part ├─centos-root 253:0 0 17.5G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP]
PaceMaker + CLVM + GFS2の設定
パッケージインストール
mukkun-clvm1、mukkun-clvm2で実施
yum -y install fence-agents-all lvm2-cluster gfs2-utils lvmconf --enable-cluster reboot
フェンスデバイスの設定
フェンスデバイスを設定します。いずれかのノード上で設定すれば OK です。 なお、以下で設定している /dev/sdb はストレージサーバーから提供されているフェンスデバイス用ディスクを指定しています。
[root@mukkun-clvm1 ~]# cat /proc/partitions major minor #blocks name 202 0 20971520 xvda 202 1 512000 xvda1 202 2 20458496 xvda2 11 0 1048575 sr0 253 0 18317312 dm-0 253 1 2097152 dm-1 8 0 19922944 sda 8 1 19918848 sda1 8 16 1048576 sdb [root@mukkun-clvm1 ~]# ll /dev/disk/by-id | grep sdb lrwxrwxrwx 1 root root 9 8月 7 22:43 scsi-3600140518bf1f7824aa4844966dca55b -> ../../sdb lrwxrwxrwx 1 root root 9 8月 7 22:43 wwn-0x600140518bf1f7824aa4844966dca55b -> ../../sdb [root@mukkun-clvm1 ~]# [root@mukkun-clvm1 ~]# pcs stonith create scsi-shooter fence_scsi devices=/dev/disk/by-id/wwn-0x600140518bf1f7824aa4844966dca55b pcmk_host_list='mukkun-clvm1 mukkun-clvm2' meta provides=unfencing [root@mukkun-clvm1 ~]# pcs property set no-quorum-policy=freeze [root@mukkun-clvm1 ~]# pcs stonith show scsi-shooter Resource: scsi-shooter (class=stonith type=fence_scsi) Attributes: devices=/dev/disk/by-id/wwn-0x600140518bf1f7824aa4844966dca55b pcmk_host_list="mukkun-clvm1 mukkun-clvm2" Meta Attrs: provides=unfencing Operations: monitor interval=60s (scsi-shooter-monitor-interval-60s) [root@mukkun-clvm1 ~]# [root@mukkun-clvm1 ~]# pcs status Cluster name: ha_cluster Stack: corosync Current DC: mukkun-clvm2 (version 1.1.21-4.el7-f14e36fd43) - partition with quorum Last updated: Fri Aug 7 22:45:45 2020 Last change: Fri Aug 7 22:45:16 2020 by root via cibadmin on mukkun-clvm1 2 nodes configured 1 resource configured Online: [ mukkun-clvm1 mukkun-clvm2 ] Full list of resources: scsi-shooter (stonith:fence_scsi): Started mukkun-clvm1 Daemon Status: corosync: active/enabled pacemaker: active/enabled pcsd: active/enabled
LVMの設定準備
当例の場合、事前に sda として認識されている共有ストレージ用デバイスに fdisk で パーティションを作成し、パーティションタイプを LVM に設定しています。backendサーバーで処理します。
[root@mukkun-clvm1 ~]# fdisk -l (略) Disk /dev/sda: 20.4 GB, 20401094656 bytes, 39845888 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 4194304 バイト Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 4194304 バイト [root@mukkun-clvm1 ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xf86fd8b3. コマンド (m でヘルプ): p Disk /dev/sda: 20.4 GB, 20401094656 bytes, 39845888 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 4194304 バイト Disk label type: dos ディスク識別子: 0xf86fd8b3 デバイス ブート 始点 終点 ブロック Id システム コマンド (m でヘルプ): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p パーティション番号 (1-4, default 1): 最初 sector (8192-39845887, 初期値 8192): 初期値 8192 を使います Last sector, +sectors or +size{K,M,G} (8192-39845887, 初期値 39845887): 初期値 39845887 を使います Partition 1 of type Linux and of size 19 GiB is set コマンド (m でヘルプ): p Disk /dev/sda: 20.4 GB, 20401094656 bytes, 39845888 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 4194304 バイト Disk label type: dos ディスク識別子: 0xf86fd8b3 デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 8192 39845887 19918848 83 Linux コマンド (m でヘルプ): t Selected partition 1 Hex code (type L to list all codes): L 0 空 24 NEC DOS 81 Minix / 古い Li bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux スワップ c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 隠し C: ド c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux 拡張領域 c7 Syrinx 5 拡張領域 41 PPC PReP Boot 86 NTFS ボリューム da 非 FS データ 6 FAT16 42 SFS 87 NTFS ボリューム db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux プレーン de Dell ユーティリ 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX ブート可能 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 ブートマネ 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad ハ eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 拡張領域 (L 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC 11 隠し FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq 診断 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 隠し FAT16 <32M 61 SpeedStor ab Darwin ブート f2 DOS セカンダリ 16 隠し FAT16 63 GNU HURD または af HFS / HFS+ fb VMware VMFS 17 隠し HPFS/NTFS 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI スワップ fd Linux raid 自動 1b 隠し W95 FAT32 70 DiskSecure Mult bb 隠し Boot Wizar fe LANstep 1c 隠し W95 FAT32 75 PC/IX be Solaris ブート ff BBT 1e 隠し W95 FAT16 80 古い Minix Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' コマンド (m でヘルプ): p Disk /dev/sda: 20.4 GB, 20401094656 bytes, 39845888 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 4194304 バイト Disk label type: dos ディスク識別子: 0xf86fd8b3 デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 8192 39845887 19918848 8e Linux LVM コマンド (m でヘルプ): w パーティションテーブルは変更されました! ioctl() を呼び出してパーティションテーブルを再読込みします。 ディスクを同期しています。 [root@mukkun-clvm1 ~]# fdisk -l /dev/sda Disk /dev/sda: 20.4 GB, 20401094656 bytes, 39845888 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 4194304 バイト Disk label type: dos ディスク識別子: 0xf86fd8b3 デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 8192 39845887 19918848 8e Linux LVM
リソースの追加
[root@mukkun-clvm1 ~]# pcs resource create dlm ocf:pacemaker:controld op monitor interval=30s on-fail=fence clone interleave=true ordered=true [root@mukkun-clvm1 ~]# pcs resource create clvmd ocf:heartbeat:clvm op monitor interval=30s on-fail=fence clone interleave=true ordered=true [root@mukkun-clvm1 ~]# pcs constraint order start dlm-clone then clvmd-clone [root@mukkun-clvm1 ~]# pcs constraint colocation add clvmd-clone with dlm-clone [root@mukkun-clvm1 ~]# pcs status resources Clone Set: dlm-clone [dlm] Started: [ mukkun-clvm1 mukkun-clvm2 ] Clone Set: clvmd-clone [clvmd] Started: [ mukkun-clvm1 mukkun-clvm2 ]
共有ストレージ用のデバイスにボリュームを作成し、GFS2 ファイルシステムでフォーマットします。いずれかのノード上で設定すれば OK です。
[root@mukkun-clvm1 ~]# pvcreate /dev/sda1 Physical volume "/dev/sda1" successfully created [root@mukkun-clvm1 ~]# vgcreate -cy vg_cluster /dev/sda1 Clustered volume group "vg_cluster" successfully created [root@mukkun-clvm1 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda1 vg_cluster lvm2 a-- 18.99g 18.99g /dev/xvda2 centos lvm2 a-- <19.51g 40.00m [root@mukkun-clvm1 ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <19.51g 40.00m vg_cluster 1 0 0 wz--nc 18.99g 18.99g [root@mukkun-clvm1 ~]# lvcreate -l100%FREE -n lv_cluster vg_cluster Logical volume "lv_cluster" created. [root@mukkun-clvm1 ~]# mkfs.gfs2 -p lock_dlm -t ha_cluster:gfs2 -j 2 /dev/vg_cluster/lv_cluster /dev/vg_cluster/lv_cluster is a symbolic link to /dev/dm-2 This will destroy any data on /dev/dm-2 Are you sure you want to proceed? [y/n] y Discarding device contents (may take a while on large devices): Done Adding journals: Done Building resource groups: Done Creating quota file: Done Writing superblock and syncing: Done Device: /dev/vg_cluster/lv_cluster Block size: 4096 Device size: 18.99 GB (4978688 blocks) Filesystem size: 18.99 GB (4978684 blocks) Journals: 2 Journal size: 64MB Resource groups: 78 Locking protocol: "lock_dlm" Lock table: "ha_cluster:gfs2" UUID: 36049878-bbf3-433a-8ed3-6366168efa55
共有ストレージをリソースに追加します。いずれかのノード上で設定すれば OK です。
[root@mukkun-clvm1 ~]# pcs resource create fs_gfs2 Filesystem \ > device="/dev/vg_cluster/lv_cluster" directory="/mnt" fstype="gfs2" \ > options="noatime,nodiratime" op monitor interval=10s on-fail=fence clone interleave=true Assumed agent name 'ocf:heartbeat:Filesystem' (deduced from 'Filesystem') [root@mukkun-clvm1 ~]# pcs resource show Clone Set: dlm-clone [dlm] Started: [ mukkun-clvm1 mukkun-clvm2 ] Clone Set: clvmd-clone [clvmd] Started: [ mukkun-clvm1 mukkun-clvm2 ] Clone Set: fs_gfs2-clone [fs_gfs2] Started: [ mukkun-clvm1 mukkun-clvm2 ] [root@mukkun-clvm1 ~]# pcs constraint order start clvmd-clone then fs_gfs2-clone Adding clvmd-clone fs_gfs2-clone (kind: Mandatory) (Options: first-action=start then-action=start) [root@mukkun-clvm1 ~]# pcs constraint colocation add fs_gfs2-clone with clvmd-clone [root@mukkun-clvm1 ~]# pcs constraint show Location Constraints: Ordering Constraints: start dlm-clone then start clvmd-clone (kind:Mandatory) start clvmd-clone then start fs_gfs2-clone (kind:Mandatory) Colocation Constraints: clvmd-clone with dlm-clone (score:INFINITY) fs_gfs2-clone with clvmd-clone (score:INFINITY) Ticket Constraints: [root@mukkun-clvm1 ~]# pcs status Cluster name: ha_cluster Stack: corosync Current DC: mukkun-clvm2 (version 1.1.21-4.el7-f14e36fd43) - partition with quorum Last updated: Fri Aug 7 22:52:08 2020 Last change: Fri Aug 7 22:51:33 2020 by root via cibadmin on mukkun-clvm1 2 nodes configured 7 resources configured Online: [ mukkun-clvm1 mukkun-clvm2 ] Full list of resources: scsi-shooter (stonith:fence_scsi): Started mukkun-clvm1 Clone Set: dlm-clone [dlm] Started: [ mukkun-clvm1 mukkun-clvm2 ] Clone Set: clvmd-clone [clvmd] Started: [ mukkun-clvm1 mukkun-clvm2 ] Clone Set: fs_gfs2-clone [fs_gfs2] Started: [ mukkun-clvm1 mukkun-clvm2 ] Daemon Status: corosync: active/enabled pacemaker: active/enabled pcsd: active/enabled
設定確認
mukkun-clvm1側
[root@mukkun-clvm1 ~]# df -Th /mnt/ ファイルシス タイプ サイズ 使用 残り 使用% マウント位置 /dev/mapper/vg_cluster-lv_cluster gfs2 19G 131M 19G 1% /mnt
mukkun-clvm2側
ファイルシス タイプ サイズ 使用 残り 使用% マウント位置 /dev/mapper/vg_cluster-lv_cluster gfs2 19G 131M 19G 1% /mnt
PaceMaker + corosync in Centos6
LPIC304の勉強として。 PaceMakerはCentos7で使ったことあるのですが、Centos6のPaceMakerはあまり経験がないので構築してみました。 VIPとhttpdリソースを使って、VIPにアクセスするとWebが表示されるような構成です。
構成
ホスト名 | IP | VIP |
---|---|---|
centos6-1 | 192.168.0.102 | 192.168.0.100 |
centos6-2 | 192.168.0.156 |
インストール
yum -y install pacemaker # crmコマンドをインストール wget -P /etc/yum.repos.d/ http://download.opensuse.org/repositories/network:ha-clustering:Stable/RedHat_RHEL-6/network:ha-clustering:Stable.repo yum -y install crmsh
認証設定
両ノードとも以下の設定を行い、内容を揃える。
vi /etc/ha.d/authkeys auth 1 1 sha1 secret chmod 600 /etc/ha.d/authkeys
コンフィグ設定
今回はcloudStackで建てたサーバーを使う。CloudStackはマルチキャストが使えないので、udpuの方を使います。
記法は古い形式の member
という記法を使います。新しいと node
という記法になるらしい。
https://qiita.com/tukiyo3/items/162e131007365fc4fe80
# cp /etc/corosync/corosync.conf.example.udpu /etc/corosync/corosync.conf # vi /etc/corosync/corosync.conf # cat /etc/corosync/corosync.conf # Please read the corosync.conf.5 manual page compatibility: whitetank aisexec { user: root group: root } service { name: pacemaker ver: 0 use_mgmtd: yes } totem { version: 2 secauth: off interface { member { memberaddr: 192.168.0.102 } member { memberaddr: 192.168.0.156 } ringnumber: 0 bindnetaddr: 192.168.0.0 mcastport: 5405 ttl: 1 } transport: udpu } logging { fileline: off to_logfile: yes to_syslog: yes logfile: /var/log/cluster/corosync.log debug: off timestamp: on logger_subsys { subsys: AMF debug: off } }
ログのパーミッション変更とサービス起動
両方のノードで行う。
chown -R hacluster. /var/log/cluster /etc/rc.d/init.d/corosync start
確認
crm_mon
コマンドは -1
をつけないと更新型の表示になる、 -1
をつけると一度きりの表示。
[root@centos6-1 ~]# crm_mon -1 Stack: classic openais (with plugin) Current DC: centos6-2 (version 1.1.18-3.el6-bfe4e80420) - partition with quorum Last updated: Sat Jul 25 21:51:34 2020 Last change: Sat Jul 25 18:53:23 2020 by hacluster via crmd on centos6-2 2 nodes configured (2 expected votes) 0 resources configured Online: [ centos6-1 centos6-2 ] No active resources [root@centos6-1 ~]# crm status Stack: classic openais (with plugin) Current DC: centos6-2 (version 1.1.18-3.el6-bfe4e80420) - partition with quorum Last updated: Sat Jul 25 22:01:49 2020 Last change: Sat Jul 25 18:53:23 2020 by hacluster via crmd on centos6-2 2 nodes configured (2 expected votes) 0 resources configured Online: [ centos6-1 centos6-2 ] No resources
初期設定・リソース設定
# STONITH無効化 crm configure property \ stonith-enabled=false # quorum無効化 (ノードの数が半分以下になったときはクラスタとしてサービス提供不可と見なすが2台構成で1台落ちたらその状態になるので無効化) crm configure property \ no-quorum-policy=ignore # ノード復帰時に自動でリソースを元のノード上に移そうとするのを止める crm configure rsc_defaults \ resource-stickiness=100
設定確認
[root@centos6-1 ~]# crm configure show node centos6-1 node centos6-2 property cib-bootstrap-options: \ have-watchdog=false \ dc-version=1.1.18-3.el6-bfe4e80420 \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes=2 \ stonith-enabled=false \ no-quorum-policy=ignore rsc_defaults rsc-options: \ resource-stickiness=100
VIPの設定
# crm configure primitive vip ocf:heartbeat:IPaddr2 \ params ip="192.168.0.100" \ nic="eth0” \ cidr_netmask="24" \ op start interval="0s" timeout="60s" \ op monitor interval="5s" timeout="20s" \ op stop interval="0s" timeout="60s" # crm configure show node centos6-1 node centos6-2 primitive vip IPaddr2 \ params ip=192.168.0.100 nic=eth0 cidr_netmask=24 \ op start interval=0s timeout=60s \ op monitor interval=5s timeout=20s \ op stop interval=0s timeout=60s property cib-bootstrap-options: \ have-watchdog=false \ dc-version=1.1.18-3.el6-bfe4e80420 \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes=2 \ stonith-enabled=false \ no-quorum-policy=ignore rsc_defaults rsc-options: \ resource-stickiness=100
VIPがついたことを確認
[root@centos6-1 ~]# ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN inet 127.0.0.1/8 scope host lo 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.0.102/24 brd 192.168.0.255 scope global eth0 inet 192.168.0.100/24 brd 192.168.0.255 scope global secondary eth0
ここでいったん設定確認
[root@centos6-1 ~]# crm_mon -1 Stack: classic openais (with plugin) Current DC: centos6-2 (version 1.1.18-3.el6-bfe4e80420) - partition with quorum Last updated: Sat Jul 25 22:19:00 2020 Last change: Sat Jul 25 22:17:13 2020 by root via cibadmin on centos6-1 2 nodes configured (2 expected votes) 1 resource configured Online: [ centos6-1 centos6-2 ] Active resources: vip (ocf::heartbeat:IPaddr2): Started centos6-1
httpd設定
両方のサーバーで設定します
コンフィグ設定
vi /etc/httpd/conf/httpd.conf # 921-926行目:コメント解除しアクセス許可範囲変更 <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 127.0.0.1 10.0.0.0/24 </Location>
httpdのリソース設定と同居設定
crm configure primitive httpd ocf:heartbeat:apache \ params configfile="/etc/httpd/conf/httpd.conf" \ port="80" \ op start interval="0s" timeout="60s" \ op monitor interval="5s" timeout="20s" \ op stop interval="0s" timeout="60s"
同居設定
crm configure colocation coloc_1 inf: vip httpd
同居設定しない場合はグループ化でも良い
crm configure group webserver vip httpd
確認(グループ化した場合)
[root@centos6-1 ~]# crm status Stack: classic openais (with plugin) Current DC: centos6-2 (version 1.1.18-3.el6-bfe4e80420) - partition with quorum Last updated: Sat Jul 25 22:28:32 2020 Last change: Sat Jul 25 22:28:17 2020 by hacluster via cibadmin on centos6-2 2 nodes configured (2 expected votes) 2 resources configured Online: [ centos6-1 centos6-2 ] Full list of resources: Resource Group: webserver vip (ocf::heartbeat:IPaddr2): Started centos6-1 httpd (ocf::heartbeat:apache): Started centos6-1 Failed Actions: * httpd_monitor_0 on centos6-1 'unknown error' (1): call=12, status=complete, exitreason='', last-rc-change='Sat Jul 25 22:24:16 2020', queued=0ms, exec=102ms [root@centos6-1 ~]# crm configure show node centos6-1 node centos6-2 primitive httpd apache \ params configfile="/etc/httpd/conf/httpd.conf" port=80 \ op start interval=0s timeout=60s \ op monitor interval=5s timeout=20s \ op stop interval=0s timeout=60s primitive vip IPaddr2 \ params ip=192.168.0.100 nic=eth0 cidr_netmask=24 \ op start interval=0s timeout=60s \ op monitor interval=5s timeout=20s \ op stop interval=0s timeout=60s group webserver vip httpd property cib-bootstrap-options: \ have-watchdog=false \ dc-version=1.1.18-3.el6-bfe4e80420 \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes=2 \ stonith-enabled=false \ no-quorum-policy=ignore rsc_defaults rsc-options: \ resource-stickiness=100
アクセスしてみる
グローバルIPにアクセスするとこんな感じです。
メンテナンスモードにする
クラスタ全体をメンテナンスモードにします。httpdサービス自体は継続されます。
[root@centos6-1 ~]# crm configure property maintenance-mode=true [root@centos6-1 ~]# crm status Stack: classic openais (with plugin) Current DC: centos6-2 (version 1.1.18-3.el6-bfe4e80420) - partition with quorum Last updated: Sat Jul 25 22:57:31 2020 Last change: Sat Jul 25 22:57:28 2020 by root via cibadmin on centos6-1 2 nodes configured (2 expected votes) 2 resources configured *** Resource management is DISABLED *** The cluster will not attempt to start, stop or recover services Online: [ centos6-1 centos6-2 ] Full list of resources: Resource Group: webserver vip (ocf::heartbeat:IPaddr2): Started centos6-1 (unmanaged) httpd (ocf::heartbeat:apache): Started centos6-1 (unmanaged) Failed Actions: * httpd_monitor_0 on centos6-1 'unknown error' (1): call=12, status=complete, exitreason='', last-rc-change='Sat Jul 25 22:24:16 2020', queued=0ms, exec=102ms [root@centos6-1 ~]# ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN inet 127.0.0.1/8 scope host lo 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.0.102/24 brd 192.168.0.255 scope global eth0 inet 192.168.0.100/24 brd 192.168.0.255 scope global secondary eth0
メンテナンスモードを解除します。
[root@centos6-1 ~]# crm configure property maintenance-mode=false [root@centos6-1 ~]# [root@centos6-1 ~]# crm status Stack: classic openais (with plugin) Current DC: centos6-2 (version 1.1.18-3.el6-bfe4e80420) - partition with quorum Last updated: Sat Jul 25 22:58:49 2020 Last change: Sat Jul 25 22:58:45 2020 by root via cibadmin on centos6-1 2 nodes configured (2 expected votes) 2 resources configured Online: [ centos6-1 centos6-2 ] Full list of resources: Resource Group: webserver vip (ocf::heartbeat:IPaddr2): Started centos6-1 httpd (ocf::heartbeat:apache): Started centos6-1 Failed Actions: * httpd_monitor_0 on centos6-1 'unknown error' (1): call=12, status=complete, exitreason='', last-rc-change='Sat Jul 25 22:24:16 2020', queued=0ms, exec=102ms
フェイルオーバーしてみる
フェイルオーバーしてみます。現在centos6-1というサーバーにリソースがあるので、centos6-2に移します。現在リソースがあるノードに対して、 crm node stanby [node_name]
でフェイルオーバーされます。
[root@centos6-1 ~]# crm node standby centos6-1 [root@centos6-1 ~]# crm status Stack: classic openais (with plugin) Current DC: centos6-2 (version 1.1.18-3.el6-bfe4e80420) - partition with quorum Last updated: Sat Jul 25 23:01:02 2020 Last change: Sat Jul 25 23:01:00 2020 by root via crm_attribute on centos6-1 2 nodes configured (2 expected votes) 2 resources configured Node centos6-1: standby Online: [ centos6-2 ] Full list of resources: Resource Group: webserver vip (ocf::heartbeat:IPaddr2): Started centos6-2 httpd (ocf::heartbeat:apache): Started centos6-2 Failed Actions: * httpd_monitor_0 on centos6-1 'unknown error' (1): call=12, status=complete, exitreason='', last-rc-change='Sat Jul 25 22:24:16 2020', queued=0ms, exec=102ms
IPはcentos6-2に移動したことがわかりました。
[root@centos6-2 ~]# ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN inet 127.0.0.1/8 scope host lo 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.0.156/24 brd 192.168.0.255 scope global eth0 inet 192.168.0.100/24 brd 192.168.0.255 scope global secondary eth0
Webはこんな感じです。
スタンバイ状態から復旧させます。復旧させても、リソースはcentos6-2のままです。
[root@centos6-1 ~]# crm node online centos6-1 [root@centos6-1 ~]# crm status Stack: classic openais (with plugin) Current DC: centos6-2 (version 1.1.18-3.el6-bfe4e80420) - partition with quorum Last updated: Sat Jul 25 23:01:42 2020 Last change: Sat Jul 25 23:01:39 2020 by hacluster via crm_attribute on centos6-2 2 nodes configured (2 expected votes) 2 resources configured Online: [ centos6-1 centos6-2 ] Full list of resources: Resource Group: webserver vip (ocf::heartbeat:IPaddr2): Started centos6-2 httpd (ocf::heartbeat:apache): Started centos6-2 Failed Actions: * httpd_monitor_0 on centos6-1 'unknown error' (1): call=12, status=complete, exitreason='', last-rc-change='Sat Jul 25 22:24:16 2020', queued=0ms, exec=102ms
CloudStackでHAproxyを利用する
概要
3回にわたってCloudStackのVMを使ってLVS(Linux Virtual Server)を構成してみました。
- ipvsadmを利用
CloudStackでLVS(Linux Virtual Server) - mukkun0824’s blog
- Ldirectordを利用
CloudStackでLVS(Linux Virtual Server) -Ldirectordを利用編 - mukkun0824’s blog
- keepalivedを利用してlvsの冗長化
CloudStackでLVS(Linux Virtual Server) -keepalivedを利用編 - mukkun0824’s blog
今回は、今までのようなL4のトランスポート層の話ではなく、L7のアプリケーション層での処理になります。したがって、バックエンド側での作業がほぼ必要なく、今までの方法よりは設定は楽です。HAproxyはその名の通りhttpリクエストを代理受付してくれます。
参考
https://www.server-world.info/query?os=CentOS_7&p=haproxy&f=1
構成
構成は全く前回と同じですが、今回はHAproxyの設定とログの設定を行います。HAproxyサーバーがhttpリクエストを処理してくれるので、送信元のヘッダ情報をバックエンド側に表示させる必要があります。これをforwarderの設定といいますが、「X-Forwarded-For」の設定もHAproxy上とバックエンドサーバーのhttpd.confで行います。まあVIPを設定する必要もないのですが、前回のまま付けています。
(internet) | | グローバルIP +---------+-----------+ | Virtual Router | +---------+-----------+ | 192.168.0.1/24 GW | | | eth0|192.168.0.223/24 eth0:0 |192.168.0.100/24 +-----------+ | HAproxy | | | +-----+-----+ | +------------+ | +------------+ | Backend01 |192.168.0.62/24| 192.168.0.243/24| Backend02 | | Web Server +------------+--------------------+ Web Server | | |eth0 eth0 | | +------------+ +------------+
HAProxyインストール・設定
念のためhostsに追加しておきます
[root@mukkun-haproxy-server ~]# cat /etc/hosts 192.168.0.223 mukkun-haproxy-server 192.168.0.62 mukkun-backend-1 192.168.0.243 mukkun-backend-2 yum -y install haproxy mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.org
設定ファイルを編集します
vi /etc/haproxy/haproxy.cfg global # ログの出力先とログレベル log 127.0.0.1 local2 info chroot /var/lib/haproxy pidfile /var/run/haproxy.pid # プロセス毎の最大接続数 maxconn 256 # 実行ユーザー/グループ user haproxy group haproxy # デーモンとして起動 daemon defaults # レイヤー7で負荷分散 mode http # ログ設定は global を継承 log global # HTTP リクエストログ取得 option httplog # バックエンドが応答しない場合のタイムアウト時間 timeout connect 10s # クライアントサイドのタイムアウト時間 timeout client 30s # サーバーサイドのタイムアウト時間 timeout server 30s # フロントエンドを定義 ( http-in の箇所は任意の名前 ) frontend http-in # 80ポートで待ち受け bind *:80 # デフォルトのバックエンドを定義 default_backend backend_servers # X-Forwarded-For ヘッダーを渡す option forwardfor # バックエンドを定義 backend backend_servers # ラウンドロビンで負荷分散 balance roundrobin # バックエンドサーバーを定義 server mukkun-backend-1 192.168.0.62:80 check server mukkun-backend-2 192.168.0.243:80 check
サービス起動します
systemctl start haproxy
ログを取得できるようにrsyslog修正
vi /etc/rsyslog.conf 15,16行目:コメント解除, 17行目:追記 $ModLoad imudp $UDPServerRun 514 $AllowedSender UDP, 127.0.0.1 54行目:以下のように変更 *.info;mail.none;authpriv.none;cron.none,local2.none /var/log/messages local2.* /var/log/haproxy.log
サービス再起動します。
systemctl restart rsyslog
BackEndServer:設定
バックエンドサーバーのhttpもログ変更
vi /etc/httpd/conf/httpd.conf # 196行目:変更 LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
サービス再起動します。
systemctl restart httpd
これで前と同じようにグローバルIPでWebアクセスすると2台に負荷分散されます。
CloudStackでLVS(Linux Virtual Server) -keepalivedを利用編
概要
前回、前々回とCloudStackのVMを使ってLVS(Linux Virtual Server)を構成してみました。
- ipvsadmを利用
CloudStackでLVS(Linux Virtual Server) - mukkun0824’s blog
- Ldirectordを利用
CloudStackでLVS(Linux Virtual Server) -Ldirectordを利用編 - mukkun0824’s blog
ただ、上記の構成だとlvsは1台しかなく、lvsの1台がダウンすると終わりなので、lvsを2台構成にします。その2台の疎通にはkeepalivedを利用します。 これもLPIC304の勉強がてらCentos7で構築しています。
参考
CentOS 7 : LVS + Keepalived の設定 : Server World
構成
構成は以下のようになります。VIPなどは変わりません。Ldirectordではなく、ipvsadmをそのまま利用します。
(internet) | | グローバルIP +---------+-----------+ | Virtual Router | +---------+-----------+ | 192.168.0.1/24 GW | VIP:192.168.0.100/24 | +-----------+ | +------------+ | lvs1 |192.168.0.223/24|192.168.0.104/24 | lvs2 | |keepalived +------------+---------------------+ keepalived | | |eth0 | eth0 | | +-----------+ | +------------+ | | +------------+ | +------------+ | Backend01 |192.168.0.62/24| 192.168.0.243/24| Backend02 | | Web Server +------------+--------------------+ Web Server | | |eth0 eth0 | | +------------+ +------------+
lvsサーバー:インストール・設定
cloudStackでの操作
(1) 事前にセカンダリIP192.168.0.100を付けておく。
(2) グローバルIPのNATの設定で、セカンダリIP 192.168.0.100へNAT設定しておく(送信元NATのグローバルIPではなく、別で用意する)
firewalld 止める
systemctl status firewalld.service systemctl stop firewalld.service systemctl disable firewalld.service systemctl status firewalld.service
インストール・設定
lvs1、lvs2共に以下の作業を行います。
yum -y install ipvsadm keepalived echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf sysctl -p touch /etc/sysconfig/ipvsadm systemctl start ipvsadm systemctl enable ipvsadm cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.org
設定が残っている場合は-Cでクリアしておく。
ipvsadm -C ipvsadm -l IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn
keepalivedの設定
これもlvs1、lvs2共に以下の作業を行います。 以下のように設定ファイルを編集します。lvs1とlvs2の設定ファイルの差分は、「priority」のところだけです。どちらか(優先度をあげたい方)を高めにしておきます。今回はIPをNATしないので、DR(ダイレクトルーティング)で行います。
ちなみに、VRRP はVirtualRouterRedundancyProtocolのことで、ルーター間の疎通監視プロトコルのことです。死活監視できるメソッドは以下の通りです。
[root@mukkun-lvs1 ~]# cat /etc/keepalived/keepalived.conf global_defs { } vrrp_instance VI_1 { # 両方でバックアップとする(プライオリティで制御する) state BACKUP # 監視させるインターフェース interface eth0 # 仮想ルータのID virtual_router_id 51 # プライオリティ (双方のサーバーで値を変更) # (値の大きい方が優先度が高くなる) priority 100 # プライオリティが高い方へ復帰しない nopreempt # VRRP送信間隔 advert_int 1 # VRRPをやり取りする際の認証情報 authentication { auth_type PASS auth_pass mukkun-test } virtual_ipaddress { # 仮想IPアドレス 192.168.0.100/24 dev eth0 } } virtual_server 192.168.0.100 80 { # 監視する間隔 delay_loop 3 # 負荷分散方式 lvs_sched rr # パケットの転送方式 lvs_method DR protocol TCP # バックエンドサーバー#1 real_server 192.168.0.62 80 { weight 1 HTTP_GET { url { # 監視先URL path / # 正常な場合のステータスコード status_code 200 } # タイムアウト時間(秒) connect_timeout 3 } } # バックエンドサーバー#2 real_server 192.168.0.243 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 } } }
サービス起動
lvs1でサービス起動
[root@mukkun-lvs1 ~]# systemctl start keepalived
lvs2でもサービス起動
[root@mukkun-lvs2 ~]# systemctl start keepalived
2台のLVSサーバーのkeepalivedのサービスをあげると「priority」を高めに設定した方のサーバーにVIPがつきます。
[root@mukkun-lvs1 ~]# ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.0.223/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.0.100/24 scope global secondary eth0 valid_lft forever preferred_lft forever
lvs1のkeepalivedを止めるとlvs2にVIPが動きます。バックエンドへの通信は問題ありません。
[root@mukkun-lvs2 ~]# ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.0.104/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.0.100/24 scope global secondary eth0 valid_lft forever preferred_lft forever
BackEndServer:設定
BackEnd(リアルサーバー)側の設定は前回と変更なしです。
これで前回と同じようにグローバルIPでWebアクセスすると2台に負荷分散されます。lvs1をダウンさせるとlvs2に処理が移行し、Webアクセスは問題ありません。CloudStack的にはlvs1のVIP(192.168.0.100/24)として静的NATしているのですが、lvs1を落としてもlvs2にNATしてくれます。
CloudStackでLVS(Linux Virtual Server) -Ldirectordを利用編
概要
前回、CloudStackのVMを使ってLVS(Linux Virtual Server)を構成してみました。
CloudStackでLVS(Linux Virtual Server) - mukkun0824’s blog
LPIC304の勉強がてらということで、今回はLdirectordを利用してみます。これもCentos7の記事があまりないので、導入時だけ少し苦労しますが、設定方法はCentos6と変わりません。
参考
https://enterprisezine.jp/iti/detail/228
http://etom.hatenablog.com/entry/2013/08/23/022656
https://thinkit.co.jp/story/2011/07/21/2201?nopaging=1
構成
構成は全く前回と同じですが、ipvsadmのコマンドを利用せず、Ldirectordの設定だけで行います。負荷状況があまりなければ、どっちを使うかは好みのレベルかもしれませんが、Ldirectordの方が設定は楽です。
(internet) | | グローバルIP +---------+-----------+ | Virtual Router | +---------+-----------+ | 192.168.0.1/24 GW | | | eth0|192.168.0.223/24 eth0:0 |192.168.0.100/24 +-----------+ | LVS | | Ldirectord| +-----+-----+ | +------------+ | +------------+ | Backend01 |192.168.0.62/24| 192.168.0.243/24| Backend02 | | Web Server +------------+--------------------+ Web Server | | |eth0 eth0 | | +------------+ +------------+
lvsサーバー:インストール・設定
cloudStackでの操作
(1) 事前にセカンダリIP192.168.0.100を付けておく。
(2) グローバルIPのNATの設定で、セカンダリIP 192.168.0.100へNAT設定しておく(送信元NATのグローバルIPではなく、別で用意する)
VIPつける
ip addr add 192.168.0.100/24 dev eth0
firewalld 止める
systemctl status firewalld.service systemctl stop firewalld.service systemctl disable firewalld.service systemctl status firewalld.service
Ldirectordの設定
rpmパッケージをサーバーに入れます なぜかWebからしかダウンロードできないので、webからダウンロードします。 https://ja.osdn.net/projects/linux-ha/downloads/71663/pacemaker-repo-1.1.21-1.1.el7.x86_64.rpm/
rpmファイルをインストール
[root@mukkun-lvs ~]# rpm -ivh pacemaker-repo-1.1.21-1.1.el7.x86_64.rpm 準備しています... ################################# [100%] 更新中 / インストール中... 1:pacemaker-repo-1.1.21-1.1.el7 ################################# [100%]
heartbeat-ldirectordをインストール(ipvsadmも入っていなければ入れてください。)
yum -y install ipvsadm #入ってなければ yum -y install heartbeat-ldirectord
バージョン確認
[root@mukkun-lvs ~]# ldirectord --version Linux Director v1.186-ha 1999-2006 Jacob Rief, Horms and others <http://www.vergenet.net/linux/ldirectord/> ldirectord comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details.
コンフィグファイルコピー
cp /usr/share/doc/ldirectord-4.3.0/ldirectord.cf /etc/ha.d/ldirectord.cf
コンフィグファイル記述
[root@mukkun-lvs ~]# cat /etc/ha.d/ldirectord.cf | grep -v ^# checktimeout=3 checkinterval=1 autoreload=yes logfile="/var/log/ldirectord.log" virtual=192.168.0.100:80 real=192.168.0.62:80 gate real=192.168.0.243:80 gate service=http scheduler=rr protocol=tcp checktype=negotiate checkport=80 request="index.html"
サービス起動
[root@mukkun-lvs ~]# systemctl start ldirectord.service
設定確認
IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.0.100:80 rr -> 192.168.0.62:80 Route 1 0 0 -> 192.168.0.243:80 Route 1 0 1
BackEndServer:設定
BackEnd(リアルサーバー)側の設定は前回と変更なしです。
これで前回と同じようにグローバルIPでWebアクセスすると2台に負荷分散されます。
CloudStackでLVS(Linux Virtual Server)
概要
CloudStackのVMを使ってLVS(Linux Virtual Server)を構成してみます。 CloudStackの場合、機能として負荷分散機能を持っているので、わざわざLVSで構築する必要ないのですが、LPIC304の勉強がてら構築してみました。
参考
https://www.server-world.info/query?os=CentOS_7&p=lvs http://dokuwiki.fl8.jp/01_linux/01_net/23_lvs_on_cloudstack
構成
本当はLVSサーバーにNIC2つ・VLAN2つとかできれば良いのですが、環境がないのでroutingモードで試してみます。 CloudStackの場合、上位のVirtual RouterでNATされるので、NATされた状態で構成を考えます。 LVSサーバーの eth0 へ来た HTTP パケットを Backend01, Backend02 の Webサーバーへ routing 方式で負荷分散します。 Virtual RouterはCloudStackの初期機能です。今回構築したのは、LVSとBackend01とBackend02だけです。
(internet) | | グローバルIP +---------+-----------+ | Virtual Router | +---------+-----------+ | 192.168.0.1/24 GW | | | eth0|192.168.0.223/24 eth0:0 |192.168.0.100/24 +----------+ | LVS | +-----+----+ | +------------+ | +------------+ | Backend01 |192.168.0.62/24| 192.168.0.243/24| Backend02 | | Web Server +------------+--------------------+ Web Server | | |eth0 eth0 | | +------------+ +------------+
lvsサーバー:インストール・設定
cloudStackでの操作
(1) 事前にセカンダリIP192.168.0.100を付けておく。
(2) グローバルIPのNATの設定で、セカンダリIP 192.168.0.100へNAT設定しておく(送信元NATのグローバルIPではなく、別で用意する)
VIPつける
ip addr add 192.168.0.100/24 dev eth0
firewalld 止める
systemctl status firewalld.service systemctl stop firewalld.service systemctl disable firewalld.service systemctl status firewalld.service
ipvsadmの設定
yum -y install ipvsadm ip_forwardを有効にする echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf [root@mukkun-lvs ~]# sysctl -p net.ipv4.conf.all.arp_notify = 1 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv4.ip_forward = 1 [root@mukkun-lvs ~]# touch /etc/sysconfig/ipvsadm [root@mukkun-lvs ~]# systemctl start ipvsadm [root@mukkun-lvs ~]# systemctl enable ipvsadm Created symlink from /etc/systemd/system/multi-user.target.wants/ipvsadm.service to /usr/lib/systemd/system/ipvsadm.service. [root@mukkun-lvs ~]# systemctl status ipvsadm ● ipvsadm.service - Initialise the Linux Virtual Server Loaded: loaded (/usr/lib/systemd/system/ipvsadm.service; enabled; vendor preset: disabled) Active: active (exited) since 木 2020-07-16 21:52:18 JST; 13s ago Main PID: 29307 (code=exited, status=0/SUCCESS)
負荷分散の設定
#テーブルクリア ipvsadm -C # 仮想サービスを登録 # [ipvsadm -A -t (サービス用IP:ポート) -s (分散方式)] ipvsadm -A -t 192.168.0.100:80 -s lc # バックエンドサーバーを登録 # [ipvsadm -a -t (サービス用IP:ポート) -r (実サーバのIP:ポート) -g] (g で gatewaying (routing)) ipvsadm -a -t 192.168.0.100:80 -r 192.168.0.62:80 -g ipvsadm -a -t 192.168.0.100:80 -r 192.168.0.243:80 -g # 設定確認 [root@mukkun-lvs ~]# ipvsadm -ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.0.100:80 lc -> 192.168.0.62:80 Route 1 0 0 -> 192.168.0.243:80 Route 1 0 0
BackEndServer:設定
まずhttpd入れておく
yum -y install httpd systemctl start httpd systemctl enable httpd systemctl status httpd # わかりやすいようにindex.htmlを作っておきます。 [root@mukkun-backend-1 ~]# cat /var/www/html/index.html <h1><font color="red">backend-1 192.168.0.62/24</font></h1> [root@mukkun-backend-2 ~]# cat /var/www/html/index.html <h1>backend-2 192.168.0.243/24</h1>
パケットを受け付ける準備をする
LVSサーバ側の設定が終わっていると、「グローバルIP → 192.168.0.100」への通信がそのままBackend01、Backend02へ転送されます。 そのままだと、自分宛てと気づけずにパケットを処理する事ができません。つまり、上位から流れてきたパケットは宛先IPが192.168.0.100宛で流れてきます。そのため、以下のどちらかの方法でパケットを処理できるようにします。
(1) iptables(firewalld)のPREROUTINGチェインにREDIRECTオプションを追加する (2) Backend01、Backend02にlvsサーバーと同じVIPを付けて、擬似的に通信を受けて返す
(1)のパターンの設定
firewalld使う場合
firewall-cmd --permanent --direct --add-rule ipv4 nat PREROUTING 100 -d 192.168.0.100 -j REDIRECT firewalld --reload
firewalldを使わない場合
firewalldサービス止める yum -y install iptables-services iptables -t nat -I PREROUTING -d 192.168.0.100 -j REDIRECT iptables -I INPUT -p ALL -s 192.168.0.0/24 -j ACCEPT
(2)のパターンの設定
firewalld 止める
systemctl status firewalld.service systemctl stop firewalld.service systemctl disable firewalld.service systemctl status firewalld.service
VIPつける(ループバックアドレスを設定)
ip addr add 192.168.0.100/24 dev eth0
ループバックアドレスを設定すると、arp関係で問題が出るので、 下記の設定を入れてあげる。
cat << EOF >> /etc/sysctl.conf net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 EOF sysctl -p
これでグローバルIPでブラウザから接続すると、パケットがBackend01、Backend02へ転送されて、それぞれのWebページが表示されます。
Centos6にOpenVZインストールしてsshログインするまで
Lpic304の勉強がてら試したのでメモ 第2段
これはCentos7の例。 https://thegeeksalive.com/how-to-setup-openvz-7-on-centos-7/
ただ、Centos7ではライブラリの依存関係が面倒だったので、Centos6で試す https://www.kwonline.org/memo2/2020/03/09/install-openvz-on-centos-6_5/ https://www.unixmen.com/install-and-configure-openvz-on-centos/
OpenVZインストール
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ yum install vzkernel 追記 [root@mukkun ~]# cat sysctl.conf # On Hardware Node we generally need # packet forwarding enabled and proxy arp disabled net.ipv4.ip_forward = 1 net.ipv6.conf.default.forwarding = 1 net.ipv6.conf.all.forwarding = 1 net.ipv4.conf.default.proxy_arp = 0 # Enables source route verification net.ipv4.conf.all.rp_filter = 1 # Enables the magic-sysrq key kernel.sysrq = 1 # We do not want all our interfaces to send redirects net.ipv4.conf.default.send_redirects = 1 net.ipv4.conf.all.send_redirects = 0 [root@mukkun ~]# cat /etc/sysconfig/selinux | grep disable # disabled - No SELinux policy is loaded. SELINUX=disabled yum install vzctl vzquota ploop grubでOpenVZのカーネルがデフォルトになっていることを確認してからreboot [root@mukkun ~]# cat /etc/grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/mapper/vg_mukkun-lv_root # initrd /initrd-[generic-]version.img #boot=/dev/md127 default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title OpenVZ (2.6.32-042stab145.3) ★ root (hd0,0) kernel /vmlinuz-2.6.32-042stab145.3 ro root=/dev/mapper/vg_mukkun-lv_root rd_MD_UUID=7f9c0939:7a3803d8:68d9f945:65819100 rd_LVM_LV=vg_mukkun/lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_mukkun/lv_swap rd_MD_UUID=f7305389:dd025f17:6fc81a4e:ba4602f8 SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-042stab145.3.img title CentOS (2.6.32-754.30.2.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-754.30.2.el6.x86_64 ro root=/dev/mapper/vg_mukkun-lv_root rd_MD_UUID=7f9c0939:7a3803d8:68d9f945:65819100 rd_LVM_LV=vg_mukkun/lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_mukkun/lv_swap rd_MD_UUID=f7305389:dd025f17:6fc81a4e:ba4602f8 SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-754.30.2.el6.x86_64.img
コンテナを作成してみる
cd /vz/template/cache/ テンプレートダウンロード wget http://download.openvz.org/template/precreated/centos-7-x86_64-minimal.tar.gz コンテナ作成 vzctl create 101 --ostemplate centos-7-x86_64-minimal
IP・ホスト名の設定
IPの設定
[root@mukkun cache]# vzctl set 100 --ipadd 10.0.20.50 --save CT configuration saved to /etc/vz/conf/100.conf
ホスト名変える
[root@mukkun cache]# vzctl set 100 --hostname con100 --save UB limits were set successfully
起動・コンソールログイン・SSHログイン
起動
[root@mukkun cache]# vzctl start 100 Starting container... Opening delta /vz/private/100/root.hdd/root.hdd Adding delta dev=/dev/ploop32913 img=/vz/private/100/root.hdd/root.hdd (rw) Mounting /dev/ploop32913p1 at /vz/root/100 fstype=ext4 data='balloon_ino=12,' Container is mounted Adding IP address(es): 10.101.20.50 Setting CPU units: 1000 Container start in progress...
入ってみる
[root@mukkun cache]# vzctl enter 100 entered into CT 100 [root@con100 /]# [root@con100 /]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@con100 /]# passwd Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully.
コンソールで入る
[root@mukkun cache]# vzctl console 100 Attached to CT 100 (ESC . to detach) Password: Login incorrect con100 login: root Password: Last login: Sun Jul 12 10:59:32 on console [root@con100 ~]#
Esc+.(ドット)で抜ける
sshしてみる
[root@mukkun cache]# ssh root@10.0.20.50 root@10.0.20.50's password: Last login: Sun Jul 12 11:00:02 2020 [root@con100 ~]#
サーバー側からコマンドを実行してみる
[root@mukkun cache]# vzctl exec 100 /sbin/ip -4 a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN inet 127.0.0.1/8 scope host lo 2: venet0: <BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN inet 127.0.0.1/32 scope host venet0 inet 10.101.20.50/32 brd 10.101.20.50 scope global venet0:0