Centos6.5_salt自动部署zabbix_agentd(二)
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
# cat top.sls
base:
'*':
- sls.zabbix_agentd.install
- sls.zabbix_agentd.conf 1.2、/conf/windows/zabbix_agentd/zabbix_agentd_conf.bat
# 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
# 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']}}
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
# 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'] }} #获取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]