zabbix 應用監控做業筆記mysql
# 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.yalnginx
- 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
- 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
- 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
- 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
- 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
- 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/web
連接: https://pan.baidu.com/s/1qOQVASOq4kVXvbpjum7a5A 提取碼: ygvnsql