配置管理!安装zabbix-agent如:
zabbix-agent:
pkg.installed:
- name: zabbix-agent
上面安装的zabbix-agent也可以这样来写
zabbix-agent:
pkg.installed
例:安装zabbix-agenthttp://docs.saltstack.cn/zh_CN/latest/ref/states/all/salt.states.file.html#module-salt.states.file
安装包
zabbix_agent:
pkg.installed:
- name: zabbix22-agent
配置文件
file.managed:
- name: /etc/zabbix_agent.conf--------------------------->minion端文件
- source: salt://init/files/zabbix_agentd.conf----------->master端文件位置
- user: root
- group: root
- mode: 644
启动服务
service.running:
- name: zabbix_agentd
- enable: True------------------------------------------>开机启动
- reload: True------------------------------------------>配置更新后reload,
注意:”不添加reload有可能自己进行restart
如下:
[root@master init]# cat zabbix_agent.sls
zabbix_agent:
pkg.installed:
- name: zabbix22-agent
file.managed:
- name: /etc/zabbix_agent.conf
- source: salt://init/files/zabbix_agentd.conf
- user: root
- group: root
- mode: 644
service.running:
- name: zabbix_agentd
- enable: True
- reload: True
[root@master init]#
[root@master init]# mkdir -p /etc/salt/status/init/files
[root@master files]# pwd
/etc/salt/status/init/files
复制一个zabbix_agent配置文件
[root@master files]# scp 10.0.0.23:/etc/zabbix_agent.conf ./
[root@master files]# pwd
/etc/salt/status/init/files
[root@master files]#
[root@master files]# vim zabbix_agent.conf
Server=192.168.233.130
将zabbix_agent.sls
定义到top.sls
中,top执行完不需要重启
[root@master files]# vim /etc/salt/status/top.sls
base:
'm*.*.com':
- match: pcre
- init.pkg
- init.zabbix_agent
添加完毕后,测试'minion.23.com'
上
[root@master init]# salt 'minion.23.com' state.highstate test=True
minion.23.com:
----------
ID: pkg.init
Function: pkg.installed
Name: mtr
Result: True
Comment: Package mtr is already installed.
Started: 06:41:07.461557
Duration: 659.368 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: nginx
Result: True
Comment: Package nginx is already installed.
Started: 06:41:08.121087
Duration: 0.394 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: lrzsz
Result: True
Comment: Package lrzsz is already installed.
Started: 06:41:08.121537
Duration: 0.236 ms
Changes:
----------
ID: zabbix_agent
Function: pkg.installed
Name: zabbix22-agent
Result: True
Comment: Package zabbix22-agent is already installed.
Started: 06:41:08.121869
Duration: 0.249 ms
Changes:
----------
ID: zabbix_agent
Function: file.managed
Name: /etc/zabbix_agentd.conf
Result: None
Comment: The file /etc/zabbix_agentd.conf is set to be changed
Started: 06:41:08.124101
Duration: 7.601 ms
Changes:
----------
diff:
---
+++
@@ -78,7 +78,8 @@
# Default:
# Server=
-Server=127.0.0.1
+#Server=127.0.0.1
+Server=10.0.0.22
### Option: ListenPort
# Agent will listen on this port for connections from the server.
----------
ID: zabbix_agent
Function: service.running
Name: zabbix_agentd
Result: False
Comment: The named service zabbix_agentd is not available
Started: 06:41:08.132359
Duration: 6.232 ms
Changes:
Summary
------------
Succeeded: 5 (unchanged=1, changed=1)
Failed: 1
------------
Total states run: 6
[root@master init]#
正式的执行:
[root@master init]# salt '*' state.highstate
minion.23.com:
----------
ID: pkg.init
Function: pkg.installed
Name: mtr
Result: True
Comment: Package mtr is already installed.
Started: 07:04:32.096445
Duration: 674.256 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: nginx
Result: True
Comment: Package nginx is already installed.
Started: 07:04:32.770899
Duration: 0.407 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: lrzsz
Result: True
Comment: Package lrzsz is already installed.
Started: 07:04:32.771405
Duration: 0.236 ms
Changes:
----------
ID: zabbix_agent
Function: pkg.installed
Name: zabbix22-agent
Result: True
Comment: Package zabbix22-agent is already installed.
Started: 07:04:32.771696
Duration: 0.303 ms
Changes:
----------
ID: zabbix_agent
Function: file.managed
Name: /etc/zabbix_agentd.conf
Result: True
Comment: File /etc/zabbix_agentd.conf updated
Started: 07:04:32.774071
Duration: 6.959 ms
Changes:
----------
diff:
New file
mode:
0644
----------
ID: zabbix_agent
Function: service.running
Name: zabbix-agentd
Result: True
Comment: Service zabbix-agentd has been enabled, and is running
Started: 07:04:32.781431
Duration: 114.562 ms
Changes:
----------
zabbix-agentd:
True
Summary
------------
Succeeded: 6 (changed=2)
Failed: 0
[root@master init]#
使用service查看
[root@master init]# salt '*' service.status zabbix-agent
minion.21.com:
True
minion.23.com:
True
master.22.com:
True
[root@master init]#
3台机器已经全部安装并且允许
当文件有变动则进行reload需要添加watch
- watch:
- file: zabbix_agent
如下:
[root@master init]# cat zabbix_agent.sls
zabbix_agent:
pkg.installed:
- names:
- zabbix22-agent
file.managed:
- name: /etc/zabbix_agentd.conf
- source: salt://init/files/zabbix_agentd.conf
- user: root
- group: root
- mode: 644
service.running:
- name: zabbix-agentd
- enable: True
- reload: True
- watch:
- file: zabbix_agent
而后修改/init/files/zabbix_agentd.conf
中任意的文件,以示区分
注意:这里的reload是手动修改reload成restart才可以reload的!
[root@master init]# salt '*' state.highstate
minion.23.com:
----------
ID: pkg.init
Function: pkg.installed
Name: mtr
Result: True
Comment: Package mtr is already installed.
Started: 07:23:39.333600
Duration: 829.029 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: nginx
Result: True
Comment: Package nginx is already installed.
Started: 07:23:40.162791
Duration: 0.433 ms
Changes:
----------
ID: pkg.init
Function: pkg.installed
Name: lrzsz
Result: True
Comment: Package lrzsz is already installed.
Started: 07:23:40.163276
Duration: 0.252 ms
Changes:
----------
ID: zabbix_agent
Function: pkg.installed
Name: zabbix22-agent
Result: True
Comment: Package zabbix22-agent is already installed.
Started: 07:23:40.163586
Duration: 0.217 ms
Changes:
----------
ID: zabbix_agent
Function: file.managed
Name: /etc/zabbix_agentd.conf
Result: True
Comment: File /etc/zabbix_agentd.conf updated
Started: 07:23:40.165805
Duration: 12.912 ms
Changes:
----------
diff:
---
+++
@@ -77,12 +77,12 @@
# Mandatory: no
# Default:
# Server=
-
-#Server=127.0.0.1
-#Server=127.0.0.1
-#Server=127.0.0.1
-#Server=127.0.0.1
-#Server=127.0.0.1
+# Server=
+# Server=
+# Server=
+# Server=
+# Server=
+
#Server=127.0.0.1
Server=10.0.0.22
----------
ID: zabbix_agent
Function: service.running
Name: zabbix-agentd
Result: True
Comment: Service reloaded
Started: 07:23:40.206135
Duration: 191.221 ms
Changes:
----------
zabbix-agentd:
True
Summary
------------
Succeeded: 6 (changed=2)
Failed: 0
------------
Total states run: 6