main.yml文件
- name: "下载数据包"
get_url:
url: "https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb"
dest: "/root"
- name : "安装下载包"
shell: "dpkg -i zabbix-release_5.0-1+focal_all.deb"
- name: "修改源"
replace:
path: "/etc/apt/sources.list.d/zabbix.list"
regexp: "http://repo.zabbix.com"
replace: "https://mirror.tuna.tsinghua.edu.cn/zabbix"
- name: update
shell:
cmd: apt update
- name: install packages
apt:
name: "zabbix-server-mysql,zabbix-frontend-php,zabbix-nginx-conf,zabbix-agent2,mysql-server"
- name: "创建mysql用户"
script:
cmd: /opt/mysql.sh
- name: "导入mysql数据"
shell: zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123456 zabbix
- name: "修改nginx配置文件"
template:
src: nginx.conf.j2
dest: /etc/zabbix/nginx.conf
- name: "修改zabbix配置文件"
template:
src: zabbix_server.conf.j2
dest: /etc/zabbix/zabbix_server.conf
- name: "修改php配置文件"
template:
src: php-fpm.conf.j2
dest: /etc/zabbix/php-fpm.conf
- name: restart apache2
shell: systemctl disable --now apache2
- name: restart server
shell: systemctl restart zabbix-server zabbix-agent2 nginx php7.4-fpm
- name: restart zabbix
shell: systemctl enable zabbix-server
中间引用的mysql.sh脚本
cat << EOF | mysqlcreate database zabbix character set utf8 collate utf8_bin; create user zabbix@localhost identified by '123456'; grant all privileges on zabbix.* to zabbix@localhost;EOF