本文针对zabbix新版本使用的探索

1,环境准备

系统版本centos7最小化安装,配置好网络能访问外网,关闭防火墙,配置基础环境及java环境

网络自行配置

关闭防火墙

setenforce 0

systemctl stop firewalld

systemctl disable firewalld

sed -i 's/enforcing/disabled/g' /etc/selinux/config


设置yum源

yum install wget -y

cd /etc/yum.repos.d/

wget http://mirrors.aliyun.com/repo/Centos-7.repo

wget http://mirrors.aliyun.com/repo/epel-7.repo

yum -y install epel-release

yum install net-tools -y

yum install tree -y

yum install lrzsz -y

yum install vim-enhanced -y


2,环境部署


2.1软件准备

Linux:centos 7
nginx:1.9.15
MySQL:5.5.49
PHP:5.5.35

zabbix-3.0.3

安装包都下载到/home/soft/下


安装nginx


安装依赖包

$ yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel


创建用户

$ useradd nginx -s /sbin/nologin -M

下载nginx软件包并进入到目录中

cd /home/soft/

$ wget http://nginx.org/download/nginx-1.9.15.tar.gz && tar xvf nginx-1.9.15.tar.gz && cd nginx-1.9.15


编译安装

$ ./configure --prefix=/usr/local/product/nginx1.9.15 --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre

$ make && make install

$ ln -s /usr/local/product/nginx1.9.15 /usr/local/nginx    // 创建软链接


参数解释

 --with-http_stub_status_module:支持nginx状态查询

 --with-http_ssl_module:支持https

 --with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持

 --with-pcre:为了支持rewrite重写功能,必须制定pcre


安装PHP

cd /home/soft/

$ wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror


解压并编译

$ mv mirror php-5.5.35.tar.gz && tar xvf php-5.5.35.tar.gz && cd php-5.5.35

$ ./configure --prefix=/usr/local/product/php-5.5.35 --with-config-file-path=/usr/local/product/php-5.5.35/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath

$ make && make install


$ ln -s /usr/local/product/php-5.5.35 /usr/local/php

$ cp php.ini-production /usr/local/php/etc/php.ini

$ cd /usr/local/php/etc/

$ cp php-fpm.conf.default php-fpm.conf


修改php.ini参数:(zabbix环境需要修改的参数)

vim /usr/local/php/etc/php.ini

 max_execution_time = 300

 memory_limit = 128M

 post_max_size = 16M
 upload_max_filesize = 2M

 max_input_time = 300

 date.timezone = PRC


安装mysql


添加mysql用户,创建mysql的数据目录

$ groupadd mysql

$ mkdir -pv /data/mysql

$ useradd -r -g mysql -d /data/mysql -s /sbin/nologin mysql

$ chown -R mysql.mysql /data/mysql


安装cmake及依赖
$ yum install cmake gcc* ncurses-devel -y

   yum install mysql-devel -y

   yum install net-snmp-devel -y


下载MySQL安装包

cd /home/soft/

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz


编译安装MySQL

$ tar -xvf mysql-5.5.49.tar.gz && cd mysql-5.5.49

$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/product/mysql5.5.49 -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci

$ make && make install

$ ln -s /usr/local/product/mysql5.5.49 /usr/local/mysql

$ chown -R mysql.mysql /usr/local/mysql


拷贝mysql的配置文件

$ cd /usr/local/mysql/support-files/

$ cp my-medium.cnf /data/mysql/my.cnf
$ cp mysql.server /etc/init.d/mysqld

$ chmod +x /etc/init.d/mysqld


初始化MySQL

$ cd /usr/local/mysql/scripts

$ ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/


修改MySQL配置文件my.cnf中数据目录

 datadir=/data/mysql/


然后复制一份到/etc/

cp -a /data/mysql/my.cnf /etc/my.cnf


启动MySQL

$ /etc/init.d/mysqld start


为数据库的root创建密码
$ mysqladmin -uroot password  "zabbix"


登录数据库,创建zabbix数据库及用户名和密码
mysql> create database zabbix default charset utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on *.* to zabbix@'localhost' identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)


mysql> grant all privileges on *.* to zabbix@'%' identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


登陆数据库问题

$ mysql -uroot -pzabbix
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)解决办法:$ ln -s /tmp/mysql.sock /var/lib/mysql/


安装zabbix

cd /home/soft/

下载安装包
$ wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz


安装zabbix

$ tar zxf zabbix-3.0.3.tar.gz && cd zabbix-3.0.3

$ ./configure --prefix=/usr/local/zabbix-3.0.3/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

$ make && make install


编译过程中如果有报错
故障1:
  checking for mysql_config... no
  configure: error: MySQL library not found
解决:
 $ yum install mysql-devel -y


故障2:
  checking for net-snmp-config... no
  configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
解决:
 $ yum install net-snmp-devel -y


创建zabbix用户

$ groupadd zabbix

$ useradd zabbix -s /sbin/nologin -M -g zabbix

zabbix server需要导入3个sql文件

$ mysql -uroot -pzabbix zabbix < database/mysql/schema.sql
$ mysql -uroot -pzabbix zabbix < database/mysql/images.sql
$ mysql -uroot -pzabbix zabbix < database/mysql/data.sql


zabbix管理页面配置(nginx)

创建项目目录
$ mkdir -p /data/web/www.zabbix.com

$ mkdir -p /data/logs/zabbix


将前端文件拷贝到项目目录下

cd /home/soft/zabbix-3.0.3

$ cp -rp frontends/php/* /data/web/www.zabbix.com/

$ cp include /data/web/www.zabbix.com/


编辑nginx虚拟主机

$ cd /usr/local/nginx/conf


编辑nginx.conf配置文件

$ vim nginx.conf
user  nginx;
worker_processes  1;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
    listen 8080;
    server_name www.zabbix.com;
    access_log /data/logs/zabbix/www.zabbix.com.access.log main;
    index index.html index.php index.html;
    root /data/web/www.zabbix.com;
    location /{
               try_files $uri $uri/ /index.php?$args;
        }
    location ~ ^(.+.php)(.*)$ {
               fastcgi_split_path_info ^(.+.php)(.*)$;
               include fastcgi.conf;
               fastcgi_pass 127.0.0.1:9000;
               fastcgi_index index.php;
               fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }    
}

编辑zabbix_server.conf文件

$ vim etc/zabbix_server.conf

LogFile=/tmp/zabbix_server.log

PidFile=/tmp/zabbix_server.pid

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

DBSocket=/tmp/mysql.sock


启动服务


启动nginx

$ /usr/local/nginx/sbin/nginx

启动PHP

$ /usr/local/php/sbin/php-fpm

启动zabbix server

$ /usr/local/zabbix-3.0.3/sbin/zabbix_server

如果启动的时候报错:
$ /usr/local/zabbix-3.0.2/sbin/zabbix_server

 /usr/local/zabbix-3.0.2/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

$ ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/


添加/etc/hosts文件
192.168.1.12  www.zabbix.com


将服务加入开机自启动
$ echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
$ echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local
$ echo "/etc/init.d/mysqld start" >>/etc/rc.local
$ echo "/usr/local/zabbix-3.0.3/sbin/zabbix_server" >>/etc/rc.local


在windows机器上添加hosts

C:\Windows\System32\drivers\etc\hosts

192.168.1.12  www.zabbix.com


浏览器访问192.168.1.12:8080 初始配置zabbix页面

图片.png


图片.png

图片.png

图片.png






图片.png








图片.png

上图:下载zabbix.conf.php文件并上传到提示的对应目录

图片.png

图片.png


登陆后设置中文界面


修改Zabbix的PHP目录中的locales.inc.php
vim /data/web/www.zabbix.com/include/locales.inc.php

找到zh_CN  将,flase改为true

接着打开Zabbix界面,Administrator-User
选择语言-Chinese(zh_CN)-update-刷新Zabbix Web页面

图片.png



安装zabbix-agent

使用rpm安装

yum install -y unixODBC

rpm -Uvh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-agent-3.0.3-1.el6.x86_64.rpm

修改配置

vim /etc/zabbix/zabbix_agentd.conf

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.1.12
ServerActive=192.168.1.12
Hostname=192.168.1.12
Include=/etc/zabbix/zabbix_agentd.d/

启动zabbix-agent

/etc/init.d/zabbix-agent start


今天先到这里,下一篇文章将继续页面设置与服务监控设置。