zabbix v3.0安装部署全过程详解
关于zabbix及相关服务软件版本:
linux:centos 6.6
nginx:1.9.15
mysql:5.5.49
php:5.5.35
一、安装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软件包并进入到目录中:
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.14 --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.14 /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
下载php安装包:
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环境需要修改的参数)
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
下载mysql安装包:
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/
启动mysql:
[root@zabbix ~]# /etc/init.d/mysqld start starting mysql... success!
登录数据库,创建zabbix数据库及用户名和密码:
mysql> create database zabbix default charset utf8; query ok, 1 row affected (0.00 sec) mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix'; query ok, 0 rows affected (0.03 sec) mysql> flush privileges; query ok, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | zabbix | +--------------------+ rows in set (0.00 sec)
如果登录数据库出现问题:
[root@zabbix ~]# mysql error 2002 (hy000): can't connect to local mysql server through socket '/var/lib/mysql/mysql.sock' (2)
解决办法:
[root@zabbix ~]# ln -s /tmp/mysql.sock /var/lib/mysql/
为数据库的root创建密码:
[root@zabbix zabbix-3.0.3]# mysqladmin -uroot password "zabbix"
四、安装zabbix server:
安装zabbix:
-rw-r--r-- 1 root root 15407273 5月 21 2016 zabbix-3.0.3.tar.gz [root@zabbix ~]# tar zxf zabbix-3.0.3.tar.gz && cd zabbix-3.0.3 编译zabbix: ./configure --prefix=/usr/local/zabbix-3.0.3/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 make && make install
编译过程中如果有报错:
故障:
checking for mysql_config... no configure: error: mysql library not found
解决:
yum install mysql-devel -y
故障:
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用户:
[root@zabbix zabbix-3.0.3]# groupadd zabbix [root@zabbix zabbix-3.0.3]# useradd zabbix -s /sbin/nologin -m -g
zabbix server需要导入3个sql文件:
[root@zabbix zabbix-3.0.3]# mysql -uroot -pzabbix zabbix < database/mysql/schema.sql [root@zabbix zabbix-3.0.3]# mysql -uroot -pzabbix zabbix < database/mysql/images.sql [root@zabbix zabbix-3.0.3]# mysql -uroot -pzabbix zabbix < database/mysql/data.sql [root@zabbix zabbix-3.0.3]# pwd /root/zabbix-3.0.3
五、zabbix管理网站配置(nginx):
创建项目目录:
[root@zabbix zabbix-3.0.3]# mkdir /data/web/zabbix.lifec.com -p [root@zabbix zabbix-3.0.3]# mkdir /data/logs/zabbix -p
将前端文件拷贝到项目目录下:
[root@zabbix zabbix-3.0.3]# cp -rp frontends/php/* /data/web/zabbix.lifec.com/
编辑nginx虚拟主机:
[root@zabbix conf]# mkdir extra [root@zabbix conf]# cd extra/ [root@zabbix extra]# vim zabbix.conf server { listen 8027; server_name zabbix.lifec.com; access_log /data/logs/zabbix/zabbix.lifec.com.access.log main; index index.html index.php index.html; root /data/web/zabbix.lifec.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; } }
编辑nginx.conf配置文件:
[root@zabbix conf]# cat nginx.conf user nginx; worker_processes 1; #error_log logs/error.log warning; #error_log logs/error.log notice; #error_log logs/error.log info; 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; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; include extra/*.conf; }
编辑zabbix_server.conf文件:
[root@zabbix etc]# pwd /usr/local/zabbix-3.0.2/etc logfile=/tmp/zabbix_server.log pidfile=/tmp/zabbix_server.pid dbhost=localhost dbname=zabbix dbuser=zabbix dbpassword=zabbix
六、启动服务
启动nginx:
[root@zabbix conf]# /usr/local/nginx/sbin/nginx
启动php:
[root@zabbix conf]# /usr/local/php/sbin/php-fpm
启动zabbix server:
[root@zabbix conf]# /usr/local/zabbix-3.0.3/sbin/zabbix_server 如果启动的时候报错: [root@zabbix ~]# /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 [root@zabbix ~]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
添加/etc/hosts文件:
192.168.119.140 zabbix.lifec.com
查看服务端口:
[root@zabbix conf]# netstat -lntup active internet connections (only servers) proto recv-q send-q local address foreign address state pid/program name tcp 0 0 0.0.0.0:22 0.0.0.0:* listen 1029/sshd tcp 0 0 0.0.0.0:8027 0.0.0.0:* listen 3730/nginx tcp 0 0 0.0.0.0:10051 0.0.0.0:* listen 3743/zabbix_server tcp 0 0 127.0.0.1:9000 0.0.0.0:* listen 3736/php-fpm tcp 0 0 0.0.0.0:3306 0.0.0.0:* listen 24922/mysqld tcp 0 0 :::22 :::* listen 1029/sshd udp 0 0 0.0.0.0:68 0.0.0.0:* 880/dhclient
将服务加入开机自启动:
[root@zabbix ~]# echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local [root@zabbix ~]# echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local [root@zabbix ~]# echo "/etc/init.d/mysqld start" >>/etc/rc.local [root@zabbix ~]# echo "/usr/local/zabbix-3.0.3/sbin/zabbix_server" >>/etc/rc.local
七、web端配置zabbix
只有图,几乎没有文字,哈哈哈。。。
需要下载文件,并上传到指定的服务器目录中。
修改界面为中文界面
默认登录界面为英文:
修改以下配置,并重启服务即可;
vim /data/web/zabbix.lifec.com/include/locales.inc.php
#'zh_cn' => ['name' => _('chinese (zh_cn)'), 'display' => false],
'zh_cn' => ['name' => _('chinese (zh_cn)'), 'display' => true],
为了防止图形中的字符出现乱码:
需要自己上传字体:
将选择的字体上传到linux服务器的zabbix的fonts目录:
/data/web/zabbix.lifec.com/fonts
并修改以下配置:
vim /data/web/zabbix.lifec.com/include/defines.inc.php define('zbx_graph_font_name', 'dejavusans'); // font file name define('zbx_graph_font_name', 'simsun'); // font file name ==>此行为新增行; define('zbx_font_name', 'dejavusans'); define('zbx_font_name', 'simsun'); ==>此行为新增行;
重启服务即可。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。