ansible
1.配置数据库
[root@zabbix-server ~]# find / -name schema.sql
[root@zabbix-server ~]# ls /usr/share/zabbix-mysql/
[root@ansible zabbix]# cat mariadb_cfg.yaml
- name: 配置数据库
hosts: server
tasks:
- name: 设置数据库登录密码
shell: mysqladmin -uroot password password
ignore_errors: yes
- name: 创建数据库
shell: mysql -uroot -ppassword -e "create database zabbix;"
ignore_errors: yes
- name: 创建用户zabbix
shell: mysql -uroot -ppassword -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'password';flush privileges;"
ignore_errors: yes
- name: 导入sql
shell: mysql -uroot -ppassword -e "use zabbix;source /usr/share/zabbix-mysql/schema.sql;source /usr/share/zabbix-mysql/images.sql; source /usr/share/zabbix-mysql/data.sql;"
ignore_errors: yes
- name: 重启mariadb
service:
name: mariadb
state: restarted
enabled: yes
[root@ansible zabbix]# ansible-playbook mariadb_cfg.yaml
2.编辑zabbix配置文件
[root@zabbix-server ~]# find / -name zabbix_server.conf
[root@ansible zabbix]# scp zabbix_server:/etc/zabbix_server.conf .
[root@ansible zabbix]# scp zabbix_server:/etc/zabbix_agentd.conf .
[root@ansible zabbix]# vim zabbix_server.conf
DBPassword=password
[root@ansible zabbix]# vim zabbix_agentd.conf
Server=192.168.100.20
ServerActive=192.168.100.20
Hostname=192.168.100.20
[root@ansible zabbix]# mv zabbix_server.conf zabbix_server.j2
[root@ansible zabbix]# mv zabbix_agentd.conf zabbix_agentd.j2
[root@ansible zabbix]# cat zsa.yaml
- name: 编排zabbix
hosts: server
tasks:
- name: 复制server配置文件
template:
src: ./zabbix_server.conf.j2
dest: /etc/zabbix_server.conf
- name: 复制agent配置文件
template:
src: ./zabbix_agentd.conf.j2
dest: /etc/zabbix_agentd.conf
- name: 重启zabbix
service:
name: "{{ item }}"
state: restarted
loop:
- zabbix-server
- zabbix-agent
[root@ansible zabbix]# ansible-playbook zsa.yaml
3.编辑php配置文件
[root@zabbix-server ~]# find / -name php.ini
[root@ansible zabbix]# scp zabbix_server:/etc/remi/php74/php.ini .
[root@ansible zabbix]# vim php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
datetimezone = Asia/Shanghai
[root@ansible zabbix]# mv php.ini php.ini.j2
[root@ansible zabbix]# cat php.yaml
- name: 编辑php
hosts: server
tasks:
- name: 复制php配置文件
template:
src: ./php.ini.j2
dest: /etc/opt/remi/php74/php.ini
- name: 重启php
service:
name: "{{item}}"
state: restarted
loop:
- php74-php-fpm
[root@ansible zabbix]# ansible-playbook php.yaml
4.配置www.conf
[root@zabbix-server ~]# find / -name www.conf
[root@ansible zabbix]# scp zabbix_server:/etc/php-fpm.d/www.conf .
[root@ansible zabbix]# vim www.conf
user = nginx
group = nginx
[root@ansible zabbix]# mv www.conf www.conf.j2
[root@ansible zabbix]# cat www.yaml
- name: 编辑php
hosts: server
tasks:
- name: 复制php配置文件
template:
src: ./www.conf.j2
dest: /etc/php-fpm.d/www.conf
- name: 重启php
service:
name: "{{item}}"
state: restarted
loop:
- php74-php-fpm
[root@ansible zabbix]# ansible-playbook www.yaml
5.编辑nginx配置文件
[root@zabbix-server ~]# find / -name default.conf
[root@ansible zabbix]# scp zabbix_server:/etc/nginx/conf.d.default.conf .
[root@ansible zabbix]# vim default.conf
root /usr/share/zabbix;
location ~ \.php$ { #让这一段生效
root /usr/share/zabbix; #路径和上面一样
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #这行要修改
[root@ansible zabbix]# mv default.conf default.conf.j2
[root@ansible zabbix]# cat default.yaml
- name: 编辑nginx
hosts: server
tasks:
- name: 复制nginx配置文件
template:
src: ./default.conf.j2.j2
dest: /etc/nginx/conf.d.default.conf
- name: 重启nginx
service:
name: "{{item}}"
state: restarted
loop:
- nginx
[root@ansible zabbix]# ansible-playbook default.yaml
6.配置zabbix.conf
[root@zabbix-server ~]# find / -name zabbix.conf
[root@ansible zabbix]# scp zabbix_server:/etc/php-fpm.d/zabbix.conf .
[root@ansible zabbix]#vim zabbix.conf
user = nginx
group = nginx
[root@ansible zabbix]# mv zabbix.conf zabbix.conf.j2
[root@ansible zabbix]# cat zabbix.yaml
- name: 编辑zabbix.conf
hosts: server
tasks:
- name: 复制zabbix.conf配置文件
template:
src: ./zabbix.conf.j2
dest: /etc/php-fpm.d/zabbix.conf
- name: 重启相关服务
service:
name: "{{item}}"
state: restarted
loop:
- zabbix_server
- zabbix-agent
- php74-php-fpm
- mariadb
- nginx
[root@ansible zabbix]# ansible-plabook zabbix.yaml
7.编写playbook
[root@ansible zabbix]# cat agent.yaml
- name: 配置agent节点
hosts: agent
tasks:
- name: 删除repo
file:
path: /etc/yum.repos.d
state: absent
- name: 设置755
file:
path: /etc/yum.repos.d
state: directory
mode: 755
- name: 复制
copy:
src: files/ftp.repo
dest: /etc/yum.repos.d/
- name: 安装zabbix-agent
yum:
name: zabbix6.0-agent
- name: 复制zabbix配置文件
template:
src: ./zabbix_agentd.conf.j2
dest: /etc/zabbix_agentd.conf
- name: 重启zabbix-agent
service:
name: "{{ item }}"
state: restarted
loop:
- zabbix-agent
[root@ansible zabbix]# ansible-playbook agent.yaml
- 点赞
- 收藏
- 关注作者
评论(0)