raid-crypto-lvm/install.sh

raw link view readme
1 fdisk /dev/sdb <
2 n
3 p
4 1
5
6
7 t
8 fd
9 w
10 EOF
11
12 sfdisk -d /dev/sdb > /var/partition-table
13 sfdisk /dev/sdc < /var/partition-table
14 sfdisk /dev/sdd < /var/partition-table
15 sfdisk /dev/sde < /var/partition-table
16
17 partprobe
18
19 yum install mdadm cryptsetup -y
20
21 mdadm --create /dev/md0 --level=10 --chunk=4 --raid-devices=4 /dev/sd[b-e]1
22
23 mdadm --detail --scan --verbose >> /etc/mdadm.conf
24
25 modprobe dm-crypt
26
27 echo -n "diskpassword" > /root/keyfile
28
29 cryptsetup luksFormat /dev/md0 -q --key-file /root/keyfile
30
31 cryptsetup luksOpen /dev/md0 encdisk --key-file /root/keyfile
32
33 pvcreate /dev/mapper/encdisk
34
35 vgcreate vg_core /dev/mapper/encdisk
36
37 lvcreate --size 20G vg_core -n lv_mongologs
38 lvcreate -l +100%FREE vg_core -n lv_mongo
39
40 mkfs.xfs /dev/vg_core/lv_mongologs
41 mkfs.xfs /dev/vg_core/lv_mongo
42
43 mkdir /var/log/mongodb
44 mkdir /var/lib/mongo
45
46 cat > /etc/crypttab <<\EOF
47 encdisk /dev/md0 /root/keyfile
48 echo
49 EOF
50
51 echo "$(xfs_admin -u /dev/vg_core/lv_mongologs | sed "s/ //g") /var/log/mongodb xfs defaults,noatime 0 0" >> /etc/fstab
52 echo "$(xfs_admin -u /dev/vg_core/lv_mongo | sed "s/ //g") /var/lib/mongo xfs defaults,noatime 0 0" >> /etc/fstab
53
54 mount -a
55