同一文件夹下建立pwd.txt,格式如下:

ip username password

ip username password

#!/bin/bash
cat pwd.txt | while read line
do
hostip=`echo $line | cut -d" " -f1`
uname=`echo $line | cut -d" " -f2`
pwd=`echo $line | cut -d" " -f3` /usr/bin/expect <<-EOF
set timeout 600
spawn scp -r /tmp/zabbix-3.4.12.tar.gz $uname@$hostip:/tmp/
expect {
 "*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$pwd\r" }
}
spawn scp -r /tmp/3.sh $uname@$hostip:/tmp/
 expect {
 "*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$pwd\r" }
}
spawn ssh $uname@$hostip
 expect {
 "*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$pwd\r" }
}
expect "*]#"
send "chmod +x /tmp/3.sh\r"
expect "*]#"
send "sh /tmp/3.sh\r"
expect "*]#"
send "exit\r"
interact
expect eof
EOF done

3.sh

#!/bin/bash
yum -y install pcre*
egrep "^zabbix" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    groupadd zabbix
fi
egrep "^zabbix" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    useradd -g zabbix zabbix -s /sbin/nologin
fi
cd /tmp/
tar -zxvf /tmp/zabbix-3.4.12.tar.gz
cd /tmp/zabbix-3.4.12/
./configure --prefix=/usr/local/zabbix-agent --enable-agent
make
make install
cd /tmp/zabbix-3.4.12/misc
cp init.d/tru64/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_agentd
cp -r /etc/init.d/zabbix_agentd /tmp/zabbix_agentd.bak
sed -i 's/DAEMON=\/usr\/local\/sbin\/zabbix_agentd/DAEMON=\/usr\/local\/zabbix-agent\/sbin\/zabbix_agentd/g' /etc/init.d/zabbix_agentd
sed -i '/#!\/bin\/sh/a\#chkconfig: 345 95 95' /etc/init.d/zabbix_agentd
sed -i '/#chkconfig: 345 95 95/a\#description: Zabbix_Server' /etc/init.d/zabbix_agentd
chkconfig zabbix_agentd on
sed -i 's/Server=127.0.0.1/Server=193.168.120.77/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive=193.168.120.77/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
HOSTNAME=`hostname`
sed -i 's/Hostname=Zabbix server/Hostname='$HOSTNAME'/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
sed -i 's/LogFile=\/tmp\/zabbix_agentd.log/LogFile=\/var\/log\/zabbix\/zabbix_agentd.log/g' /usr/local/zabbix-agent/etc/zabbix_agentd.conf
mkdir -p /var/log/zabbix
chown -R zabbix.zabbix /var/log/zabbix/
chown -R zabbix.zabbix /usr/local/zabbix-agent/ /etc/init.d/zabbix_agentd start

Linux记录-批量安装zabbix(转载)的更多相关文章

  1. Linux记录-批量安装LNMP(转载)

    #!/bin/bash # Describe: This is a one - button installation service script # 提示:使用此脚本时,尽量先选择第一项配置Yum ...

  2. Linux记录-批量安装ssh(转载)

    首先,需要检查expect是否安装:rpm -qa|grep expect 然后,在操作机上创建公钥:ssh-keygen 一路回车即可 创建好之后到/root/.ssh/下就可以看到id开头的2个文 ...

  3. Linux记录-批量安装软件服务(转载)

    #!/bin/bash # 安装函数 install(){    for soft in $*    do         echo "$soft"安装中...         y ...

  4. Zabbix 4.0.2试用(七):在Linux主机中安装zabbix agent并添加该主机(yum源安装)

    Zabbix 4.0.2试用(七):在Linux主机中安装zabbix agent并添加主机(yum源安装) 2018年12月20日, 上午6:42 之前介绍的是下载源安装包,编译安装的方式来安装ag ...

  5. Redis进阶实践之一VMWare Pro虚拟机安装和Linux系统的安装(转载)(1)

    Redis进阶实践之一VMWare Pro虚拟机安装和Linux系统的安装 一.引言 设计模式写完了,相当于重新学了一遍,每次学习都会有不同的感受,对设计模式的理解又加深了,理解的更加透彻了.还差一篇 ...

  6. ansible 批量安装zabbix agentd客户端

    目录结构 # tree /etc/ansible/ /etc/ansible/ ├── ansible.cfg ├── hosts ├── roles │   └── zabbix-agentd │  ...

  7. Linux记录-salt-minion安装

    python -m SimpleHTTPServer 8888#!/bin/bash sed -i 's/^#//g' /etc/yum.repos.d/centos7.4.repo sed -i ' ...

  8. Linux记录-AWK语法(转载)

    1.原理 awk,一个行文本处理工具,逐行处理文件中的数据 语法:awk 'pattern + {action}' 说明:(1)单引号''是为了和shell命令区分开:(2)大括号{}表示一个命令分组 ...

  9. Linux记录-批量更改当前目录的文件后缀名

    #!/bin/bash path=. for file in $(ls $path) do if [ -f $file ] then filename=${file%.*} bak=${file#*. ...

随机推荐

  1. SSM自测错题解析

    试题解析:spring 中bean的作用域有:singleton.session.prototype.request.global Session 试题解析:使用import导入子元素需要用prope ...

  2. python爬取动态网页数据,详解

    原理:动态网页,即用js代码实现动态加载数据,就是可以根据用户的行为,自动访问服务器请求数据,重点就是:请求数据,那么怎么用python获取这个数据了? 浏览器请求数据方式:浏览器向服务器的api(例 ...

  3. href = '' 表示刷新当前页面

    <a href="javascript:;" target="_blank"><img src="../img/focus-slid ...

  4. Oracle CAST() 函数 数据类型的转换

    CAST()函数可以进行数据类型的转换. CAST()函数的参数有两部分,源值和目标数据类型,中间用AS关键字分隔. 以下例子均通过本人测试. 一.转换列或值 语法:cast( 列名/值 as 数据类 ...

  5. nohup 后台执行

    nohup  默认是当前用户执行的,当当前用户退出会导致执行进程异常. 所以正确的 nohup 是指定 /bin/bash 进行执行. nohup /bin/bash/ /opt/script/s.s ...

  6. word collocations中文版(信息检索)

    虽然说是大作业,也做了好几天,但是完全没有什么实际价值...就是把现有的东西东拼西凑一下,发现跑的特别慢还搞了个多核 写这篇blog纯属是我吃饱了没事干,记录一下装env的蛋疼 首先我们是在pytho ...

  7. 【概率论】6-2:大数定理(The Law of Large Numbers)

    title: [概率论]6-2:大数定理(The Law of Large Numbers) categories: - Mathematic - Probability keywords: - Ma ...

  8. word 插入表格,位置不在最左边

    首先想到的是 样式的问题.

  9. Pytest权威教程07-Monkeypatching,对模块和环境进行Mock

    目录 Monkeypatching,对模块和环境进行Mock 简单示例如: 猴子补丁方法 Monkeypatching 返回对象: 构建mock类 全局补丁示例如:阻止"requests&q ...

  10. OpenCV reshape The Matrix is not continuous, thus its number of rows can not be changed

    When using OpenCV  reshape and gets this error: OpenCV Error: Image step is wrong (The matrix is not ...