Ansible部署Zabbix监控工具

[[email protected] roles]# pwd

/etc/ansible/roles

[[email protected] roles]# ls

ansible_zabbix.tar.gz  zabbix

[[email protected] roles]# ll zabbix/

总用量 16

drwxr-xr-x. 2 root root 4096 5月  25 17:15 group_vars

drwxr-xr-x. 8 root root 4096 5月  26 17:25 roles

-rw-r--r--. 1 root root   14 5月  27 11:05 zabbix.retry

-rw-r--r--. 1 root root  140 5月  27 15:29 zabbix.yaml

.角色与包含

├── ansible_zabbix.tar.gz

└── zabbix

├── group_vars

│?? └── zabbix

├── roles

│?? ├── java

│?? │?? ├── files

│?? │?? │?? ├── java.sh

│?? │?? │?? └── jdk-8u101-linux-x64.tar.gz

│?? │?? ├── handlers

│?? │?? │?? └── main.yml

│?? │?? └── tasks

│?? │??     └── main.yml

│?? ├── mysql

│?? │?? ├── files

│?? │?? │?? ├── cmake-2.8.10.2.tar.gz

│?? │?? │?? └── mysql-5.6.24.tar.gz

│?? │?? ├── handlers

│?? │?? │?? └── main.yml

│?? │?? └── tasks

│?? │??     └── main.yml

│?? ├── nginx

│?? │?? ├── files

│?? │?? │?? ├── nginx

│?? │?? │?? ├── nginx-1.10.2.tar.gz

│?? │?? │?? ├── openssl-1.0.2f.tar.gz

│?? │?? │?? ├── pcre-8.38.tar.gz

│?? │?? │?? └── zlib-1.2.8.tar.gz

│?? │?? ├── handlers

│?? │?? │?? └── main.yml

│?? │?? ├── tasks

│?? │?? │?? └── main.yml

│?? │?? └── templates

│?? │??     └── nginx.conf.j2

│?? ├── php

│?? │?? ├── files

│?? │?? │?? ├── index.php

│?? │?? │?? ├── libiconv-1.13.1.tar.gz

│?? │?? │?? ├── libmcrypt-2.5.8.tar.gz

│?? │?? │?? ├── Makefile

│?? │?? │?? ├── mhash-0.9.9.9.tar.gz

│?? │?? │?? ├── php-5.6.29.tar.gz

│?? │?? │?? ├── php-fpm

│?? │?? │?? ├── php-fpm.conf

│?? │?? │?? ├── php.ini

│?? │?? │?? └── testdb.php

│?? │?? ├── handlers

│?? │?? │?? └── main.yml

│?? │?? └── tasks

│?? │??     └── main.yml

│?? ├── yum

│?? │?? ├── files

│?? │?? │?? └── CentOS-Base.repo

│?? │?? └── tasks

│?? │??     └── main.yml

│?? └── zabbix_server

│??     ├── files

│??     │?? ├── zabbix

│      │  ├── zabbix-3.0.4.tar.gz

│      │  ├── zabbix_agentd

│      │  ├── zabbix_server

│      │  └── zabbix_server.conf

│      ├── handlers

│      │   └── main.yml

│      ├── tasks

│      │   └── main.yml

│      └── templates

│           └── zabbix_agentd.conf.j2

├── zabbix.retry

└── zabbix.yaml

定义变量

[[email protected] roles]# cd zabbix/

[[email protected] zabbix]# cat group_vars/zabbix

java_path: /etc/ansible/roles/zabbix/roles/java/files/

nginx_path: /etc/ansible/roles/zabbix/roles/nginx/files/

mysql_path: /etc/ansible/roles/zabbix/roles/mysql/files/

php_path: /etc/ansible/roles/zabbix/roles/php/files/

zabbix_server_path: /etc/ansible/roles/zabbix/roles/zabbix_server/files/

zabbix_agent_path: /etc/ansible/roles/zabbix/roles/zabbix_agent/files/

dest_path: /usr/local/src/

主yaml文件

[[email protected] zabbix]# cat zabbix.yaml

---

- hosts: zabbix

roles:

- role: yum

- role: java

- role: nginx

- role: mysql

- role: php

- role: zabbix_server

role里面的文件内容

[[email protected] roles]# pwd

/etc/ansible/roles/zabbix/roles

[[email protected] roles]# ll

总用量 24

drwxr-xr-x. 5 root root 4096 5月  23 18:14 java

drwxr-xr-x. 5 root root 4096 5月  23 11:46 mysql

drwxr-xr-x. 6 root root 4096 5月  25 21:39 nginx

drwxr-xr-x. 5 root root 4096 5月  24 10:25 php

drwxr-xr-x. 4 root root 4096 5月  19 05:32 yum

drwxr-xr-x. 6 root root 4096 5月  27 16:06 zabbix_server

Yum部署

[[email protected] yum]# pwd

/etc/ansible/roles/zabbix/roles/yum

[[email protected] yum]# tree

.

├── files

│   └── CentOS-Base.repo

└── tasks

└── main.yml

2 directories, 2 files

[[email protected] yum]# cat tasks/main.yml

---

# tasks file for yum

- name: copy the repo

copy: src=CentOS-Base.repo dest=/etc/yum.repos.d/CentOS-Base.repo

- name: clean cache

shell: yum clean all;yum makecache

- name: install software

yum: name=gcc,gcc-c++,make,zlib-devel,ncurses-devel,libxml2,libxml2-devel,libjpeg-devel,libpng-devel,freetype,openldap-devel,openldap,openssl,openssl-devel,pcre,pcre-devel,curl-devel,freetype-devel,net-snmp-devel,mysql-devel state=latest

Java部署

[[email protected] java]# tree

.

├── files

│   ├── java.sh

│   └── jdk-8u101-linux-x64.tar.gz

├── handlers

│   └── main.yml

└── tasks

└── main.yml

3 directories, 4 files

[email protected] java]# cat tasks/main.yml

---

# tasks file for java

- name: jie ya jdk-8u101-linux-x64.tar.gz

unarchive: src={{ java_path }}jdk-8u101-linux-x64.tar.gz dest={{ dest_path }} copy=yes

- name: move jdk

shell: mv /usr/local/src/jdk1.8.0_101 /usr/local/jdk

- name: add bianliang

copy: src=java.sh dest=/etc/profile.d/

#lineinfile: dest=/etc/profile line={{ item }}

#with_items:

#  - export JRE_HOME=/usr/local/jdk

#  - export JAVA_BIN=/usr/local/jdk/bin

#  - export PATH=$JRE_HOME/bin:$PATH

#  - export CLASSPATH=.:$JRE_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar

#  - export JRE_HOME JAVA_BIN PATH CLASSPATH

- name: source profile

shell: source /etc/profile.d/java.sh

#  notify:

#    - add bianliang

#    - source profile

[[email protected] java]# cat handlers/main.yml

---

# handlers file for java

- name: add bianliang

lineinfile: dest=/etc/profile line={{ item }}

with_items:

- export JRE_HOME=/usr/local/jdk

- export JAVA_BIN=/usr/local/jdk/bin

- export PATH=$JRE_HOME/bin:$PATH

- export CLASSPATH=.:$JRE_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar

- export JRE_HOME JAVA_BIN PATH CLASSPATH

- name: source profile

shell: source /etc/profile

Nginx部署

[[email protected] nginx]# tree

.

├── files

│   ├── nginx

│   ├── nginx-1.10.2.tar.gz

│   ├── openssl-1.0.2f.tar.gz

│   ├── pcre-8.38.tar.gz

│   └── zlib-1.2.8.tar.gz

├── handlers

│   └── main.yml

├── tasks

│   └── main.yml

└── templates

└── nginx.conf.j2

4 directories, 8 files

[[email protected] nginx]#

[[email protected] tasks]# pwd

/etc/ansible/roles/zabbix/roles/nginx/tasks

[[email protected] tasks]# cat main.yml

---

- name: useradd www

user: name=www shell=/sbin/nologin createhome=no

- name: openssl-1.0.2f.tar.gz package

unarchive: src={{ nginx_path }}openssl-1.0.2f.tar.gz dest={{ dest_path }} copy=yes

- name: pcre-8.38.tar.gz package

unarchive: src={{ nginx_path }}pcre-8.38.tar.gz dest={{ dest_path }} copy=yes

- name: zlib-1.2.8.tar.gz

unarchive: src={{ nginx_path }}zlib-1.2.8.tar.gz dest={{ dest_path }} copy=yes

- name: nginx-1.10.2.tar.gz package

unarchive: src={{ nginx_path }}nginx-1.10.2.tar.gz dest={{ dest_path }} copy=yes

- name: nginx config

shell: cd {{ dest_path }}nginx-1.10.2;./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-ipv6 --with-pcre={{ dest_path }}pcre-8.38 --with-zlib={{ dest_path }}zlib-1.2.8 --with-openssl={{ dest_path }}openssl-1.0.2f

- name: nginx make and install

shell: cd {{ dest_path }}nginx-1.10.2;make;make install

- name: create cache nginx

file: path=/var/cache/nginx state=directory owner=root group=root mode=0644

- name: copy config file

template: src=nginx.conf.j2 dest=/usr/local/nginx/nginx.conf owner=root group=root mode=0644

- name: add nginx grant

shell: cd /usr/local/nginx/;chown -R www:www *

- name: copy start file

copy: src=nginx dest=/etc/init.d/ owner=root group=root mode=0755 backup=yes

notify:

- start nginx service

tags: nginx

[[email protected] handlers]# pwd

/etc/ansible/roles/zabbix/roles/nginx/handlers

[[email protected] handlers]# cat main.yml

---

- name: start nginx service

service: name=nginx state=restarted enabled=yes

[[email protected] templates]# pwd

/etc/ansible/roles/zabbix/roles/nginx/templates

[[email protected] templates]# cat nginx.conf.j2

user www;

worker_processes {{ ansible_processor_cores }};

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server {

listen       80;

server_name  localhost;

location / {

root   html;

index  index.php index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

location ~ \.php$ {

root           html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include        fastcgi_params;

}

}

}

MySQL部署

[[email protected] mysql]# pwd

/etc/ansible/roles/zabbix/roles/mysql

[[email protected] mysql]# tree

.

├── files

│   ├── cmake-2.8.10.2.tar.gz

│   └── mysql-5.6.24.tar.gz

├── handlers

│   └── main.yml

└── tasks

└── main.yml

3 directories, 4 files

[[email protected] mysql]# cat tasks/main.yml

---

# tasks file for mysql

- name: mysql-5.6.24.tar.gz package

unarchive: src={{ mysql_path }}mysql-5.6.24.tar.gz dest={{ dest_path }} copy=yes

- name: cmake-2.8.10.2.tar.gz package

unarchive: src={{ mysql_path }}cmake-2.8.10.2.tar.gz dest={{ dest_path }} copy=yes

- name: install camke

shell: cd {{ dest_path }}cmake-2.8.10.2;./bootstrap --prefix=/usr/local/cmake;make;make install

- name: add user

shell: id mysql || useradd -M -s /sbin/nologin mysql

- name: add quanxian

file: path=/tmp mode=777

- name: bianyi

shell: cd {{ dest_path }}mysql-5.6.24;/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld.sock -DMYSQL_USER=mysql -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0

- name: make and make install

shell: cd {{ dest_path }}mysql-5.6.24;make;make install

- name: shou quna

shell: chown -R mysql:mysql /usr/local/mysql

- name: line

shell: ln -s /usr/local/mysql/bin/{{ item }} /usr/sbin/

with_items:

- innochecksum

- msql2mysql

- myisamchk

- myisam_ftdump

- myisamlog

- myisampack

- my_print_defaults

- mysql

- mysqlaccess

- mysqlaccess.conf

- mysqladmin

- mysqlbinlog

- mysqlbug

- mysqlcheck

- mysql_client_test

- mysql_client_test_embedded

- mysql_config

- mysql_config_editor

- mysql_convert_table_format

- mysqld

- mysqld_multi

- mysqld_safe

- mysqldump

- mysqldumpslow

- mysql_embedded

- mysql_find_rows

- mysql_fix_extensions

- mysqlhotcopy

- mysqlimport

- mysql_plugin

- mysql_secure_installation

- mysql_setpermission

- mysqlshow

- mysqlslap

- mysqltest

- mysqltest_embedded

- mysql_tzinfo_to_sql

- mysql_upgrade

- mysql_waitpid

- mysql_zap

- perror

- replace

- resolveip

- resolve_stack_dump

tags:

- link

- name: copy mysql start script

shell: cp {{ dest_path }}mysql-5.6.24/support-files/mysql.server /etc/init.d/mysqld

- name: insert ld.so.conf

lineinfile: dest=/etc/ld.so.conf line=/usr/local/mysql/lib/

- name: ldconfig

shell: ldconfig

- name: chu shi hua

shell: /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

- name: copy my.cnf

shell: rm -rf /etc/my.cnf;mv /usr/local/mysql/my.cnf /etc/

- name: add max_connections

lineinfile: dest=/etc/my.cnf line="max_connections = 1000"

#- name: insert /var/lib/mysql/mysql.sock

#  lineinfile:  dest=/etc/my.cnf line="socket = /var/lib/mysql/mysql.sock"

#  tags:

#    - socket

- name: start mysql service

service: name=mysqld state=restarted enabled=yes

tags:

- mysqlstart

- name: set mysql passwd

shell: /usr/local/mysql/bin/mysqladmin -u root password ‘mysql_dbpass‘

tags:

- mysqlpasswd

[[email protected] mysql]# cat handlers/main.yml

---

# handlers file for mysql

- name: start mysql service

service: name=mysqld state=restarted enabled=yes

- name: set mysql passwd

shell: /usr/local/mysql/bin/mysqladmin -u root password ‘mysql_dbpass‘

PHP部署

[[email protected] php]# pwd

/etc/ansible/roles/zabbix/roles/php

[[email protected] php]# tree

.

├── files

│   ├── index.php

│   ├── libiconv-1.13.1.tar.gz

│   ├── libmcrypt-2.5.8.tar.gz

│   ├── Makefile

│   ├── mhash-0.9.9.9.tar.gz

│   ├── php-5.6.29.tar.gz

│   ├── php-fpm

│   ├── php-fpm.conf

│   ├── php.ini

│   └── testdb.php

├── handlers

│   └── main.yml

└── tasks

└── main.yml

3 directories, 12 files

[[email protected] php]# cat tasks/main.yml

---

# tasks file for php

- name: mhash-0.9.9.9.tar.gz

unarchive: src={{ php_path }}mhash-0.9.9.9.tar.gz dest={{ dest_path }} copy=yes

- name: libiconv-1.13.1.tar.gz

unarchive: src={{ php_path }}libiconv-1.13.1.tar.gz dest={{ dest_path }} copy=yes

- name: libmcrypt-2.5.8.tar.gz

unarchive: src={{ php_path }}libmcrypt-2.5.8.tar.gz dest={{ dest_path }} copy=yes

- name: php-5.6.29.tar.gz

unarchive: src={{ php_path }}php-5.6.29.tar.gz dest={{ dest_path }} copy=yes

- name: config mhash

shell: cd {{ dest_path }}mhash-0.9.9.9;./configure;make;make install

- name: config libiconv

shell: cd {{ dest_path }}libiconv-1.13.1;./configure;make;make install

- name: config libmcrypt

shell: cd {{ dest_path }}libmcrypt-2.5.8;./configure;make;make install

- name: config libmcrypt-2.5.8/libltdl

shell: cd {{ dest_path }}libmcrypt-2.5.8/libltdl/;./configure --with-gmetad --enable-gexec --enable-ltdl-install

- name: libmcrypt make and make install

shell: cd {{ dest_path }}libmcrypt-2.5.8/libltdl/;make;make install

- name: line libmcrypt*

file: src=/usr/local/lib/{{ item.src }} dest=/usr/lib/{{ item.dest }} state=link

with_items:

- { src: ‘libmcrypt.so.4.4.8‘, dest: ‘libmcrypt.so.4.4.8‘ }

- { src: ‘libmcrypt.so.4‘, dest: ‘libmcrypt.so.4‘ }

- { src: ‘libmcrypt.so‘, dest: ‘libmcrypt.so‘ }

- { src: ‘libmcrypt.la‘, dest: ‘libmcrypt.la‘ }

- { src: ‘libmcrypt‘, dest: ‘libmcrypt‘ }

- { src: ‘libmhash.a‘, dest: ‘libmhash.a‘ }

- { src: ‘libmhash.la‘, dest: ‘libmhash.la‘ }

- { src: ‘libmhash.so‘, dest: ‘libmhash.so‘ }

- { src: ‘libmhash.so.2‘, dest: ‘libmhash.so.2‘ }

- { src: ‘libmhash.so.2.0.1‘, dest: ‘libmhash.so.2.0.1‘ }

- name: ldconfig

shell: ldconfig

- name: cp libladp*

file: src=/usr/lib64/{{ item.src }} dest=/usr/lib/{{ item.dest }} state=link

with_items:

- { src: ‘libldap-2.4.so.2‘, dest: ‘libldap-2.4.so.2‘ }

- { src: ‘libldap_r-2.4.so.2‘, dest: ‘libldap_r-2.4.so.2‘ }

- { src: ‘libldap_r.so‘, dest: ‘libldap_r.so‘ }

- { src: ‘libldap.so‘, dest: ‘libldap.so‘ }

- name: config php

shell: cd {{ dest_path }}php-5.6.29;./configure  --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-freetype-dir --with-gettext --with-fpm-user=www --with-fpm-group=www

- name: copy Makefile

copy: src=Makefile dest={{ dest_path }}php-5.6.29 owner=root group=root mode=0644 backup=yes

#- name: config Makefile

#  shell: sed -i ‘s#EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmysqlclient -lmcrypt -lltdl -lldap -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -lcurl -lxml2 -lz -lm -lfreetype -lmysqlclient -lm -lrt -lssl -lcrypto -ldl -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmysqlclient -lmcrypt -lltdl -lldap -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -lcurl -lxml2 -lz -lm -lfreetype -lmysqlclient -lm -lrt -lssl -lcrypto -ldl -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -liconv#g‘ {{ dest_path }}php-5.6.29/Makefile

- name: make ZEND_EXTRA_LIBS=‘-liconv‘

shell: cd {{ dest_path }}php-5.6.29;make ZEND_EXTRA_LIBS=‘-liconv‘

- name: make install

shell: cd {{ dest_path }}php-5.6.29;make install

- name: copy file php.ini

copy: src=php.ini dest=/usr/local/php/etc/ owner=root group=root mode=0644 backup=yes

- name: copy file php-fpm.conf

copy: src=php-fpm.conf dest=/usr/local/php/etc/ owner=root group=root mode=0644 backup=yes

- name: copy php-fpm

copy: src=php-fpm dest=/etc/init.d/ owner=root group=root mode=0755 backup=yes

- name: copy file index.php testdb.php

copy: src={{ item }} dest=/usr/local/nginx/html/ owner=root group=root mode=0644 backup=yes

with_items:

- index.php

- testdb.php

notify:

- start php

[[email protected] php]# cat handlers/main.yml

---

# handlers file for php

- name: start php

service: name=php-fpm state=restarted enabled=yes

Zabbix部署

[[email protected] zabbix_server]# pwd

/etc/ansible/roles/zabbix/roles/zabbix_server

[[email protected] zabbix_server]# ls

handlers  tasks  templates

[[email protected] zabbix_server]# tree

├── files

│   ├── zabbix

│   ├── zabbix-3.0.4.tar.gz

│   ├── zabbix_agentd

│   ├── zabbix_server

│   └── zabbix_server.conf

├── handlers

│   └── main.yml

├── tasks

│   └── main.yml

└── templates

└── zabbix_agentd.conf.j2

[[email protected] zabbix_server]# cat tasks/main.yml

---

# tasks file for zabbix_server

- name: add usergroup

group: name=zabbix gid=201 system=yes

tags:

- zabbix_1

- name: add user

user: name=zabbix uid=201 group=zabbix

tags:

- zabbix_2

- name: unarchive zabbix-3.0.4.tar.gz

unarchive: src={{ zabbix_server_path }}zabbix-3.0.4.tar.gz dest={{ dest_path }} copy=yes

tags:

- zabbix_3

- name: config and make install

shell: cd {{ dest_path }}zabbix-3.0.4;./configure --prefix=/usr/local/zabbix --enable-java --enable-server --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2;make install

tags:

- zabbix_4

- name: add zabbix to services

lineinfile: dest=/etc/services line={{ item }}

with_items:

- "zabbix-agent    10050/tcp               #Zabbix Agent"

- "zabbix-agent    10050/udp               #Zabbix Agent"

- "zabbix-server   10051/tcp               #zabbix Trapper"

- "zabbix-server   10051/udp               #zabbix Trapper"

tags:

- zabbix_4_1

- name: create database user

shell: mysql -uroot -pmysql_dbpass -e "create database zabbix default character set utf8;"

tags:

- zabbix_5

- name: databases shou quan

shell: mysql -uroot -pmysql_dbpass -e "grant all on zabbix.* to ‘zabbix‘@‘localhost‘ identified by ‘zabbix‘;"

tags:

- zabbix_6

- name: flush privileges

shell: mysql -uroot -pmysql_dbpass -e "flush privileges;"

tags:

- zabbix_7

- name: import databases

shell: cd {{dest_path }}zabbix-3.0.4/database/mysql;mysql -uzabbix -pzabbix zabbix < schema.sql;mysql -uzabbix -pzabbix zabbix < images.sql;mysql -uzabbix -pzabbix zabbix < data.sql

tags:

- zabbix_8

- name: create zabbix log directory

file: path=/data/logs/zabbix/ state=directory owner=zabbix group=zabbix

tags:

- zabbix_9

- name: create /etc/ zabbix directory

file: path=/etc/zabbix/ state=directory

tags:

- zabbix_10

- name: create /usr/local/zabbix/etc link

file: src=/usr/local/zabbix/etc/{{ item.src }} dest=/etc/zabbix/{{ item.dest }} state=link

with_items:

- { src: ‘zabbix_agentd.conf‘, dest: ‘zabbix_agentd.conf‘ }

- { src: ‘zabbix_proxy.conf‘, dest: ‘zabbix_proxy.conf‘ }

- { src: ‘zabbix_server.conf‘, dest: ‘zabbix_server.conf‘ }

- { src: ‘zabbix_agentd.conf.d‘, dest: ‘zabbix_agentd.conf.d‘ }

- { src: ‘zabbix_proxy.conf.d‘, dest: ‘zabbix_proxy.conf.d‘ }

- { src: ‘zabbix_server.conf.d‘, dest: ‘zabbix_server.conf.d‘ }

tags:

- zabbix_11

- name: create /usr/local/zabbix/bin link

file: src=/usr/local/zabbix/bin/{{ item.src }} dest=/etc/zabbix/{{ item.dest }} state=link

with_items:

- { src: ‘zabbix_get‘, dest: ‘zabbix_get‘ }

- { src: ‘zabbix_sender‘, dest: ‘zabbix_sender‘ }

tags:

- zabbix_12

- name: create /usr/local/zabbix/sbin link

file: src=/usr/local/zabbix/sbin/{{ item.src }} dest=/usr/sbin/{{ item.dest }} state=link

with_items:

- { src: ‘zabbix_agentd‘, dest: ‘zabbix_agentd‘ }

- { src: ‘zabbix_java‘, dest: ‘zabbix_java‘ }

- { src: ‘zabbix_proxy‘, dest: ‘zabbix_proxy‘ }

- { src: ‘zabbix_server‘, dest: ‘zabbix_server‘ }

tags:

- zabbix_13

- name: copy zabbix start stop script

copy: src={{ item }} dest=/etc/init.d owner=root group=root mode=0755 backup=yes

with_items:

- zabbix_server

- zabbix_agentd

tags:

- zabbix_14

- name: copy zabbix_server.conf

#file: src={{ item }} dest=/usr/local/zabbix/etc/ owner=root group=root mode=0644 backup=yes

synchronize: src={{ item }} dest=/usr/local/zabbix/etc/  mode=push

with_items:

- zabbix_server.conf

tags:

- zabbix_15

- name: copy zabbix_agentd.conf

template: src=zabbix_agentd.conf.j2 dest=/usr/local/zabbix/etc/zabbix_agentd.conf owner=root group=root mode=0644

tags:

- zabbix_16

- name: copy zabbix wangzhan directory

synchronize: src=zabbix dest=/usr/local/nginx/html/ mode=push

tags:

- zabbix_17

#- name: change user

#  file: dest=/usr/local/nginx/html/zabbix owner=www group=www backup=yes

- name: add /usr/local/lib

lineinfile: dest=/etc/ld.so.conf line=/usr/local/lib

tags:

- zabbix_19

#- name: add max_connections

#  lineinfile: dest=/etc/my.cnf line="max_connections = 1000"

- name: ldconfig

shell: ldconfig;

tags:

- zabbix_20

notify:

- start zabbix_server

- start zabbix_agentd

- stop iptables

- stop selinux

[[email protected] zabbix_server]# cat handlers/main.yml

---

# handlers file for zabbix_server

- name: start zabbix_server

service: name=zabbix_server state=restarted enabled=yes

- name: start zabbix_agentd

service: name=zabbix_agentd state=restarted enabled=yes

- name: stop iptables

service: name=iptables state=stopped enabled=no

- name: stop selinux

shell: setenforce 0

[[email protected] zabbix_server]# cat templates/zabbix_agentd.conf.j2

EnableRemoteCommands=1

UnsafeUserParameters=1

Server=127.0.0.1,{{ ansible_eth0.ipv4.address }}

ServerActive={{ ansible_eth0.ipv4.address }}:10051

Hostname={{ ansible_hostname }}

LogFile=/data/logs/zabbix/zabbix_agentd.log

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

执行Yaml主文件

[[email protected] zabbix]# ls

group_vars  roles  zabbix.retry  zabbix.yaml

[[email protected] zabbix]# pwd

/etc/ansible/roles/zabbix

[[email protected] zabbix]# ansible-playbook zabbix.yaml

时间: 2024-08-08 14:20:53

Ansible部署Zabbix监控工具的相关文章

ansible 部署 zabbix客户端 脚本

[[email protected] ~]# tree ansible ansible ├── get-pip.py ├── hosts ├── roles │   └── zabbix │       ├── default │       ├── files │       │   ├── tcp_status.conf │       │   ├── tcp_status.log │       │   └── tcp_status.sh │       ├── handlers │   

ansible自动化部署zabbix客户端

本文主要介绍使用ansible playbook中roles,在不同os版本下批量部署zabbix客户端. 一.facts介绍 playbook的部分fetch信息 ansible版本2.2.1.0 使用setup模块获取 # ansible 192.168.1.12 -m setup "ansible_distribution": "CentOS",  "ansible_distribution_major_version": "6&

通过PlayBook部署Zabbix(6)

title: 通过PlayBook部署Zabbix(6) date: 2018-12-03 19:33:24 tags: Ansible categories: Ansible copyright: true --- Ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能,ansible是基于模块工作的,本身没有批量部署的能力,真正具有批量部署

使用saltstack集中部署zabbix服务

需求描述:使用saltstack在机器上部署zabbix服务. 思路:通过state sls实现. 安装zabbix的策略目录: 第一部分sls文件: 上面的策略是安装策略,目的是将安装包下载到minion,然后解压到安装目录. 第二部分是配置修改策略,修改后重启agentd服务. 模版配置文件一段信息,这个信息会被sls文件里的server变量替换掉 同步策略 salt '*' state.sls zabbix.config prod 这个会执行策略并安装zabbix. 是不是很简单啊 使用s

部署zabbix监控mysql (一) 安装zabbix

部署zabbix监控mysql (1)安装LAMP环境 [[email protected] ~]# yum -y installmysql-server http php (2)安装zabbix web所需要的依赖包 [[email protected] ~]# yum -y installmysql-dev gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmathphp-mbstring php-xml 安装Fpin

使用Ansible部署LAMP环境

使用Ansible部署LAMP环境 前言 Ansible在部署实验环境真的很好用,今天向大家分享如何使用Ansible部署LAMP环境. 实验环境 今天实验环境比较简单, 所以就不画图了 主机 IP地址 功用 server1.anyisalin.com 172.16.1.2 控制主机 web.anyisalin.com 172.16.1.3 httpd和php data.anyisalin.com 172.16.1.4 MySQL 实验步骤 配置ssh公钥认证 ansible是agentless

ansible 部署ssh 偶尔巨慢的解决方法

ansible 部署ssh 偶尔巨慢,以前没留意,今天实在登录不上了,于是专门来解决下. ssh [email protected] -vvvv debug 调试: 修改 /etc/ssh/ssh_config 配置参数,不是/etc/ssh/sshd_config !!!修改本机的客户端配置文件ssh_conf,注意,不是sshd_conf 前后效果对比图: 知识补充: GSSAPI ( Generic Security Services Application Programming Int

ansible部署tomcat8

其实大部分是参考别人的博文做的,自己做了修改 准备 tomcat.tar.gz 经过优化后的 参考 http://vekergu.blog.51cto.com/9966832/1672931进行优化 apr模式开启 tomcat都使用root默认目录 文件 tomcat.sh server.xml 建立一些目录,并赋予权限 /opt/src/logs 启动 sh /opt/ea/tomcat.sh cat tomcat.sh #!/bin/bash JAVA_OPTS="-Xms2048m -X

部署zabbix环境的搭建

部署zabbix环境的搭建 配置LAMP环境(因为之前已经搭建过了lnmp所以这里就不一一演示了) 也可以yum源安装: [[email protected] ~]#yum install make mysql-server httpd php mysql-devel gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml unixODBC-devel OpenIPMI-dev