linux安装nodejs一键脚本,批量安装node_exporter脚本

github地址:https://github.com/zhuqiyang/install-node_exporter-shell

批量安装node_exporter:适用于CentOS6、CentOS7两个版本。#!/bin/bash

#######################################

#                                     #

#        install node_exporter        #

#                                     #

#######################################

set -x

export HOST_IP=$1

export PACKAGE_NAME=$2

if [ -z "$1" ] || [ -z "$2" ]; then

cat <

bash $0 HOST_IP PACKAGE_NAME

EOF

exit

fi

# check ssh without password

ssh -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -o ConnectTimeout=1 $HOST_IP 'date'

if [ $? -ne 0 ]; then

echo 'Unable to log in without password'

exit

fi

# check 9100 port exists

export PORT_EXISTS=$(ssh $HOST_IP  'lsof -i:9100 > /dev/null' && echo $?)

if [ "$PORT_EXISTS" = "0" ]; then

echo "9100 port exists"

exit

fi

#  check OS version

export OS_RELEASE=`ssh $HOST_IP "uname -r"`

scp_file(){

ssh $HOST_IP 'hostname'

scp $PACKAGE_NAME ${HOST_IP}:/tmp/

ssh $HOST_IP "tar -xf /tmp/$PACKAGE_NAME -C /usr/local/ && cd /usr/local/ && ln -sv node_exporter-1.0.1.linux-amd64/ node_exporter"

}

if grep '.el7.' <<

scp_file

scp ./node_exporter.service ${HOST_IP}:/usr/lib/systemd/system/

ssh $HOST_IP 'systemctl start node_exporter.service'

ssh $HOST_IP 'systemctl enable node_exporter.service'

ssh $HOST_IP 'rm /tmp/node_exporter-1.0.1.linux-amd64.tar.gz'

elif grep '.el6.' <<

scp_file

scp node_exporter ${HOST_IP}:/etc/init.d/

ssh $HOST_IP 'chmod +x /etc/init.d/node_exporter'

ssh $HOST_IP 'service node_exporter start'

ssh $HOST_IP 'rm /tmp/node_exporter-1.0.1.linux-amd64.tar.gz'

fi

其他版本的linux:#!/bin/bash

export HOST_IP=$1

export PACKAGE_NAME=$2

# check ssh without password

ssh -p22 -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no $HOST_IP 'date'

if [ $? -ne 0 ]; then

echo 'Unable to log in without password'

echo $HOST_IP >> notok.txt

exit

fi

# check 9100 port exists

export PORT_EXISTS=$(ssh -p22 -o ConnectTimeout=2 $HOST_IP  'lsof -i:9100 > /dev/null' && echo $?)

if [ "$PORT_EXISTS" = "0" ]; then

echo "9100 port exists"

echo $HOST_IP >> portnotok.txt

#exit

fi

ssh -p22 $HOST_IP 'hostname'

scp -P22 $PACKAGE_NAME ${HOST_IP}:/tmp/

ssh -p22 $HOST_IP "tar -xf /tmp/$PACKAGE_NAME -C /usr/local/ && cd /usr/local/ && ln -sv node_exporter-1.0.1.linux-amd64/ node_exporter"

scp -P22 start.sh ${HOST_IP}:/usr/local/node_exporter/

ssh -p22 $HOST_IP "cd /usr/local/node_exporter && chmod +x start.sh && ./start.sh"

ssh -p22 $HOST_IP 'rm /tmp/node_exporter-1.0.1.linux-amd64.tar.gz'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值