ansible 一键安装zabbix-server

1,这里我的数据库和zabbix-server不在同一台服务器

安装mysql

yum -y install mariadb-server
systemctl restart mariadb
[root@zabbix-server ~]# mysqladmin -uroot -p password 
Enter password: 
[root@zabbix-server ~]# mysql -u root -p'123qqq...A'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user zabbix@'%' identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@'%';
Query OK, 0 rows affected (0.00 sec)
cd /usr/local/src/zabbix/database/mysql/
mysql -u zabbix -h 10.1.234.116 -p'zabbix' zabbix < schema.sql
 mysql -u zabbix -h 10.1.234.116 -p'zabbix' zabbix < images.sql
mysql -u zabbix -h 10.1.234.116 -p'zabbix' zabbix < data.sql 

 

[root@ansible-11 zabbix]# tree
.
├── conf
│   ├── nginx.conf
│   ├── nginx.service
│   ├── php.ini
│   └── zabbix_server.conf
├── hosts
├── pkg
│   ├── nginx-1.18.0.tar.gz
│   ├── zabbix-4.0.15.tar.gz
│   ├── zabbix-4.2.0.tar.gz
│   └── zabbix-4.4.10.tar.gz
└── zabbix.yaml

 

---
- hosts: zabbix
  vars: 
  remote_user: root
  gather_facts: false

  tasks:
  - name: yum 安装依赖
    shell: yum install  openldap openldap-devel gcc libxml2-devel   net-snmp net-snmp-devel   curl curl-devel php php-bcmath php-mbstring mariadb mariadb-devel  java-1.8.0*  libevent-devel   libpng-devel -y

  - name: 安装php 依赖
    shell: yum -y install net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath fping OpenIPMI-devel php-mbstring  php-ldap

  - name: 分发压缩包
    unarchive: src=pkg/zabbix-4.0.15.tar.gz dest=/tmp 

  - name: 创建用户和组
    user: name=zabbix state=present
   
  - name: mv 文件到路径
    shell: mv /tmp/zabbix-4.0.15  /usr/local/src/zabbix

  - name: 编译安装
    shell: cd /usr/local/src/zabbix &&  
           ./configure --prefix=/apps/zabbix_server --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java &&
            make install

  - name: yum 安装nginx依赖
    shell: yum -y install  gcc  pcre-devel zlib-devel openssl-devel  php  php-mysql  php-fpm

  - name: 分发压缩包
    unarchive: src=pkg/nginx-1.18.0.tar.gz dest=/tmp

  - name: 编译nginx
    shell: cd /tmp/nginx-1.18.0 &&
           ./configure --with-http_ssl_module &&
           make && make install    
 
  - name: 拷贝nginx配置
    copy: src=conf/nginx.conf  dest=/usr/local/nginx/conf/nginx.conf
  
  - name: 修改php 基础配置
    copy: src=conf/php.ini dest=/etc/php.ini

  - name: 启动php-fpm
    systemd: name=php-fpm state=restarted enabled=yes

  - name: copy nginx启动配置文件
    copy: src=conf/nginx.service dest=/usr/lib/systemd/system/nginx.service

  - name: 启动nginx
    systemd: name=nginx state=restarted enabled=yes

  - name: 创建zabbix php 文件存放
    file: dest=/usr/local/nginx/html/zabbix  state=directory

  - name: 拷贝zabbix php文件到nginx
    shell: cd /usr/local/src/zabbix/frontends/php/ &&
           cp -a * /usr/local/nginx/html/zabbix/   &&
           chmod -R 777 /usr/local/nginx/html/zabbix 

  - name: 拷贝zabbix server配置文件
    copy: src=conf/zabbix_server.conf dest=/apps/zabbix_server/etc/zabbix_server.conf

  - name: 启动zabbix-server
    shell: /apps/zabbix_server/sbin/zabbix_server -c /apps/zabbix_server/etc/zabbix_server.conf      

 全部ok 就可以下一步了

ansible 一键安装zabbix-server_第1张图片

 

你可能感兴趣的:(监控,zabbix)