-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_glusterFS.sh
More file actions
293 lines (236 loc) · 9.35 KB
/
script_glusterFS.sh
File metadata and controls
293 lines (236 loc) · 9.35 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
#########################################################################
# AUTOR : AMAURI HIDEKI #
# DATA CRIAÇÃO : 11/05/2017 #
# DATA ALTERAÇÃO : 15/05/2017 #
# VERSÃO : 17/05/2017 V1.0
# SERVIÇO : CLUSTER AMBIENTE WEB #
# DISTRIB : CENTOS 7 #
# #
# FONTE #
# http://gluster.readthedocs.io/en/latest/Quick-Start-Guide/Quickstart/ #
# #
#########################################################################
### PRÉ REQUISITOS #####################################################
# #
# - TER DISCO DE DADOS EXCLUSIVO PARA O CLUSTER #
# #
# Deve ser criado arquivo conforme exemplo abaixo sem as cerquilhas #
# #
# configgluster #
# NOS:INTERFACE:SENHA:IP_NÓ1:IP_NÓ2 #
# VOL:/var/www:/dev/vdb:/dev/vdb #
# #
#########################################################################
#############################################################################
## VARIÁVEIS DEFAULT #
#############################################################################
# DECLARAÇÃO DE VARIÁVEIS GLOBAIS PARA ARQIOVO CONFIG
# LISTA IPS DO CLUSTER
NOS_CLUSTER=`grep '^NOS' configgluster | sed 's/:/\n/g' | sed '1d;2d;3d'`
# CONTAS NÚMEROS DE SERVIDORES DO CLUSTER
NOS_COUNT=`grep '^NOS' configgluster | sed 's/:/\n/g' | sed '1d;2d;3d' | wc -l`
# SENHA DO CLUSTER
SENHASSH=`grep '^NOS' configgluster | cut -d : -f3`
# LISTA DE VOLUMES
VOL=`grep '^VOL' configgluster | sed 's/:/\n/g' | sed '1d;2d'`
# DIRETÓRIO PADRÃO PARA O CLUSTER
DATADIR=`grep '^VOL' configgluster | cut -d : -f2`
# CHECK 0 FSTAB SEM INFORMAÇÃO INPUTADA PELO SCRIPT 1 INFORMAÇÃO JÁINPUTADA
USO_FSTAB=`grep -i brick1 /etc/fstab > /dev/null; echo $?`
USO_FSTAB_GV=`grep -i :gv0 /etc/fstab > /dev/null; echo $?`
perfil_padrao_local(){
echo "# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
HISTSIZE=1000
HISTFILESIZE=1000
export HISTTIMEFORMAT='%F %T '
export HISTCONTROL=ignoredups
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi" > /root/.bashrc
source /root/.bashrc
echo '#!/bin/bash
# User specific aliases and functions
Normal="\[\\033[0m\]"
Vermelho="\[\\033[1;31m\]"
Verde="\[\\033[1;32m\]"
Amarelo="\[\\033[1;33m\]"
Azul="\[\\033[1;34m\]"
Roxo="\[\\033[1;35m\]"
Ciano="\[\\033[1;36m\]"
Branco="\[\\033[1;37m\]"
PS1="$Normal$Azul[$Branco(\t) $Verde\u$Vermelho@$Amarelo\h$Verde $Ciano\w$Azul]$Branco\\$ $Normal"' > /etc/profile.d/mandic_bashrc.sh
source /etc/profile.d/mandic_bashrc.sh
echo '# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# powersave disable
#setterm -powersave off -blank 0
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH' > /root/.bash_profile
source /root/.bash_profile
}
gera_chave_local(){
# INSTALANDO PACOTES
# SSHPASS
VALIDA_PACOTE1=`rpm -qa | grep -i sshpass > /dev/null; echo $?`
if [ $VALIDA_PACOTE1 -ne 1 ] ;then
echo "NÃO FAZER" > /dev/null
else
rpm -ivh ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/KGronlund/CentOS_7/x86_64/sshpass-1.05-7.1.x86_64.rpm
fi
# OPENSSH
VALIDA_PACOTE2=`rpm -qa | grep -i openssh > /dev/null; echo $?`
if [ $VALIDA_PACOTE1 -ne 1 ] ;then
echo "NÃO FAZER" > /dev/null
else
yum install openssh-clients.x86_64 wget -y
fi
# GERANDO CHAVE
if [ -e /root/.ssh/id_rsa ];then
echo "Já tem chave RSA" > /dev/null
else
ssh-keygen -t rsa -f /root/.ssh/id_rsa -P ""
fi
}
troca_chave_cluster(){
echo ""
echo "###############################################"
echo "# Configuração dos NODES dentro do CLUSTER #"
echo "###############################################"
echo ""
# TROCA DE CHAVES BASEADO NA LINHA COM CAMPO "NOS" DO ARQUIVO configgluster
echo '#!/bin/bash' > config_rel_conf.sh
echo "$NOS_CLUSTER" | while read TROCACHAVE; do
echo 'sshpass -p' "$SENHASSH" 'ssh-copy-id -i /root/.ssh/id_rsa.pub' "$TROCACHAVE" '&& sleep 1' >> config_rel_conf.sh
done
echo 'StrictHostKeyChecking no
#serKnownHostsFile=/dev/null'> ~/.ssh/config
sh +x config_rel_conf.sh && sleep 1
rm -rf config_rel_conf.sh
# COPIA CAVE PARA O CLUSTER
scp /root/.ssh/id_rsa.pub $NO_CLUSTER:/root/.ssh/id_rsa.pub
# DESABILITA SELINUX CLUSTER
ssh $NO_CLUSTER "sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config" && \
ssh $NO_CLUSTER "sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/sysconfig/selinux" && \
ssh $NO_CLUSTER "setenforce 0"
# COPIA ARQUIVOS DE PERFIL PARA O CLUSTER
scp /root/.bashrc $NO_CLUSTER:/root/.bashrc && \
ssh $NO_CLUSTER "source /root/.bashrc" && \
scp /etc/profile.d/mandic_bashrc.sh $NO_CLUSTER:/etc/profile.d/mandic_bashrc.sh && \
ssh $NO_CLUSTER "source /etc/profile.d/mandic_bashrc.sh" && \
scp /root/.bash_profile $NO_CLUSTER:/root/.bash_profile && \
ssh $NO_CLUSTER "source /root/.bash_profile" && \
ssh $NO_CLUSTER "rm -rf /root/ajusta_fqdn.sh"
}
fqdn_cluster(){
# FQDN
echo 'host_name=`hostname | grep -i .mandic.net.br > /dev/null ; echo $?`
if [ $host_name -eq 0 ]; then
echo "Hostname já no padrão FQDN"
else
hostnamectl set-hostname $(echo -e $(hostname | cut -d "-" -f1,7).mandic.net.br)
systemctl restart systemd-hostnamed.service
fi' > ajusta_fqdn.sh
# FQDN SETADO NA MÁQUIUNA
scp ajusta_fqdn.sh $NO_CLUSTER:/root/ajusta_fqdn.sh && \
ssh $NO_CLUSTER "sh +x ajusta_fqdn.sh"
# INSERE FQDN NOs HOSTS
ssh $NO_CLUSTER hostname | while read NAMEHOST; do echo "$NO_CLUSTER $NAMEHOST" >> /etc/hosts; done
# COPIA ARQUIVO HOSTS PARA TODOS OS NÓS
for i in `echo "$NOS_CLUSTER"`; do
scp /etc/hosts $i:/etc/hosts
done
}
fdisk_cluster(){
# CRIANDO PARTIÇÃO
ssh $NO_CLUSTER "echo -e 'n\np\n\n\n\n\nw' | fdisk $(echo $VOL | cut -d ' ' -f$CONT)" && \
# FORMATANDO PARTIÇÃO
ssh $NO_CLUSTER "mkfs.xfs -fi size=512 $(echo $VOL | cut -d ' ' -f$CONT)1" && \
# CRIANDO DIRETÓRIO
ssh $NO_CLUSTER "mkdir -p /data/brick1"
# IF CHECA SE O FSTAB JÀ POSSUI A INFORMAÇÃO PARA NÃO DUPLICAR
if [ $USO_FSTAB -eq "1" ] ;then
# ADICIONA MONTAGEM DA PARTIÇÃO NO DIRETÓRIO CRIADO DENTRO DO FSTAB
ssh $NO_CLUSTER "echo "$(echo $VOL | cut -d ' ' -f$CONT)1 /data/brick1 xfs defaults 1 2" >> /etc/fstab"
fi
# MONTANDO PARTIÇÃO NO DIRETÓRIO CRIADO
ssh $NO_CLUSTER "mount -a"
}
install_gluster_cluster(){
# INSTALAR O SERVIÇO GLUSTERFS
ssh $NO_CLUSTER "yum -y install centos-release-gluster37.noarch " && \
ssh $NO_CLUSTER "yum -y install glusterfs gluster-cli glusterfs-libs glusterfs-server"
# TEMPO ESTIMADO DE ATÉ 10 MIN PARA A INSTALAÇÃO
# 15:09:10
# 15:18:23
# INICIAR DAEMON DE GERENCIAMENTO DO GLUSTERFS
ssh $NO_CLUSTER "service glusterd start"
}
configura_gluster_cluster_adicina_nos(){
# ADICINA TODOS OS SERVIDORES COM EXCEÇÃO DELE MESMO DENTRO DA CONFIGURAÇÃO DO GLUSTER DE CADA NO
ssh $NO_CLUSTER "gluster peer probe $(for i in `echo "$NOS_CLUSTER"`; do ssh $i hostname;done | grep -v $NO_CLUSTER_NAME)"
}
configura_gluster_cluster_cria_volume_nos(){
#############################################################################
## Executar só no servidor MASTER #
#############################################################################
#mkdir -p /data/brick1/gv0
NUM_NOS=`echo $NOS_CLUSTER | wc -l`
gluster volume create gv0 replica $NUM_NOS $(for i in `echo "$NOS_CLUSTER"`; do ssh $i hostname | while read GV_NO; do echo $GV_NO:/data/brick1/gv0 ;done ;done)
gluster volume start gv0
}
client_glusterfs(){
# CRIAR DIRETÓRIO ONDE SERÁ MONTADO O VOLUME
ssh $NO_CLUSTER "mkdir -p $DATADIR"
# IF CHECA SE O FSTAB JÀ POSSUI A INFORMAÇÃO PARA NÃO DUPLICAR
if [ $USO_FSTAB_GV -eq "1" ] ;then
# ADICIONA MONTAGEM DA PARTIÇÃO NO DIRETÓRIO CRIADO DENTRO DO FSTAB
ssh $NO_CLUSTER "echo "$NO_CLUSTER_NAME:gv0 $DATADIR glusterfs defaults 0 0" >> /etc/fstab"
fi
# MONTANDO PARTIÇÃO NO DIRETÓRIO CRIADO
ssh $NO_CLUSTER "mount -a"
}
engrenagem(){
engine_1(){
COUNT=0
CONT=$(( $COUNT + 1 ))
while [[ $NOS_COUNT -ge $CONT ]] ; do
# VARIAVEIS CONDICINAIS ATRELADO AO CONTADOR
NO_CLUSTER=`echo $NOS_CLUSTER | cut -d ' ' -f"$CONT"`
NO_CLUSTER_NAME=`ssh $NO_CLUSTER hostname`
perfil_padrao_local
gera_chave_local
troca_chave_cluster
fqdn_cluster
fdisk_cluster
install_gluster_cluster
CONT=$(( $CONT + 1 ))
done
}
engine_2(){
# DEPENDE DE QUE TODAS AS EXECUÇÕES DA engine_1
COUNT=0
CONT=$(( $COUNT + 1 ))
while [[ $NOS_COUNT -ge $CONT ]] ; do
# VARIAVEIS CONDICINAIS ATRELADO AO CONTADOR
NO_CLUSTER=`echo $NOS_CLUSTER | cut -d ' ' -f"$CONT"`
NO_CLUSTER_NAME=`ssh $NO_CLUSTER hostname`
configura_gluster_cluster_adicina_nos
client_glusterfs
CONT=$(( $CONT + 1 ))
done
}
engine_1
engine_2
configura_gluster_cluster_cria_volume_nos
}
engrenagem