-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_ntp_cluster.sh
executable file
·66 lines (58 loc) · 2.16 KB
/
install_ntp_cluster.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
#!/bin/bash
log_file='./cluster_ntp_installer.log'
#get master
get_master_node(){
master_node=$(kubectl get node | grep master | sed -n '1p' | awk '{print $1}')
master_node_ip=$(kubectl get node ${master_node} -o wide | awk '{print $6}' | sed '1d')
sed "s/NTP_MASTER_IP/${master_node_ip}/g" ntp_client.conf.template > ntp_client.conf
for i in $(ls ntp_check/*.template);do
script=$(echo ${i} | sed 's/.template//g')
echo "change master ip for check scripts ${script}"
sed "s/NTP_MASTER_IP/${master_node_ip}/g" ${i} > ${script}
done
}
#get all nodes
get_all_nodes(){
node_list=$(kubectl get node -o wide | awk '{print $6}' | sed '1d')
echo ${node_list} | sed 's/ /\n/g' > clusterhosts
}
#install ntp
install_ntp_each_node(){
#master
echo 'master node installing...'
scp install_ntp_node.sh ${master_node_ip}:/tmp/install_ntp_node.sh
ssh ${master_node_ip} 'bash -c /tmp/install_ntp_node.sh'
scp -r ntp_check/ ${master_node_ip}:/opt/
scp ntp_master.conf.template ${master_node_ip}:/etc/ntp.conf
ssh ${master_node_ip} 'bash -c /tmp/install_ntp_node.sh'
#client
echo 'client nodes installing...'
for node in $(cat ./clusterhosts | grep -v ${master_node_ip});do
echo ${node}
scp install_ntp_node.sh ${node}:/tmp/install_ntp_node.sh
ssh ${node} 'bash -c /tmp/install_ntp_node.sh'
scp ntp_client.conf ${node}:/etc/ntp.conf
ssh ${node} 'bash -c /tmp/install_ntp_node.sh'
ssh ${node} 'ntpq -p'
ssh ${node} 'mkdir -p /opt/ntp_check'
scp ntp_check/resynctime.sh ${node}:/opt/ntp_check/resynctime.sh
done
}
init_check_scripts(){
cp uninstall_ntp_cluster.sh ntp_check/uninstall_ntp_cluster.sh
chmod +x ntp_check/*.sh
cp clusterhosts ntp_check/clusterhosts
cp -r ntp_check /opt/ntp_check
}
crontab_check(){
# restart all ntp service in 00:00 every day
(crontab -l | grep -v ntp_check; echo "0 0 */1 * * /opt/ntp_check/restartallsync.sh >> /opt/ntp_check/sync.log 2>&1") | crontab -
}
main(){
get_master_node
get_all_nodes
init_check_scripts
install_ntp_each_node
crontab_check
}
main 2>&1 | tee -a ${log_file}