Browse Source

一些优化

master
xiaoz 3 years ago
parent
commit
41ae8591c4
  1. 28
      node_exporter.sh

28
node_exporter.sh

@ -14,19 +14,21 @@ INSTALL_PATH="/opt/node_exporter"
#安装前准备 #安装前准备
depend(){ depend(){
echo "Pre-installation preparation is in progress..."
if [ -e "/usr/bin/yum" ] if [ -e "/usr/bin/yum" ]
then then
yum -y install wget yum -y install wget curl
else else
#更新软件,否则可能make命令无法安装 #更新软件,否则可能make命令无法安装
apt-get -y update apt-get -y update
apt-get install -y wget apt-get install -y wget curl
fi fi
#创建目录 #创建目录
#mkdir -p ${INSTALL_PATH} #mkdir -p ${INSTALL_PATH}
} }
#下载 #下载
download(){ download(){
echo "Ready to download the installation package..."
wget -P /opt http://soft.xiaoz.org/linux/node_exporter-${VERSION}.linux-amd64.tar.gz wget -P /opt http://soft.xiaoz.org/linux/node_exporter-${VERSION}.linux-amd64.tar.gz
cd /opt && tar -xvf node_exporter-${VERSION}.linux-amd64.tar.gz cd /opt && tar -xvf node_exporter-${VERSION}.linux-amd64.tar.gz
mv node_exporter-${VERSION}.linux-amd64 node_exporter mv node_exporter-${VERSION}.linux-amd64 node_exporter
@ -34,7 +36,7 @@ download(){
#一些额外的配置 #一些额外的配置
setting(){ setting(){
#设置密码访问
cat >> $INSTALL_PATH/config.yaml << EOF cat >> $INSTALL_PATH/config.yaml << EOF
basic_auth_users: basic_auth_users:
$USERNAME_PASSWORD $USERNAME_PASSWORD
@ -44,8 +46,19 @@ EOF
#放行端口 #放行端口
release_port(){ release_port(){
echo "Detecting firewall type..."
#检测防火墙类型
which firewall-cmd
if [ $? -eq 0 ]
then
firewall-cmd --zone=public --add-port=29100/tcp --permanent firewall-cmd --zone=public --add-port=29100/tcp --permanent
firewall-cmd --reload firewall-cmd --reload
fi
which ufw
if [ $? -eq 0 ]
then
ufw allow 29100/tcp
fi
} }
@ -68,10 +81,17 @@ WantedBy=default.target" > /etc/systemd/system/node_exporter.service
systemctl start node_exporter.service systemctl start node_exporter.service
} }
#安装完成
install_success(){
myip=$(curl ip.sb)
echo "Installation is complete, please visit http://${myip}:29100"
}
#清理工作 #清理工作
clean_work() { clean_work() {
echo "Cleaning installation packages..."
rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz rm -rf /opt/node_exporter-${VERSION}.linux-amd64.tar.gz
} }
depend && download && setting && release_port && reg_systemd depend && download && setting && release_port && reg_systemd && install_success
clean_work clean_work
Loading…
Cancel
Save