salt服务器的根目录为:/srv/salt/ (下面写salt服务器路径都是在此目录下)
一、服务端准备工作(建目录,写配置文件)
Windows和linux批量部署准备工作
1、新建目录:
/conf/windows/zabbix_agentd
/file/windows/zabbix_agentd/tmp
/sls/zabbix_agentd
/conf/linux/zabbix_agentd
2、新建文件:
1.1、top.sls
[root@zabbix salt]# cat top.sls
base:
'*':
- sls.zabbix_agentd.install
- sls.zabbix_agentd.conf 1.2、/conf/windows/zabbix_agentd/zabbix_agentd_conf.bat
[root@zabbix salt]# cat conf/windows/zabbix_agentd/zabbix_agentd_conf.bat
@echo off
setlocal enabledelayedexpansion
set file=c:\zabbix_agentd.conf
set "file=%file:"=%"
for %%i in ("%file%") do set file=%%~fi
echo.
set replaced=windowsagentd
echo.
set all=%computername%
for /f "delims=" %%i in ('type "%file%"') do (
set str=%%i
set "str=!str:%replaced%=%all%!"
echo !str!>>"%file%"_tmp.txt
)
copy "%file%" "%file%"_bak.txt >nul 2>nul
move "%file%"_tmp.txt "%file%"
start "" "%file%" 1.2、/file/windows/zabbix_agentd/tmp/zabbix_agentd.log
1.3、/sls/zabbix_agnetd/conf.sls
[root@zabbix salt]# cat sls/zabbix_agentd/conf.sls
{% if grains ['os'] == 'CentOS' %}
zabbix_agentd_conf:
file.managed:
- name: /usr/local/etc/zabbix_agentd.conf
- source: salt://conf/linux/zabbix_agentd/zabbix_agentd.conf
- template: jinja
- defaults:
Hostname: {{ grains ['ip_interfaces']['eth1'][0]}}
zabbix_agentd_service:
file.managed:
- name: /etc/init.d/zabbix_agentd
- user: root
- mode: 755
- source: salt://conf/linux/zabbix_agentd/zabbix_agentd
cmd.run:
- names:
- /bin/chmod +x /etc/init.d/zabbix_agentd
- /sbin/chkconfig --add zabbix_agentd
- /sbin/chkconfig zabbix_agentd on
- /etc/init.d/zabbix_agentd start
- unless: /sbin/chkconfig --list zabbix_agentd
service.running:
- name: zabbix_agentd
- enable: True
- restart: True
- watch:
- file: /usr/local/etc/zabbix_agentd.conf
{% elif grains ['os'] == 'Windows' %}
zabbix_agentd_file:
file.recurse:
- source: salt://file/windows/zabbix_agentd
- name: c:/
- makedir: True
- backup: minion
- unless: c:/zabbix-2.4.4
zabbix_agentd_conf:
file.managed:
- name: C:/zabbix_agentd.conf
- source: salt://conf/windows/zabbix_agentd/zabbix_agentd.conf
- unless: test -d c:/zabbix_agentd.conf
zabbix_agentd_bat:
file.managed:
- name: C:/zabbix_agentd_conf.bat
- source: salt://conf/windows/zabbix_agentd/zabbix_agentd_conf.bat
- unless: test -d c:/zabbix_agentd_conf.bat
zabbix_agentd_change:
cmd.run:
- names:
- c:/zabbix_agentd_conf.bat
- require:
- file: zabbix_agentd_bat
zabbix_agentd:
cmd.run:
- names:
- c:/zabbix-2.4.4/bin/win64/zabbix_agentd.exe
- unless:
- stderr:zabbix_agentd.exe
{% endif %} 1.4、/sls/zabbix_agentd/install.sls
[root@zabbix salt]# cat sls/zabbix_agentd/install.sls
{% if grains['os'] == 'CentOS' %}
zabbix_agentd_source:
file.managed:
- name: /tmp/zabbix-2.4.4.tar.gz
- unless: test -e /tmp/zabbix-2.4.4.tar.gz
- user: root
- goup: root
- makedirs: True
- source: salt://file/linux/zabbix_agentd/zabbix-2.4.4.tar.gz
zabbix_agentd_extract:
cmd.run:
- cwd: /tmp
- names:
- tar xvf zabbix-2.4.4.tar.gz
- unless: test -d /tmp/zabbix-2.4.4
- require:
- file: zabbix_agentd_source
zabbbix_user:
user.present:
- name: zabbix
- createhome: Fales
- gid_from_name: True
- shell: /sbin/nologin
zabbix_agentd_compile:
cmd.run:
- cwd: /tmp/zabbix-2.4.4
- names:
- ./configure --enable-agent
- unless: test -d /tmp/zabbix-2.4.4
- require:
- cmd: zabbix_agentd_extract
zabbix_agentd_make:
cmd.run:
- cwd: /tmp/zabbix-2.4.4
- names:
- make install
- unless: test -d /tmp/zabbix-2.4.4
- require:
- cmd: zabbix_agentd_compile
{% elif grains['os'] == 'Windows' %}
{% endif %} 1.4、
3、安装文件摆放:
将zabbix-2.4.4.tar.gz复制到file/linux/zabbix_agentd目录下
解压zabbix-2.4.4.tar.gz,将解压出来的zabbix-2.4.4整个文件夹复制到:/file/windows/zabbix_agentd/
4、修改配置文件:
4.1、将安装包里面的conf/zabbix_agentd.conf复制到salt服务器conf/linux/zabbix_agentd/zabbix_agentd.conf并修改内容
Server=192.168.203.30,192.168.203.1 #你的服务器地址以及服务器网关,如果是跨网段最好写上网关。
ServerActive=192.168.203.30,192.168.203.1
Hostname={{ grains ['ip_interfaces']['eth1'][0] }} #获取IP地址赋值给hostname 4.2、将安装包里面的 misc/init.d/fedora/core/zabbix_agentd文件复制到salt服务器conf/windows/zabbix_agentd/zabbix_agentd
4.3、将安装包里面的conf/zabbix_agentd.win.conf复制到salt服务器conf/windows/zabbix_agentd/zabbix_agentd.conf并修改内容
Server=192.168.203.30,192.168.203.1 #你的服务器地址以及服务器网关,如果是跨网段最好写上网关。
ServerActive=192.168.203.30,192.168.203.1
Hostname=windowsagentd #为了bat而定义的hostname,如果更改hostname为其他字符,后面的bat文件也要更改。
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com