1.配置zabbix源
cat >/etc/yum.repos.d/zabbix.repo<<EOF [zabbix] name=Zabbix Official Repository - \$basearch baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/ enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX [zabbix-non-supported] name=Zabbix Official Repository non-supported - \$basearch baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/\$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=0 EOF
2.安装zabbix相关服务
yum install zabbix-server-mysql zabbix-web-mysql zabbix-get mariadb-server zabbix-java-gateway.x86_64 java-1.8.0 -y rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.36-1.el7.x86_64.rpm
3.初始化数据库
systemctl start mariadb systemctl enable mariadb mysql_secure_installation 回车 n y y y y mysql >:create database zabbix character set utf8 collate utf8_bin; >:grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; 导入zabbix表结构和初始数据 zcat /usr/share/doc/zabbix-server-mysql-4.0.*/create.sql.gz | mysql -uzabbix -p zabbix
4.启动服务
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix (数据库密码)
systemctl start zabbix-server
systemctl enable zabbix-server
systemctl start zabbix-agent && systemctl enable zabbix-agent
ps -ef | grep zabbix
vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
systemctl start httpd
systemctl enable httpd
http://10.0.0.71/zabbix
=====================================================================
《利用剧本批量部署客户端》
使用命令生成密钥
[root@ansible ~]# ssh-keygen
将公钥发送到所有安装zabbix客户端的主机
[root@ansible ~]# ssh-copy-id 10.0.0.7
[root@ansible ~]# ssh-copy-id 10.0.0.51
安装 ansible 软件
vim
[ansible]
name=ansible
baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/7/x86_64/
gpgcheck=0
[root@ansible ~]# yum install -y epel-release
[root@ansible ~]# yum install -y ansible
修改配置文件,将zabbix 客户机添加进组,(在文末添加即可)
[root@ansible ~]# vim /etc/ansible/hosts
[webservers]
10.0.0.7
10.0.0.51
执行剧本
ansible-playbook -e server_ip=10.0.0.72 install_zabbix.yaml
(1) 检测语法
ansible-playbook --syntax-check /path/to/playbook.yaml
(2) 测试运行
ansible-playbook -C /path/to/playbook.yaml
(3)运行
ansible-playbook /path/to/playbook.yaml
剧本内容:
- hosts: webservers
remote_user: root
tasks:
- name: rpm
shell: rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.36-1.el7.x86_64.rpm
- name: zabbix_agentd.conf
shell: sed -i 's/Server=127.0.0.1/Server=10.0.0.72/g' /etc/zabbix/zabbix_agentd.conf
- name: start
shell: systemctl start zabbix-agent && systemctl enable zabbix-agent