设为首页 收藏本站
查看: 944|回复: 0

[经验分享] saltstack的探索-演示部署文件和脚本安装zabbix-agent服务

[复制链接]

尚未签到

发表于 2018-8-1 08:39:11 | 显示全部楼层 |阅读模式
1. 配置salt-master  
# yum  -y install salt-master
  
# service salt-master start
  

  
防火墙放行端口:4505:4506
  

  

  
2. 配置其他主机test1-test9为minion
  
# yum  -y install salt-minion
  

  
调整配置文件
  
# vim /etc/salt/minion
  
master: ip
  
id: hostname
  

  
以其中一个minion为例:
  
# cp -a /etc/salt/minion /etc/salt/minion.bak && s_ip=10.10.10.1 && s_host=$(hostname) && sed -i -e "s/#master: salt/master: ${s_ip}/"  -e "s/#id:/id: ${s_host}/" /etc/salt/minion && cat /etc/salt/minion |grep ^[^#]
  
master: 10.10.10.1
  
id: test1.company.com
  

  
# service salt-minion start
  

  

  

  
3. master接受minion
  
[root@master ~]# salt-key -L
  
Accepted Keys:
  
Unaccepted Keys:
  
test1.company.com
  
test2.company.com
  
test3.company.com
  
test4.company.com
  
test5.company.com
  
test6.company.com
  
test7.company.com
  
test8.company.com
  
test9.company.com
  
Rejected Keys:
  
[root@master ~]# salt-key -a *.company.com
  
The following keys are going to be accepted:
  
Unaccepted Keys:
  
test1.company.com
  
test2.company.com
  
test3.company.com
  
test4.company.com
  
test5.company.com
  
test6.company.com
  
test7.company.com
  
test8.company.com
  
test9.company.com
  
Proceed? [n/Y] y
  
Key for minion test1.company.com accepted.
  
Key for minion test2.company.com accepted.
  
Key for minion test3.company.com accepted.
  
Key for minion test4.company.com accepted.
  
Key for minion test5.company.com accepted.
  
Key for minion test6.company.com accepted.
  
Key for minion test7.company.com accepted.
  
Key for minion test8.company.com accepted.
  
Key for minion test9.company.com accepted.
  

  

  
[root@master ~]# salt "*.company.com" test.ping
  
test1.company.com:
  
    True
  
test2.company.com:
  
    True
  
test3.company.com:
  
    True
  
test4.company.com:
  
    True
  
test5.company.com:
  
    True
  
test6.company.com:
  
    True
  
test7.company.com:
  
    True
  
test8.company.com:
  
    True
  
test9.company.com:
  
    True
  

  

  
4. 【更新vim配置】
  
[root@master salt]# salt '*.company.com' state.sls edit.vim
  

  
salt的配置如下:
  
-----------
  
[root@master srv]# ls
  
pillar  salt
  
[root@master srv]# pwd
  
/srv
  
[root@master srv]# cat salt/edit/vim.sls
  
vim:
  
    pkg:
  
      - installed
  
      - name: {{ pillar['pkgs']['vim'] }}
  

  
/root/.vimrc:
  
    file.managed:
  
        - source: salt://edit/conf/vimrc
  
        - mode: 644
  
        - uesr: root
  
        - group: root
  
        - require:
  
          - pkg: vim
  
[root@master srv]# ls salt/edit/conf/
  
vimrc
  
[root@master srv]# cat pillar/top.sls
  
base:
  
  '*':
  
    - pkg
  
[root@master srv]# cat pillar/pkg/init.sls
  
pkgs:
  
  {% if grains['os_family'] == 'RedHat' %}
  
  vim: vim-enhanced
  
  {% elif grains['os_family'] == 'Debian' %}
  
  vim: vim
  
  {% elif grains['os'] == 'Arch' %}
  
  vim: vim
  
  {% endif %}
  
-----------
  

  

  

  
5. 【增加zabbix-agent】
  
目录和脚本:
  
[root@master salt]# ls zabbix/
  
agent.sls  bin/       sbin/
  
[root@master salt]# ls zabbix/bin/
  
install_agent.sh  zabbix-agent
  
[root@master salt]# ls zabbix/sbin/
  
zabbix_agent  zabbix_agentd
  
[root@master salt]# cat zabbix/bin/install_agent.sh
  
#!/bin/bash
  
#
  
# 2015/4/10
  

  
cip=$(ip a s dev em2  |grep "global" |awk '{print $2}' |cut -d '/' -f1)
  
sip='10.10.10.10'
  

  
#cp ./zabbix-agent /etc/init.d/
  
#cp ../sbin/zabbix* /usr/sbin/
  
mkdir -p /etc/zabbix/zabbix_agentd.conf.d
  
cat <<_CFG >>/etc/zabbix/zabbix_agentd.conf
  
PidFile=/tmp/zabbix_agentd.pid
  
LogFile=/tmp/zabbix_agentd.log
  
SourceIP=$cip
  
Server=$sip
  
ListenIP=$cip
  
ServerActive=$sip
  
Hostname=$cip
  
Timeout=30
  
Include=/etc/zabbix/zabbix_agentd.conf.d/
  
_CFG
  

  
useradd -s /sbin/nologin -d /var/lib/zabbix -c "Zabbix Monitoring System" zabbix
  
chmod +x /etc/init.d/zabbix-agent
  
service zabbix-agent start
  
chkconfig zabbix-agent on
  
chkconfig --list |grep zabbix
  

  

  
salt配置:
  
[root@master salt]# cat zabbix/agent.sls
  
/usr/sbin/zabbix_agent:
  
  file.managed:
  
    - source: salt://zabbix/sbin/zabbix_agent
  
    - mode: 755
  

  
/usr/sbin/zabbix_agentd:
  
  file.managed:
  
    - source: salt://zabbix/sbin/zabbix_agentd
  
    - mode: 755
  

  
/etc/rc.d/init.d/zabbix-agent:
  
  file.managed:
  
    - source: salt://zabbix/bin/zabbix-agent
  
    - mode: 755
  

  
/data/ops/bin/install_agent.sh:
  
  file.managed:
  
    - source: salt://zabbix/bin/install_agent.sh
  
    - mode: 755
  
  require:
  
    - file: /etc/rc.d/init.d/zabbix-agent
  

  
install-agent:
  
  cmd.run:
  
    - require:
  
      - file: /data/ops/bin/install_agent.sh
  
    - name: /bin/bash /data/ops/bin/install_agent.sh
  

  

  
在其中一台上测试执行这个sls:
  
[root@master salt]# salt 'test1.company.com' state.sls zabbix.agent
  
test1.company.com:
  
----------
  
          ID: /usr/sbin/zabbix_agent
  
    Function: file.managed
  
      Result: True
  
     Comment: File /usr/sbin/zabbix_agent updated
  
     Started: 17:01:15.356802
  
    Duration: 352.254 ms
  
     Changes:
  
              ----------
  
              diff:
  
                  New file
  
              mode:
  
                  0755
  
----------
  
          ID: /usr/sbin/zabbix_agentd
  
    Function: file.managed
  
      Result: True
  
     Comment: File /usr/sbin/zabbix_agentd updated
  
     Started: 17:01:15.709238
  
    Duration: 93.603 ms
  
     Changes:
  
              ----------
  
              diff:
  
                  New file
  
              mode:
  
                  0755
  
----------
  
          ID: /etc/rc.d/init.d/zabbix-agent
  
    Function: file.managed
  
      Result: True
  
     Comment: File /etc/rc.d/init.d/zabbix-agent updated
  
     Started: 17:01:15.802999
  
    Duration: 8.472 ms
  
     Changes:
  
              ----------
  
              diff:
  
                  New file
  
              mode:
  
                  0755
  
----------
  
          ID: /data/ops/bin/install_agent.sh
  
    Function: file.managed
  
      Result: True
  
     Comment: File /data/ops/bin/install_agent.sh updated
  
     Started: 17:01:15.811627
  
    Duration: 7.134 ms
  
     Changes:
  
              ----------
  
              diff:
  
                  New file
  
              mode:
  
                  0755
  
----------
  
          ID: install-agent
  
    Function: cmd.run
  
        Name: /bin/bash /data/ops/bin/install_agent.sh
  
      Result: True
  
     Comment: Command "/bin/bash /data/ops/bin/install_agent.sh" run
  
     Started: 17:01:15.819710
  
    Duration: 118.255 ms
  
     Changes:
  
              ----------
  
              pid:
  
                  3524
  
              retcode:
  
                  0
  
              stderr:
  

  
              stdout:
  
                  Starting Zabbix agent: [  OK  ]
  
                  zabbix-agent          0:off   1:off   2:on    3:on    4:on    5:on    6:off
  

  
Summary
  
------------
  
Succeeded: 5 (changed=5)
  
Failed:    0
  
------------
  
Total states run:     5
  

  

  
确认无误后,批量执行。
  
[root@master salt]# salt '*.company.com' state.sls zabbix.agent
  

  
注:后续再采用rpm包来安装,此处只是简单的做法,演示部署文件和脚本。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-544476-1-1.html 上篇帖子: SaltStack源码分析之使用Redis模块 下篇帖子: CentOS6.5 安装 SaltStack
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表