网站改版要注意什么,中建集团,wordpress 数字格式,下载58同城网招聘找工作文章目录 Ansible单yaml文件部署Zabbix5.0监控平台节点规划案例实施基础环境准备编写剧本文件ZabbixWeb界面(1)改中文(2)添加监控主机 Ansible单yaml文件部署Zabbix5.0监控平台
节点规划
IP主机名节点192.168.200.10ansibleAnsible节点192.168.200.20zabbix-serverZabbix-ser… 文章目录 Ansible单yaml文件部署Zabbix5.0监控平台节点规划案例实施基础环境准备编写剧本文件ZabbixWeb界面(1)改中文(2)添加监控主机 Ansible单yaml文件部署Zabbix5.0监控平台
节点规划
IP主机名节点192.168.200.10ansibleAnsible节点192.168.200.20zabbix-serverZabbix-server节点192.168.200.30zabbix-agentAgent 节点
使用Ansible部署一个zabbix监控平台并监控192.168.200.30主机
案例实施
基础环境准备
(1)修改主机名
[rootlocalhost ~]# hostnamectl set-hostname ansible
[rootlocalhost ~]# hostnamectl set-hostname zabbix-server
[rootlocalhost ~]# hostnamectl set-hostname zabbix-agent(2)安装ansible
[rootansible ~]# yum install -y epel-release
[rootansible ~]# yum install -y ansible(3)配置Ansible节点和远程主机的连接
[rootansible ~]# ssh-keygen
[rootzabbix-server ~]# ssh-keygen
[rootzabbix-agent ~]# ssh-keygen
[rootansible ~]# ssh-copy-id 192.168.200.20
[rootansible ~]# ssh-copy-id 192.168.200.30(4)配置主机组
[rootansible ~]# vim /etc/ansible/hosts
[yum]
192.168.200.20
192.168.200.30
[zabbix]
192.168.200.20
[agent]
192.168.200.30(5)测试连通性
[rootansible ~]# ansible zabbix -m ping
192.168.200.30 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}
192.168.200.20 | SUCCESS {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}编写剧本文件
[rootansible ~]# vim install_zabbix.yaml
- hosts: yumremote_user: roottasks:- name: stop firewalld setenforce 0shell: systemctl stop firewalld systemctl disable firewalld setenforce 0- name: download zabbix-repoyum: name: https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpmstate: installed- name: modify zabbix-reposhell: sed -i s#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix# /etc/yum.repos.d/zabbix.repo- name: enable zabbix-frontendshell: sed -i 11s/enabled0/enabled1/g /etc/yum.repos.d/zabbix.repo- name: install cangkuyum: name:- centos-release-scl- epel-release state: installed- hosts: zabbixremote_user: roottasks:- name: install zabbixyum: name: - zabbix-server-mysql- zabbix-agent- zabbix-web-mysql-scl- zabbix-apache-conf-sclstate: installed- name: install mariadbyum: namemariadb-server stateinstalled- name: start enable mariadbservice: namemariadb.service enabledyes statestarted- name: mariadb passwordshell: mysqladmin -uroot password 000000- name: create zabbix databaseshell: mysql -uroot -p000000 -e create database zabbix character set utf8 collate utf8_bin;- name: create zabbix usershell: mysql -uroot -p000000 -e create user zabbixlocalhost identified by 000000;- name: shouquanshell: mysql -uroot -p000000 -e grant all privileges on zabbix.* to zabbixlocalhost; - name: import db informationshell: zcat /usr/share/doc/zabbix-server-mysql-5.0.36/create.sql.gz | mysql -u zabbix -p000000 zabbix- name: DBPasswordlineinfile: path: /etc/zabbix/zabbix_server.confregexp: DBPasswordline: DBPassword000000- name: modify time zonelineinfile:path: /etc/opt/rh/rh-php72/php-fpm.d/zabbix.confregexp: ^;php_value[date.timezone]line: php_value[date.timezone] Asia/Shanghai- name: restart zabbix-servershell: systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm- name: luanma install zitiyum: namewqy-microhei-fonts stateinstalled- name: copy zitishell: cp -rf /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf- hosts: agentremote_user: roottasks:- name: install zabbix-agentyum: namezabbix-agent stateinstalled- name: modify zabbix-agent.config 被动监控lineinfile:path: /etc/zabbix/zabbix_agentd.confregexp: ^Server127.0.0.1line: Server192.168.200.20- name: modify zabbix-agent.conf 主动监控lineinfile:path: /etc/zabbix/zabbix_agentd.confregexp: ^ServerActive127.0.0.1line: ServerActive192.168.200.20- name: modify zabbix-agent.conf 被监控的主机名lineinfile:path: /etc/zabbix/zabbix_agentd.confregexp: ^HostnameZabbix serverline: Hostnamezabbix-agent- name: restart zabbix-agent enableservice: namezabbix-agent staterestarted enabledyes执行剧本
[rootansible ~]# ansible-playbook install_zabbix.yaml PLAY [yum] ***********************************************************************************************************************************************TASK [Gathering Facts] ***********************************************************************************************************************************
ok: [192.168.200.20]
ok: [192.168.200.30]TASK [stop firewalld setenforce 0] ***********************************************************************************************************************
changed: [192.168.200.20]
changed: [192.168.200.30]TASK [download zabbix-repo] ******************************************************************************************************************************
changed: [192.168.200.20]
changed: [192.168.200.30]TASK [modify zabbix-repo] ********************************************************************************************************************************
[WARNING]: Consider using the replace, lineinfile or template module rather than running sed. If you need to use command because replace, lineinfile
or template is insufficient you can add warn: false to this command task or set command_warningsFalse in ansible.cfg to get rid of this message.
changed: [192.168.200.20]
changed: [192.168.200.30]TASK [enable zabbix-frontend] ****************************************************************************************************************************
changed: [192.168.200.20]
changed: [192.168.200.30]TASK [install cangku] ************************************************************************************************************************************
changed: [192.168.200.20]
changed: [192.168.200.30]PLAY [zabbix] ********************************************************************************************************************************************TASK [Gathering Facts] ***********************************************************************************************************************************
ok: [192.168.200.20]TASK [install zabbix] ************************************************************************************************************************************
changed: [192.168.200.20]TASK [install mariadb] ***********************************************************************************************************************************
changed: [192.168.200.20]TASK [start enable mariadb] ******************************************************************************************************************************
changed: [192.168.200.20]TASK [mariadb password] **********************************************************************************************************************************
changed: [192.168.200.20]TASK [create zabbix database] ****************************************************************************************************************************
changed: [192.168.200.20]TASK [create zabbix user] ********************************************************************************************************************************
changed: [192.168.200.20]TASK [shouquan] ******************************************************************************************************************************************
changed: [192.168.200.20]TASK [import db information] *****************************************************************************************************************************
changed: [192.168.200.20]TASK [DBPassword] ****************************************************************************************************************************************
changed: [192.168.200.20]TASK [modify time zone] **********************************************************************************************************************************
changed: [192.168.200.20]TASK [restart zabbix-server] *****************************************************************************************************************************
changed: [192.168.200.20]TASK [luanma install ziti] *******************************************************************************************************************************
changed: [192.168.200.20]TASK [copy ziti] *****************************************************************************************************************************************
changed: [192.168.200.20]PLAY [agent] *********************************************************************************************************************************************TASK [Gathering Facts] ***********************************************************************************************************************************
ok: [192.168.200.30]TASK [install zabbix-agent] ******************************************************************************************************************************
changed: [192.168.200.30]TASK [modify zabbix-agent.config 被动监控] *******************************************************************************************************************
changed: [192.168.200.30]TASK [modify zabbix-agent.conf 主动监控] *********************************************************************************************************************
changed: [192.168.200.30]TASK [modify zabbix-agent.conf 被监控的主机名] ******************************************************************************************************************
changed: [192.168.200.30]TASK [restart zabbix-agent enable] ***********************************************************************************************************************
changed: [192.168.200.30]PLAY RECAP ***********************************************************************************************************************************************
192.168.200.20 : ok20 changed18 unreachable0 failed0 skipped0 rescued0 ignored0
192.168.200.30 : ok12 changed10 unreachable0 failed0 skipped0 rescued0 ignored0 ZabbixWeb界面
浏览器访问192.168.200.20/zabbix 点击Next step 设置完信息继续点击Next step 设置完信息继续点击Next step 继续点击Next step 安装成功点击 Finish 登录 进入登录界面使用默认的用户名和密码 Admin/zabbix 登录 zabbix界面 (1)改中文
点击user settings 如果你想的话设置中文可以改登录密码 点击左下角用户设置即可更改密码
(2)添加监控主机
点击配置→主机→创建主机 点击模板 查看日志文件
[rootzabbix-server ~]# tail -f /var/log/zabbix/zabbix_server.log 7371:20230729:003919.818 enabling Zabbix agent checks on host zabbix-agent: host became available
# 当出现了这条信息说明已经开启成功了查看监控图表