-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbcache-install.sh
129 lines (109 loc) · 2.87 KB
/
bcache-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# This script installs bcache on an already running elasticsearch node.
# All data on the node will be destroyed!
# part 1
set -e
# change cloud-init config to not mount ephemeral0 to /mnt.
cat >> /etc/cloud/cloud.cfg <<'EOT'
mounts:
- [ ephemeral0 ]
- [ swap, none, swap, sw, '0', '0' ]
- [ /dev/bcache0, /datadisks/disk1, ext4, "nofail,noatime,nodiratime", "0", "0"]
EOT
# undo elasticsearch specific mount
cp /etc/fstab /etc/fstab.old
cat /etc/fstab.old | sed '/datadisks\/disk1/d' > /etc/fstab
# stop elasticsearch
monit stop elasticsearch
sleep 5
modprobe bcache
# unmount previously mounted disks
umount /mnt
umount /datadisks/disk1
# set up data disk
wipefs -a /dev/sdc1
make-bcache -B /dev/sdc1
#enable bcache module
echo /dev/sdc1 > /sys/fs/bcache/register
echo 1 > /sys/block/sdc/sdc1/bcache/running
sleep 1
# format bcache backing device
mkfs.ext4 /dev/bcache0
mount /dev/bcache0 /datadisks/disk1
# recreate elasticsearch directories
mkdir /datadisks/disk1/elasticsearch
chown elasticsearch:elasticsearch /datadisks/disk1/elasticsearch
# set up cache init script
cat > /etc/init.d/bcache <<'EOT'
#!/bin/bash
### BEGIN INIT INFO
# Provides: bcache
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: bcache
# Description: Enables bcache
### END INIT INFO#
# adjusted from http://blog.rralcala.com/2014/08/using-bcache-in-ec2.html
#
export basedisk=sdc/
export base=sdc1
export cache=sdb1
rc=0
start() {
if [ ! -e /sys/block/bcache0/bcache/cache ]
then
umount /dev/$cache
/sbin/wipefs -a -t ext2,ext3,ext4 /dev/$cache
/usr/sbin/make-bcache -C /dev/$cache
echo /dev/$cache > /sys/fs/bcache/register
sleep 1
name=`basename /sys/fs/bcache/*-*-*`
echo $name > /sys/block/bcache0/bcache/attach
# Some performance tuning, we assume NAS is always
# going to be slower than local SSDs
echo 1 > /sys/block/$basedisk$base/bcache/running
sleep 1
echo 0 > /sys/block/bcache0/bcache/sequential_cutoff
sleep 1
echo 0 > /sys/block/bcache0/bcache/cache/congested_read_threshold_us
echo 0 > /sys/block/bcache0/bcache/cache/congested_write_threshold_us
echo writethrough > /sys/block/bcache0/bcache/cache_mode
fi
touch /var/lock/subsys/bcache
return 0
}
stop() {
echo 1 > /sys/block/bcache0/bcache/cache/unregister
/bin/sleep 5
rm -f /var/lock/subsys/bcache
return 0
}
status() {
cat /sys/block/bcache0/bcache/state
return 0
}
case "$1" in
start)
start
rc=$?
;;
stop)
stop
rc=$
;;
status)
status
rc=$?
;;
esac
exit $rc
EOT
chmod +x /etc/init.d/bcache
update-rc.d bcache defaults
/etc/init.d/bcache start
monit restart elasticsearch
# print info
lsblk -o NAME,MAJ:MIN,RM,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUID,PARTUUID
/etc/init.d/bcache status