介绍
Ansible 是一种开源的自动化平台,用于配置管理、应用部署以及任务自动化。它简化了 IT 环境的管理工作,使得自动化变得更加容易实现。Ansible 使用简单的语言YAML来描述自动化任务,这使得它易于阅读和编写。它可以连接到客户端并在多个系统上执行任务,而无需在客户端上安装任何代理软件。
Zabbix 是一个企业级的开源解决方案,用于监控各种网络参数,确保服务器系统的安全运行,并提供灵活的通知机制,帮助系统管理员快速定位和解决问题。Zabbix也是一款能够监控各种网络参数以及服务器健康性和完整性的软件。Zabbix使用灵活的通知机制,允许用户为几乎任何事件配置基于邮件的告警。这样可以快速反馈服务器的问题。基于已存储的数据,Zabbix提供了出色的报告和数据可视化功能
1.配置源
[root@node1 ~]# cat /etc/yum.repos.d/local.repo
[ansible]
name=ansible
baseurl=ftp://ansible/ansible
enabled=1
gpgcheck=0
[centos]
name=centos
baseurl=ftp://ansible/centos
enabled=1
gpgcheck=0
[zabbix]
name=zabbix
baseurl=ftp://ansible/zabbix
enabled=1
gpgcheck=0#母机上把文件配好:
[root@ansible ansible_ftp]#yum install zabbix-server -y
#zabbix-server.conf
[root@ansible ~]# egrep -v '^$|#' zabbix/zabbix_server.conf
母机添加配置传给node1
DBHost=localhost
DBPassword=zabbix
[root@zabbix ansible]# yum install zabbix-web-mysql
[root@ansible ansible_ftp]# vi /etc/httpd/conf.d/zabbix.conf #添加时区
php_value date.timezone Asia/Shanghai[root@ansible ansible_ftp]# vi /etc/php.ini 添加
date.timezone = RPC
测试连通性
[root@ansible ~]# ansible node -m ping
编写剧本
[root@controller ansible_ftp]#cat install_zabbix.yaml
- hosts: all
remote_user: root
tasks:
- shell: mv /etc/yum.repos.d/* /home/
- name: copy
copy:
src: /etc/yum.repos.d/local.repo
dest: /etc/yum.repos.d/
- name: yum
yum:
name:
- httpd
- mariadb-server
- MySQL-python
- zabbix-agent
- zabbix-server
- zabbix-web
- name: service
service:
name: mariadb
state: started
enabled: yes
- name: mysql_user
mysql_user:
name: zabbix
priv: '*.*:ALL'
password: 'zabbix'
state: present
- name: mysql_db
mysql_db:
name: zabbix
login_user: zabbix
login_password: 'zabbix'
target: '/usr/share/doc/zabbix-server-mysql-3.4.15/create.sql.gz'
state: import
- name: copy-zabbix
copy:
src: /etc/zabbix/zabbix_server.conf
dest: /etc/zabbix/zabbix_server.conf
- name: copy-httpd
copy:
src: /etc/httpd/conf.d/zabbix.conf
dest: /etc/httpd/conf.d/zabbix.conf
- name: copy-php
copy:
src: /etc/php.ini
dest: /etc/php.ini
- name: service
service:
name: '{{item}}'
state: started
enabled: yes
loop:
- httpd
- zabbix-server
[root@controller ansible_ftp]# ansible-playbook install_zabbix.yaml