Commit 1f160c56 by 杜崇铭

Install zabbix

parent f91c481e
...@@ -8,15 +8,23 @@ ...@@ -8,15 +8,23 @@
使用: 使用:
1. 个人环境安装ansible,使用pip工具安装(需要Python3)。pip3 install ansible即可完成。 1. 个人环境安装ansible,使用pip工具安装(需要Python3)。pip3 install ansible即可完成。
2. git clone http://code.mayi888.com/duchongming/Ant_Devops.git 2. git clone http://code.mayi888.com/operation/Ant_Devops.git
3. cd Ant_Devops 3. cd Ant_Devops
4. 设置免密认证。文档:https://blog.csdn.net/furzoom/article/details/79139570 4. 设置免密认证。文档:https://blog.csdn.net/furzoom/article/details/79139570
5. 修改host.yml.examples中内容为远程主机公网地址,并重命名此文件为host.yml 5. 修改host.yml.examples中内容为远程主机公网地址,并重命名此文件为host.yml
6. 修改roles/nginx/templates/examples.conf或roles/nginx/templates/examplesadmin.conf内容,把文中“examples”替换成需要的URL。其中,roles/nginx/templates/examples.conf适合前后分离的web环境。roles/nginx/templates/examplesadmin.conf适合用到“统一管理平台”的web环境。 6. 修改roles/nginx/templates/examples.conf或roles/nginx/templates/examplesadmin.conf内容,把文中“examples”替换成需要的URL。其中,roles/nginx/templates/examples.conf适合前后分离的web环境。roles/nginx/templates/examplesadmin.conf适合用到“统一管理平台”的web环境。
7. 运行 ansible-playbook -i host.yml -u root playbook.yml 7. 运行 ansible-playbook -i host.yml -u root standard.yml
本环境内容: 本环境内容:
1. nginx(tenginx 2.2.2) 1. nginx(tenginx 2.2.2)
2. openjdk(1.8) 2. openjdk(1.8)
3. docker(17.12.1-ce) 3. docker(17.12.1-ce)
4. git(2.9.5) 4. git(2.9.5)
\ No newline at end of file
Zabbix
自动化部署Zabbix监控
使用:
1-5同上
6. 修改roles/zabbix_server/templates/zabbix_server.conf和roles/zabbix_agent/templates/zabbix_agentd.conf中的变量
7. 运行ansible-playbook -i host.yml -u root zabbix.yml
\ No newline at end of file
[local] [local]
118.25.142.187 localhost
[zabbix_server] [zabbix_server]
host1 118.25.142.187
[zabbix_agent] [zabbix_agent]
agent1 106.15.184.18
\ No newline at end of file \ No newline at end of file
---
- name: restart zabbix-agentd
service:
name: zabbix-agent
state: restarted
enabled: yes
\ No newline at end of file
---
- name: "Install zabbix repo"
yum:
name: https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
state: present
- name: "Install zabbix agent"
yum:
name: "{{ zabbix_agent_packages }}"
state: latest
- name: "move templates to zabbix agentd"
template:
src: zabbix_agentd.conf
dest: "{{ zbwork }}/zabbix_agentd.conf"
notify:
- restart zabbix-agentd
\ No newline at end of file
############ GENERAL PARAMETERS #################
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
##### Passive checks related
Server=118.25.142.187
### Option: ServerActive
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf
\ No newline at end of file
---
- name: restart zabbix-server
service:
name: zabbix-server
state: restarted
enabled: yes
- name: restart httpd
service:
name: httpd
state: restarted
enabled: yes
\ No newline at end of file
--- ---
- name: "Install zabbix repo" - name: "Install zabbix repo"
shell: "rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.noarch.rpm" yum:
name: https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
state: present
- name: "Install zabbix packages" - name: "Install zabbix packages"
yum: yum:
name: "{{ zabbix_server_packages }}" name: "{{ zabbix_server_packages }}"
state: latest state: latest
when: host=="zabbix_server"
- name: "Install zabbix agent"
yum:
name: "{{ zabbix_agent_packages }}"
state: latest
when: host=="zabbix_agent"
- name: "mysql operation" - name: "mysql operation"
mysql_db: mysql_db:
...@@ -23,15 +18,25 @@ ...@@ -23,15 +18,25 @@
login_password: "{{ login_password }}" login_password: "{{ login_password }}"
encoding: utf8 encoding: utf8
state: present state: present
when: host=="zabbix_server"
- name: "copy mysql shell script" - name: "copy mysql shell script"
copy: copy:
src: zabbix_db.sh src: zabbix_db.sh
dest: /tmp/zabbix.sh dest: /tmp/zabbix.sh
when: host=="zabbix_server"
- name: "run mysql shell script" - name: "run mysql shell script"
shell: "/bin/bash /tmp/zabbix.sh" shell: "/bin/bash /tmp/zabbix.sh"
when: host=="zabbix_server"
- name: "move templates to zabbix server"
template:
src: zabbix_server.conf
dest: "{{ zbwork }}/zabbix_server.conf"
notify:
- restart zabbix-server
- name: "run zabbix web"
template:
src: zabbix.conf
dest: /etc/httpd/conf.d/zabbix.conf
notify:
- restart httpd
\ No newline at end of file
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
</IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/app">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/include">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/local">
Require all denied
</Directory>
\ No newline at end of file
############ GENERAL PARAMETERS #################
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=1q2w3e4r
############ ADVANCED PARAMETERS ################
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
\ No newline at end of file
...@@ -14,4 +14,7 @@ zabbix_agent_packages: ...@@ -14,4 +14,7 @@ zabbix_agent_packages:
#mysql args #mysql args
login_password: 1q2w3e4r login_password: 1q2w3e4r
mysql_port: 3306 mysql_port: 3306
\ No newline at end of file
#zabbix work dir
zbwork: /etc/zabbix
\ No newline at end of file
--- ---
- name: "Install zabbix " - name: "Install zabbix_server "
hosts: all hosts: zabbix_server
remote_user: root remote_user: root
vars_files: vars_files:
- var/main.yml - var/main.yml
roles: roles:
- zabbix - zabbix_server
\ No newline at end of file
- name: "Install zabbix_agent "
hosts: zabbix_agent
remote_user: root
vars_files:
- var/main.yml
roles:
- zabbix_agent
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment