Created
September 24, 2012 05:13
-
-
Save reoring/3774295 to your computer and use it in GitHub Desktop.
CentOS 仮想化ホスト構築マニュアル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CentOS 仮想化ホスト構築マニュアル | |
SELinux停止 | |
/etc/sysconfig/selinux | |
不要サービス停止 | |
service portmap stopservice messagebus stop | |
service smartd stop | |
service yum-updatesd stop | |
service bluetooth stop | |
service hidd stop | |
service haldaemon stop | |
service ip6tables stop | |
service kudzu stop | |
service mcstrans stop | |
service pcscd stop | |
service rpcgssd stop | |
service rpcidmapd stop | |
service cups stop | |
service gpm stop | |
service avahi-daemon stop | |
service mdmonitor stop | |
service irqbalance stop | |
service restorecond stop | |
service netfs stop | |
chkconfig portmap off | |
chkconfig messagebus off | |
chkconfig smartd off | |
chkconfig yum-updatesd off | |
chkconfig bluetooth off | |
chkconfig hidd off | |
chkconfig haldaemon off | |
chkconfig ip6tables off | |
chkconfig kudzu off | |
chkconfig mcstrans off | |
chkconfig pcscd off | |
chkconfig rpcgssd off | |
chkconfig rpcidmapd off | |
chkconfig cups off | |
chkconfig gpm off | |
chkconfig avahi-daemon off | |
chkconfig mdmonitor off | |
chkconfig irqbalance off | |
chkconfig netfs off | |
VLAN有効化 | |
/etc/sysconfig/networkに、VLAN=yesを追記 | |
KVM構成 | |
yum install kvm qemu kvm-qemu-img kvm-tools qspice-libs libvert python-virtinst bridge-utils | |
service libvirtd start && chkconfig libvirtd on | |
modprobe kvm | |
modprobe kvm_amd | |
modprobe ksm | |
DRBD構成 | |
yum install -y kmod-drbd83 | |
fdisk構成 | |
/dev/sda1 * 1 33 265041 83 Linux/dev/sda2 34 63774 511999582+ 8e Linux LVM | |
/dev/sda3 63775 127515 511999582+ 8e Linux LVM | |
/dev/sda4 127516 243201 929247795 5 Extended | |
/dev/sda5 127516 191256 511999551 8e Linux LVM | |
/dev/sda6 191257 243201 417248181 8e Linux LVM | |
/dev/sdb1 1 60789 488287611 8e Linux LVM | |
/dev/sdb2 60790 121578 488287642+ 8e Linux LVM | |
/dev/sdb3 121579 182367 488287642+ 8e Linux LVM | |
/dev/sdb4 182368 243201 488649105 8e Linux LVM | |
Physical Volume作成 | |
pvcreate /dev/sda3 /dev/sda5 /dev/sda6 | |
pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 | |
Volume Group作成 | |
vgcreate instance /dev/sda3 /dev/sdb1 | |
Logical Volume作成 | |
lvcreate --name ir0 --size 950G instance | |
/etc/lvm/lvm.conf | |
下記内容を追記 filter = [ "a/.*/" ] と置換 | |
filter = ["a|sd.*|", "a|drbd.*|", "r|.*|"] | |
/etc/drbd.conf に設定を記述 | |
global { usage-count yes; }common { | |
protocol C; | |
syncer { | |
rate 300M; | |
al-extents 257; | |
} | |
net { | |
sndbuf-size 1024k; | |
timeout 60; | |
connect-int 10; | |
ping-int 10; | |
ping-timeout 5; | |
max-buffers 8192; | |
max-epoch-size 8192; | |
} | |
} | |
resource ir0 { | |
device /dev/drbd0; | |
disk /dev/DrbdVG00/ir0; | |
meta-disk internal; | |
on storage01 { | |
address 192.168.0.101:7789; | |
} | |
on storage02 { | |
address 192.168.0.102:7789; | |
} | |
} | |
---------------- | |
ここからは双方のノードで実行 | |
# 初期化 | |
drbdadm create-md ir0 | |
service drbd start | |
or | |
drbdadm attach ir0 | |
drbdadm syncer ir0 | |
drbdadm connect ir0 | |
# drbdadm down ir0 && drbdadm ir0 up でも同様の意味 | |
cat /proc/drbd として、Secondary/Secondary ds: Inconsistent/Inconsitent となっているか確認する。 | |
------------------ | |
同期ソースで実行 | |
drbdadm -- --overwrite-data-of-peer primary ir0 | |
cat /proc/drbd | |
version: 8.2.6 (api:88/proto:86-88)GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17 | |
0: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C r--- | |
ns:3251844 nr:0 dw:0 dr:3270304 al:0 bm:197 lo:448 pe:666 ua:1024 ap:0 oos:992886204 | |
[>....................] sync'ed: 0.4% (969615/972770)M | |
finish: 2:09:50 speed: 127,428 (115,376) K/sec | |
同期中ステータスになれば正常 | |
------------------- | |
プライマリノードで実行 | |
pvcreate /dev/drbd0 | |
pvs | grep drbd0 | |
/dev/drbd0 lvm2 -- 949.97G 949.97G | |
vgcreate InstanceVG0 /dev/drbd0 | |
Volume group "InstanceVG0" successfully created | |
lvcreate --name InstanceLV01 --size 128G InstanceVG0 Logical volume "InstanceLV01" created | |
vgchange -a y InstanceVG0 | |
1 logical volume(s) in volume group "InstanceVG0" now active | |
// drbdadm secondary r0 | |
-----対向ノードでマウントする時に実行 | |
drbdadm primary r0 | |
vgchange -a y replicated | |
iSCSI構成 | |
yum install -y scsi-target-utils iscsi-initiator-utils | |
ターゲット | |
iSCSIターゲットは、ドライブをイニシエータに提供する。 | |
iptables -A INPUT -p tcp -m tcp --dport 3260 -j ACCEPT | |
service iptables save | |
service tgtd start | |
service tgtd start | |
二回起動しないと正常に立ち上がらない | |
tgt-setup-lun -d /dev/InstanceVG0/InstanceLV01 -n iscsi-vol01 192.168.0.0/24 | |
tgt-setup-lunコマンドで設定した内容は、tgt-admin --dump とすると取得できるので、それを、/etc/tgt/targets.confに設定する。 | |
tgt-admin -s 現状のステータスを取得する | |
/etc/tgt/targets.confに記述する | |
現状の設定をダンプして、設定とする | |
tgt-admin --dump > /etc/tgt/targets.conf | |
手動で追記する場合は下記の様にする | |
<target iqn.2001-04.com.iscsifs-iscsi-vol1> | |
backing-store /dev/InstanceVG0/InstanceLV01 | |
initiator-address 192.168.0.0/24 | |
</target> | |
イニシエータ | |
service iscsi start | |
iscsiadm -m discovery -t sendtargets -p 192.168.0.10 | |
service iscsi restart | |
dmesg Attached | |
sd 6:0:0:1: Attached scsi disk sdc | |
iSCSIドライブの初期化 | |
fdisk /dev/sdc | |
n | |
p | |
1 | |
t | |
8e | |
Command (m for help): p | |
Disk /dev/sdc: 137.4 GB, 137438953472 bytes | |
255 heads, 63 sectors/track, 16709 cylinders | |
Units = cylinders of 16065 * 512 = 8225280 bytes | |
Device Boot Start End Blocks Id System | |
/dev/sdc1 1 16709 134215011 8e Linux LVM | |
w | |
iSCSI接続したドライブにインスタンス用のLVM領域を作成 (仮想化インスタンスに必要) | |
pvcreate /dev/sdc1 | |
vgcreate ${instance_name}VG /dev/sdc1 | |
lvcreate --name ${instance_name}LV --size {n}G ${instance_name}VG | |
lvs | |
LV VG Attr LSize Origin Snap% Move Log Copy% Convert ${instance_name}LV ${instance_name}VG -wi-a- 125.00G | |
mke2fs -j /dev/${instance_name}VG/${instance_name}VG | |
tune2fs -i0 -c0 /dev/${instance_name}VG/${instance_name}VG | |
iSCSI接続したドライブにインスタンス用のボリュームプールを作成する | |
pvcreate /dev/sdc | |
vgcreate ServiceVG00 /dev/sdc | |
libvirtにプール領域として追加 | |
virsh pool-create-as ServiceVG00 logical --target=/dev/ServiceVG00 | |
Ethernet Bridgeの構成 | |
/etc/sysconfig/network-scripts/ifcfg/ifcfg-br0x0 | |
DEVICE=br0x0 | |
ONBOOT=yes | |
IPV6INIT=no | |
IPADDR=192.168.0.1 | |
NETMASK=255.255.255.0 | |
TYPE=Bridge | |
/etc/sysconfig/network-scripts/ifcfg/ifcfg-eth0 | |
DEVICE=eth0 | |
BOOTPROTO=none | |
ONBOOT=yes | |
BRIDGE=br0x0 # どのブリッジに接続するか | |
ホストサーバネットワーク設定 | |
sysctl -w net.ipv4.ip_forward=1 | |
iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT | |
service iptables save | |
service iptables restart | |
KVMインスタンスのインストール | |
virt-install \ | |
-n ${instance_name} \ | |
--connect qemu:///system -r 1024 --vcpus=2 \ | |
--disk path=${disk_path},bus=virtio \ | |
--os-type linux --accelerate \ | |
--network network:default \ | |
--location='http://ftp.riken.jp/Linux/centos/5.5/os/x86_64' \ | |
--extra-args='console=tty0 console=ttyS0,115200n8' | |
例 | |
virt-install \ | |
-n ${name} \ | |
--connect qemu:///system -r 1024 --vcpus=2 \ | |
--disk path=/dev/mapper/DatabaseVG-DatabaseLV,bus=virtio \ | |
--os-type linux --accelerate \ | |
--network network:default \ | |
--location='http://ftp.riken.jp/Linux/centos/5.5/os/x86_64' \ | |
--extra-args='console=tty0 console=ttyS0,115200n8' | |
ブリッジを使用する例 | |
virt-install \ | |
-n ${name} \ | |
--connect qemu:///system -r 1024 --vcpus=2 \ | |
--disk path=/dev/mapper/DatabaseVG-DatabaseLV,bus=virtio \ | |
--os-type linux \ | |
--accelerate \ | |
--network bridge:br0x0 \ | |
--location='http://ftp.riken.jp/Linux/centos/5.5/os/x86_64' \ | |
--extra-args='console=tty0 console=ttyS0,115200n8' | |
Pool定義 | |
virsh pool-create-as ServicePoolVG0 logical --target=/dev/ServicePoolVG0 | |
Poolのディスクを指定 | |
virt-install \ -n ${name} \ | |
--connect qemu:///system -r 512 --vcpus=2 \ | |
--disk pool=ServiceVG00,bus=virtio,size=230,cache=writethrough \ | |
--os-type linux \ | |
--accelerate \ | |
--network bridge:br0x0 \ | |
--location='http://ftp.riken.jp/Linux/centos/5.5/os/x86_64' \ | |
--extra-args='console=tty0 console=ttyS0,115200n8' | |
Keepalived構成 | |
keepalivedでストレージサービスを冗長化する | |
インストール | |
yum install -y kernel-devel openssl-devel make gcc ipvsadm | |
wget http://keepalived.org/software/keepalived-1.1.20.tar.gz | |
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.8.tar.gz | |
tar xvzf linux-*.tar.gz | |
cp -Rp linux/net/core/* /usr/src/kernel/net/core/ | |
tar xvzf keepalived-x.tar.gz | |
cd keepalived | |
./configure --with-kernel-dir=/usr/src/kernels/version | |
make | |
make install | |
ln -s /usr/local/sbin/keepalived /usr/sbin/keepalived | |
cp -Rp keepalived/etc/init.d/keepalived.rh.init /etc/init.d/keepalived | |
chkconfig --add keepalived | |
chkconfig keepalived on | |
service keepalived start | |
/etc/keepalived/keepalived.conf | |
global_defs { notification_email { | |
acassen | |
} | |
notification_email_from ${from_address} | |
smtp_server ${smtp_server} | |
smtp_connect_timeout 30 | |
router_id LVS_DEVEL | |
} | |
vrrp_instance iSCSI_One { | |
state MASTER | |
interface eth0 | |
garp_master_delay 10 | |
smtp_alert | |
virtual_router_id 5 | |
priority 110 | |
advert_int 1 | |
authentication { | |
auth_type PASS | |
auth_pass 1111 | |
} | |
virtual_ipaddress { | |
192.168.0.10 | |
} | |
notify_master /etc/keepalived/master.sh | |
notify_backup /etc/keepalived/backup.sh | |
notify_fault /etc/keepalived/fault.sh | |
} | |
/etc/sysconfig/iptables | |
下記行を追加 | |
RH-Firewall-1-INPUT -m state --state NEW -p vrrp -j ACCEPT | |
Appendix | |
LVM領域をコピー | |
dd if=/dev/${from}/${from}LV.img of=/dev/${to}VG.img/${to}LV.img bs=8192 | |
KVMゲストライブマイグレーション | |
virsh migrate --live ${instance_domain_name} qemu+ssh://{$host}/system | |
(マイグレーション先は、DNS名から解決する必要がある。hosts記述でも可) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment