77 lines
2.7 KiB
Bash
77 lines
2.7 KiB
Bash
#!/bin/bash
|
||
echoColor(){
|
||
echo -e "\033[41;33m $1 \033[0m"
|
||
}
|
||
|
||
|
||
judgeOK(){
|
||
if [ $? -ne 0 ]
|
||
then
|
||
echoColor "faild,please check log..."
|
||
exit
|
||
fi
|
||
}
|
||
|
||
echoStartLine(){
|
||
echo "------------------------------------" >> $1
|
||
echo "--------- $2 start--------" >> $1
|
||
echo "------------------------------------" >> $1
|
||
}
|
||
|
||
echoEndLine(){
|
||
judgeOK
|
||
echo "------------------------------------" >> $1
|
||
echo "---------$2 end--------" >> $1
|
||
echo "------------------------------------" >> $1
|
||
}
|
||
|
||
|
||
echoColor "更新操作系统ing..."
|
||
echoStartLine serverInit.log "apt update -y"
|
||
apt update -y >> serverInit.log 2>&1
|
||
echoEndLine serverInit.log "apt update -y"
|
||
echoStartLine serverInit.log "apt upgrade -y"
|
||
apt upgrade -y >> serverInit.log 2>&1
|
||
echoEndLine serverInit.log "apt upgrade -y"
|
||
echoColor "更新操作系统完毕"
|
||
|
||
|
||
echoColor "安装常用软件net-tools、nload、lrzsz jq..."
|
||
echoStartLine serverInit.log "apt install net-tools nload lrzsz jq -y"
|
||
apt install net-tools nload lrzsz jq -y >> serverInit.log 2>&1
|
||
echoEndLine serverInit.log "apt install net-tools nload lrzsz jq -y"
|
||
echoColor "安装常用软件完毕"
|
||
|
||
|
||
echoColor "安装node exporter ..."
|
||
echoStartLine serverInit.log "安装node exporter ..."
|
||
wget -P /opt/ http://119.45.208.119:81/download/node_exporter-1.8.1.linux-amd64.tar.gz >> serverInit.log 2>&1
|
||
tar -zxvf /opt/node_exporter-1.8.1.linux-amd64.tar.gz --remove-files -C /opt/
|
||
echoEndLine serverInit.log "安装node exporter 完毕"
|
||
echoColor "安装node exporter 完毕"
|
||
|
||
|
||
echoColor "写入node exporter services ..."
|
||
echoStartLine serverInit.log "写入node exporter services ..."
|
||
wget -P /usr/lib/systemd/system/ http://119.45.208.119:81/download/nodeExport.service >> serverInit.log 2>&1
|
||
echoEndLine serverInit.log "写入node exporter services 成功"
|
||
echoColor "写入node exporter services成功"
|
||
|
||
|
||
|
||
echoColor "启动node exporter ..."
|
||
echoStartLine serverInit.log "启动node exporter ..."
|
||
systemctl daemon-reload >> serverInit.log 2>&1
|
||
systemctl enbale nodeExport.service >> serverInit.log 2>&1
|
||
systemctl start nodeExport.service >> serverInit.log 2>&1
|
||
echoEndLine serverInit.log "启动node exporter完成"
|
||
echoColor "启动node exporter完成"
|
||
|
||
|
||
echoColor "向consul注册..."
|
||
echoStartLine serverInit.log "向consul注册..."
|
||
IP=$(curl -s cip.cc | grep IP | awk -F : '{print $2}' | sed 's/ //g')
|
||
SERVICE_JSON=$(jq -n --arg ip "$IP" '{Name: $ip, Port: 9100, Tags: ["node"], Check: {HTTP: "http://\($ip):9100", Interval: "10s"}}')
|
||
curl -X PUT -H "X-Consul-Token: d3e43a9e-b529-fdde-dc0d-b047d9e51697" -d "$SERVICE_JSON" http://119.45.208.119:8500/v1/agent/service/register
|
||
echoEndLine serverInit.log "向consul注册完成"
|
||
echoColor "注册完成" |