zabbix安装与配置(总结)

 

1.去官网下载:

https://www.zabbix.com/download_sources#tab:34

2.使用ansible安装相关依赖:

ansible monitor -m copy -a 'src=/etc/ansible/monitor/zabbix-3.4.14.tar.gz dest=/home mode=0644'
ansible monitor -m group -a 'name=zabbix system=yes state=present'
ansible monitor -m user -a 'name=zabbix system=yes group=zabbix home=/var/lib/zabbix createhome=no shell=/usr/sbin/nologin state=present'
ansible monitor -m unarchive -a 'src=/home/zabbix-3.4.14.tar.gz dest=/home copy=no mode=0755'
ansible monitor -m file -a 'path=/home/zabbix-3.4.14 owner=root group=root recurse=yes'
ansible monitor -m apt -a 'pkg=mysql-server,mysql-client,libmysqlclient-dev,libxml2-dev,libsnmp-dev,libevent-dev,libcurl4-openssl-dev,libpcre3-dev state=present force=yes'
ansible monitor -m apt -a 'pkg=apache2,php5,php5-gd,libapache2-mod-php5,php5-mysql,php5-ldap,language-pack-zh-hant,language-pack-zh-hans state=present force=yes'

3.mysql数据库配置:

mysql -uroot
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
quit
cd /home/zabbix-3.4.14/database/mysql
mysql -uzabbix -ppassword zabbix < schema.sql
mysql -uzabbix -ppassword zabbix < images.sql
mysql -uzabbix -ppassword zabbix < data.sql

4.PHP配置:

sed -i 's/post_max_size = 8M/post_max_size = 16M/' /etc/php5/apache2/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/' /etc/php5/apache2/php.ini
sed -i 's/max_input_time = 60/max_input_time = 300/' /etc/php5/apache2/php.ini
sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#' /etc/php5/apache2/php.ini

5.编译安装zabbix server: 

cd /home/zabbix-3.4.14/
./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
make install

cp misc/init.d/tru64/zabbix_server /etc/init.d/
chmod 700 /etc/init.d/zabbix_server
/etc/init.d/zabbix_server start

6.配置apache:

echo "ServerName 10.0.22.17" >> /etc/apache2/apache2.conf
service apache2 restart
mkdir /var/www/zabbix
cd /home/zabbix-3.4.14/frontends/php
cp -a . /var/www/zabbix/
安装zabbix前端,In your browser, open Zabbix URL: http://<server_ip_or_name>/zabbix
参考官方文档:https://www.zabbix.com/documentation/3.4/manual/installation/install

附: 解决图形中文乱码:
 #将windows字体文件simkai.ttf上传至: /var/www/zabbix/fonts 

  ansible monitor -m copy -a 'src=/etc/ansible/monitor/simkai.ttf dest=/var/www/zabbix/fonts mode=0644'
  sed -i 's/DejaVuSans/simkai/g' /var/www/zabbix/include/defines.inc.php

7.agent端安装:

#!/bin/bash
##install zabbix_agent

#新增用户和用户组
groupadd zabbix
useradd zabbix -g zabbix -s /sbin/nologin
##安装
cd /usr/local/src  && tar zxvf zabbix-3.4.14.tar.gz
cd zabbix-3.4.14
./configure --with-net-snmp --with-libcurl --enable-agent --prefix=/usr/local/zabbix
make && make install

cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
chmod 700 /etc/init.d/zabbix_agentd

###配置
client_hostname=`hostname`
Server='serverIP'

if [ ! -d /usr/local/zabbix/logs/ ]
    then
        mkdir -p /usr/local/zabbix/logs/
fi

if [ ! -f /usr/local/zabbix/etc/zabbix_command.conf ]
    then
        touch /usr/local/zabbix/etc/zabbix_command.conf
fi

cat > /usr/local/zabbix/etc/zabbix_agentd.conf  <<EOF
Server=${Server}
ServerActive=${Server}
#RefreshActiveChecks=30
Hostname=${client_hostname}
HostMetadataItem=system.uname

BufferSize=1024
DebugLevel=2
StartAgents=3
LogFileSize=1024
EnableRemoteCommands=1
PidFile=/tmp/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Include=/usr/local/zabbix/etc/zabbix_command.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
EOF

chown -R zabbix:zabbix /usr/local/zabbix/
sed -i "24s/local/sbin/local/zabbix/sbin/" /etc/init.d/zabbix_agentd
/etc/init.d/zabbix_agentd start
install_zabbix_agent.sh

使用ansible-playbook安装:

---
   - hosts: monitor
     remote_user: root
     gather_facts: no
     tasks:
        - name: install zabbix_agent packages
          apt: name={{ item }} state=latest force=yes
          with_items:
          - libcurl4-openssl-dev
          - libpcre3-dev

        - name: copy tar to host
          copy: src=/etc/ansible/monitor/zabbix-3.4.14.tar.gz dest=/usr/local/src/zabbix-3.4.14.tar.gz owner=root group=root mode=544

        - name: copy install shell to host
          copy: src=/etc/ansible/monitor/zabbix_agent.sh dest=/usr/local/src/zabbix_agent.sh owner=root group=root mode=755
          notify: install zabbix

     handlers:
        - name: install zabbix
          shell: /bin/bash /usr/local/src/zabbix_agent.sh
原文地址:https://www.cnblogs.com/pythonlee/p/9922346.html