zabbix 应用监控作业笔记
- 2台web(Nginx+PHP)、1台MySQL、1台NFS、1台Rsync(所有的.conf监控项一样,模板不一样)
1.自定义监控项、自定义触发器、自定义动作
2.如何制作模板,模板的导出与导入
#####
使用Ansible统一
安装Zabbix-Agent
配置Zabbix-Agent
推送所有的脚本
推送所有的.conf文件
# ansible 批量管理
1.创建密钥对
[root@m01 ~]# ssh-keygen -t rsa -C xuliangwei.com #一路回车即可
[root@m01 ~]# ls ~/.ssh/
id_rsa(钥匙) id_rsa.pub(锁头)
2#发送密钥给需要登录的用户
[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.71
配置ansible 主机清单
[root@m01 ansible-playbook]# cat /etc/ansible/hosts
[lb]
172.16.1.5
172.16.1.6
[web]
172.16.1.7
172.16.1.8
[sweb]
172.16.1.9
[nfs]
172.16.1.31
[backup]
172.16.1.41
[db]
172.16.1.51
[zabbix]
172.16.1.71
目录结构
[root@m01 ansible-playbook]# tree
.
├── conf
│ ├── conf.zip
│ ├── php-status.conf
│ ├── ss_get_mysql_stats.php
│ ├── status.conf
│ ├── www.conf
│ ├── zabbix_agentd.conf
│ ├── zabbix.conf
│ └── zabbix_server.conf
├── mail.retry
├── mail.yaml
├── scripts
│ └── mysql.sh
├── zabbix-backup.yaml
├── zabbix-mysql.yaml
├── zabbix-nfs.yaml
├── zabbix-server.retry
├── zabbix-server.yaml
└── zabbix-web.yaml
2 directories, 17 files
mail.yal
- import_playbook: zabbix-web.yaml
- import_playbook: zabbix-backup.yaml
- import_playbook: zabbix-nfs.yaml
- import_playbook: zabbix-mysql.yaml
- import_playbook: zabbix-server.yaml
zabbix-web.yaml
- hosts: web
tasks:
- name: Yum zabbix-agent
yum: name=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.12-1.el7.x86_64.rpm state=present
- name: configure zabbix-agent
copy: src=./conf/zabbix_agentd.conf dest=/etc/zabbix/zabbix_agentd.conf
- name: Start zabbix-agent
service: name=zabbix-agent state=started enabled=yes
- name: Copy nginx conf
copy: src=./conf/status.conf dest=/etc/nginx/conf.d/status.conf
- name: Restart nginx
service: name=nginx state=restarted
# - name: Mkdir directory
# file: path=/etc/zabbix/zabbix_agentd.d/scripts state=directory mode=755
#
# - name: copy nginx_status.sh
# copy: src=./scripts/nginx_status.sh dest=/etc/zabbix/zabbix_agentd.d/scripts/nginx_status.sh
#
# - name: chmod 755
# shell: chmod 755 /etc/zabbix/zabbix_agentd.d/scripts/nginx_status.sh
- name: cpoy conf.zip
unarchive: src=conf/conf.zip dest=/etc/zabbix/zabbix_agentd.d/ creates=/etc/zabbix/zabbix_agentd.d/io.conf
# unarchive: src=./conf/conf.zip dest=/etc/zabbix/zabbix_agentd.d/
- name: Restart zabbix-agent
service: name=zabbix-agent state=restarted
- name: php-fpm/www.conf
copy: src=./conf/www.conf dest=/etc/php-fpm.d/www.conf
- name: php-status.conf
copy: src=./conf/php-status.conf dest=/etc/nginx/conf.d/
- name: Restart php-fpm
service: name=php-fpm state=restarted
- name: Restart zabbix-agent
service: name=zabbix-agent state=restarted
zabbix-backup.yaml
- hosts: backup
tasks:
- name: Install zabbix-agent
yum: name=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.12-1.el7.x86_64.rpm state=present
- name: configure zabbix-agent
copy: src=./conf/zabbix_agentd.conf dest=/etc/zabbix/zabbix_agentd.conf
- name: cpoy conf.zip
unarchive: src=conf/conf.zip dest=/etc/zabbix/zabbix_agentd.d/ creates=/etc/zabbix/zabbix_agentd.d/io.conf
- name: Start zabbix-agent
service: name=zabbix-agent state=started enabled=yes
zabbix-nfs.yaml
- hosts: nfs
tasks:
- name: Yum zabbix-agent
yum: name=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.12-1.el7.x86_64.rpm state=present
- name: configure zabbix-agent
copy: src=./conf/zabbix_agentd.conf dest=/etc/zabbix/zabbix_agentd.conf
- name: cpoy conf.zip
unarchive: src=conf/conf.zip dest=/etc/zabbix/zabbix_agentd.d/ creates=/etc/zabbix/zabbix_agentd.d/io.conf
- name: Start zabbix-agent
service: name=zabbix-agent state=started enabled=yes
zabbix-mysql.yaml
- hosts: db
tasks:
- name: Yum zabbix-agent
yum: name=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.12-1.el7.x86_64.rpm state=present
- name: configure zabbix-agent
copy: src=./conf/zabbix_agentd.conf dest=/etc/zabbix/zabbix_agentd.conf
- name: Start zabbix-agent
service: name=zabbix-agent state=started enabled=yes
- name: Yum php php-mysql
yum: name=php,php-mysql state=installed
- name: Yum percona
yum: name=https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm state=present
- name: copy percona configurl
copy: src=./conf/ss_get_mysql_stats.php dest=/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
- name: cpoy conf.zip
unarchive: src=conf/conf.zip dest=/etc/zabbix/zabbix_agentd.d/ creates=/etc/zabbix/zabbix_agentd.d/io.conf
- name: Restart zabbix-agent
service: name=zabbix-agent state=started
- name: ReStart zabbix-agent
service: name=zabbix-agent state=started
zabbix-server.yaml
- hosts: zabbix
tasks:
- name: Yum zabbixsrc
yum: name=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm state=present
- name: Yum zabbix
yum: name=zabbix-server-mysql,zabbix-web-mysql,zabbix-agent,mariadb-server state=installed
- name: start mariadb
service: name=mariadb state=started enabled=yes
- name: all in one mysql.sh
script: ./scripts/mysql.sh
args:
creates: /tmp/file.txt
- name: copy zabbix_server.conf
copy: src=./conf/zabbix_server.conf dest=/etc/zabbix/zabbix_server.conf
- name: copy httpd/zabbix.conf
copy: src=./conf/zabbix.conf dest=/etc/httpd/conf.d/zabbix.conf
- name: Start zabbix-server
service: name=zabbix-server state=started enabled=yes
- name: Start httpd
service: name=httpd state=started enabled=yes
- name: Start mariadb
service: name=mariadb state=started enabled=yes
浏览器访问 http://10.0.0.71/zabbix/
链接: https://pan.baidu.com/s/1qOQVASOq4kVXvbpjum7a5A 提取码: ygvn