-
Notifications
You must be signed in to change notification settings - Fork 0
/
adm
executable file
·221 lines (219 loc) · 5.46 KB
/
adm
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
osd_num=3
if [ m$1 = m"run" ]; then
for ((j=0; j<$osd_num; j++))
do
echo "mmm" > /var/log/ceph/ceph-osd.$j.log
done
cmd=""
m=0
for var in $*
do
if [ $m != 0 ]; then
cmd="$cmd$var "
fi
m=$m+1
done
$cmd
exit 0
fi
pkg()
{
if [ "m`ceph --version | awk '{print $5}'`" = "mluminous" ]; then
msg="/usr/local/lib/ceph"
else
msg="/usr/local/share/ceph"
fi
if [ ! -d "/usr/local/lib/ceph/erasure-code" ]; then
mkdir -p /usr/local/lib/ceph/erasure-code
fi
if [ ! -d "/usr/local/lib/rados-classes" ]; then
mkdir -p /usr/local/lib/rados-classes/
fi
if [ ! -d $msg ]; then
mkdir -p $msg
fi
rm -fr /usr/local/lib/ceph/erasure-code/*
rm -fr /usr/local/lib/rados-classes/*
rm -fr "$msg/mgr"
ln -s /home/me/codes/ceph/src/pybind/mgr "$msg/mgr"
ln -s /home/me/codes/ceph/build/lib/libcls_rbd.so /usr/local/lib/rados-classes/libcls_rbd.so
ln -s /home/me/codes/ceph/build/lib/libcls_lock.so /usr/local/lib/rados-classes/libcls_lock.so
ln -s /home/me/codes/ceph/build/lib/libec_jerasure.so /usr/local/lib/ceph/erasure-code/libec_jerasure.so
ln -s /home/me/codes/ceph/build/lib/libec_lrc.so /usr/local/lib/ceph/erasure-code/libec_lrc.so
ln -s /home/me/codes/ceph/build/lib/libec_isa.so /usr/local/lib/ceph/erasure-code/libec_isa.so
}
remove_osd()
{
tem=`ps aux | grep "ceph-osd -i $1" | grep -v "grep" | awk '{print $2}'`
if [ "m$tem" = "m" ]; then
echo not exist
exit 0
fi
while [ "m$tem" != "m" ]
do
kill -9 $tem
sleep 3
tem=`ps aux | grep "ceph-osd -i $1" | grep -v "grep" | awk '{print $2}'`
done
ceph osd crush remove osd.$1
ceph osd rm $1
rm -fr /var/lib/ceph/osd/ceph-$1
}
create_osd()
{
mkdir -p /var/lib/ceph/osd/ceph-$1
ceph-osd -i $1 --mkfs
ceph osd create $1
ceph osd crush add osd.$1 1 root=default host=localhost
ceph-osd -i $1
}
create_cluster()
{
if [ ! -d "/etc/ceph" ]; then
mkdir -p /etc/ceph
fi
rm -fr /etc/ceph/*
cd /etc/ceph
# address=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d '/'`
address="127.0.0.1"
m=`uuidgen`
monmaptool --create --add 0 $address:6789 --fsid $m monmap
f="[global]\n
\tfsid = $m\n
\tmon_host = $address\n
\tauth_cluster_required = none\n
\tauth_service_required = none\n
\tauth_client_required = none\n
[osd]\n
\tosd journal size = 512\n
[mon.0]\n
\tmon addr = $address:6789"
echo -e $f > ceph.conf
rm -fr /var/lib/ceph/*
if [ ! -d "/var/lib/ceph" ]; then
mkdir -p /var/lib/ceph
fi
pkg
mkdir -p /var/lib/ceph/mon/ceph-0
ceph-authtool --create-keyring ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'
ceph-authtool --create-keyring ceph.client.admin.keyring --gen-key -n client.admin --set-uid=0 --cap mon 'allow *' --cap osd 'allow *'
ceph-authtool ceph.mon.keyring --import-keyring ceph.client.admin.keyring
ceph-mon --mkfs -i 0 --monmap monmap --keyring ceph.mon.keyring
ceph-mon -i 0
for ((j=0; j<$osd_num; j++))
do
mkdir -p /var/lib/ceph/osd/ceph-$j
ceph-osd -i $j --mkfs
ceph osd create $j
ceph osd crush add osd.$j 1 root=default host=localhost
ceph-osd -i $j
done
ceph-mgr -i 0
}
if [ m$1 = m"remove" ]; then
if [ ! $# -gt 1 ]; then
exit 0
fi
if [ m$2 = m"osd" ]; then
remove_osd $3
fi
fi
if [ m$1 = m"clean" ]; then
if [ ! $# -gt 1 ]; then
exit 0
fi
ceph osd crush remove osd.$2
ceph osd rm $2
rm -fr /var/lib/ceph/osd/ceph-$2/*
ceph-osd -i $2 --mkfs
ceph osd create $2
ceph osd crush add osd.$2 1 root=default host=localhost
ceph-osd -i $2
fi
if [ m$1 = m"create" ]; then
if [ $# -eq 1 ]; then
create_cluster
exit 0
fi
if [ m$2 = m"osd" ]; then
create_osd $3
fi
fi
if [ m$1 = m"install" ]; then
pkg
fi
if [ m$1 = m"log" ]; then
if [ $# -gt 1 ]; then
file="/var/log/ceph/ceph-osd.$2.log"
else
file="/var/log/ceph/ceph-osd.0.log"
fi
line=`grep -n "mmm" $file | tail -1 | cut -d ":" -f 1`
awk '/123/{gsub("123", "");gsub("/home/me/codes/ceph/src/","");$3="";$4="";if(FNR>'$line'){print}}' $file
exit 0
fi
if [ m$1 = m"make" ]; then
cd /home/me/codes/ceph/build
make -j6 >/dev/null
if [ $? -ne 0 ]; then
echo error
exit 0
fi
if [ $# -gt 1 ]; then
if [ m$2 = m"pkg" ]; then
pkg
fi
fi
exit 0
fi
if [ m$1 = m"show" ]; then
if [ $# -gt 1 ]; then
ps aux | grep "ceph-osd -i $2" | grep -v "grep" | awk '{print $2}'
fi
fi
if [ m$1 = m"restart" ]; then
echo "wait osds exit"
if [ $# -eq 1 ]; then
pkill ceph-osd
sleep 3
tem=`pgrep ceph-osd`
while [ "m$tem" != "m" ]
do
pkill ceph-osd
sleep 3
tem=`pgrep ceph-osd`
done
else
tem=`ps aux | grep "ceph-osd -i $2" | grep -v "grep" | awk '{print $2}'`
kill $tem
sleep 3
while [ -d /proc/$tem ]
do
kill $tem
sleep 3
done
fi
echo "restart the osds"
if [ $# -eq 1 ]; then
for ((j=0; j<$osd_num; j++))
do
ceph-osd -i $j >/dev/null 2>&1
done
else
ceph-osd -i $2 >/dev/null 2>&1
fi
sleep 3
tem=`ceph -s | tail -n 8 | sed -n '1p' | awk '{print $4}'`
if [ $tem = 0 ]; then
echo "osds none start"
exit 0
fi
echo "wait cluster status"
tem=`ceph -s | tail -n 2 | sed -n '1p' | awk '{print $3}'`
while [ "m$tem" != "mactive+clean" ]
do
tem=`ceph -s | tail -n 2 | sed -n '1p' | awk '{print $3}'`
sleep 3
done
fi