一.准备zabbix安装环境 Centos7系统 zabbix安装

1.安装ntpdate yum install ntpdate /usr/sbin/ntpdate 0.pool.ntp.org 更新时间不重要

2.创建用户www mysql #groupadd www #useradd -g www www -s /bin/false #groupadd mysql #useradd -g mysql mysql -s /bin/false

在安装nginxt和php之前,我们需要安装时所需要的相关软件包. (1)yum -y install gcc gcc++ gcc-c++ zlibzlib-devel libjpeg-devel curl-devel openssl openssl-devel libxml2 libxml2-devel cmake bison-devel ncurses-devel perllibpng libpng-devel 注意事项,先创建一个目录,用来存放所有的安装包,以便管理,并且配置要用的 #mkdir /data #yum -y install lrzsz shell 安装shell拉入包命令 #yum -y install nano vim wget curl net-tools lsof 最小化安装的Centos7系统并没有nano、vim、wget、curl、ifconfig、lsof、zip、unzip命令 (2)安装pcre #cd /data 然后把对应的安装包丢进里面 #tar xf pcre-8.39.tar.gz #cd pcre-8.39 #./configure --prefix=/usr/local/pcre #make #make install (3)安装libmcrypt #cd /data 然后把对应的安装包丢进里面 #ar xf libmcrypt-2.5.8.tar.gz #cd libmcrypt-2.5.8 #./configure #make #make install (4)安装jpeg #cd /data 然后把对应的安装包丢进里面 #tar xf jpegsrc.v8d.tar.gz #cd jpeg-8d/ #./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static #make #make install (5)安装png #cd /data 然后把对应的安装包丢进里面 #tar xf libpng-1.6.25.tar.gz #cd libpng-1.6.25 #./configure #make #make install (6)安装freetype #cd /data 然后把对应的安装包丢进里面 #tar xf freetype-2.5.4.tar.gz #cd freetype-2.5.4 #./configure --prefix=/usr/local/freetype --enable-shared #make #make install 二.安装nginx #tar xf nginx-1.8.1.tar.gz #cd nginx-1.8.1 #./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/data/pcre-8.39 注意:--with-pcre=/data/pcre-8.39指向的是源码包解压的路径,而不是安装的路径,否则会报错 #make #make install #/usr/local/nginx/sbin/nginx 启动nainx 设置nginx开启启动 vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容 #!/bin/bash

nginx Startup script for the Nginx HTTP Server it is v.0.0.2 version. chkconfig: - 85 15 description: Nginx is a high-performance web and proxy server. It has a lot of features, but it's not for everyone. processname: nginx pidfile: /var/run/nginx.pid config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx"

Source function library. . /etc/rc.d/init.d/functions

Source networking configuration. . /etc/sysconfig/network

Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0

Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL }

Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] &&rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } reload() { echo -n $"Reloading $prog: " #kill -HUP cat ${nginx_pid} killproc $nginxd -HUP RETVAL=$? echo }

See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL :wq! #保存退出 #chmod 775 /etc/rc.d/init.d/nginx 赋予文件执行权限 #chkconfig nginx on 设置开机启动 #/usr/local/nginx/sbin/nginx -s reload 重新加载nginx #/etc/rc.d/init.d/nginx restart 重启nainx #service nginx restart 也是重启nainxne命令

三.安装mysql (1)#cd /data 然后把对应的安装包丢进里面 #tarxf mysql-5.5.45.tar.gz #cd mysql-5.5.45 cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/data
-DSYSCONFDIR=/etc
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci #make&& make install 进行编译

(2)配置mysql #cat /etc/passwd 查看用户列表 #cat /etc/group 查看用户组列表 如果没有就创建用户 #Groupadd mysql #useradd -g mysqlmysql #chsh mysql -s /sbin/nologin 禁止mysql用户登录系统 #chown -R mysql:mysql /usr/local/mysql 修改/usr/local/mysql权限 初始化配置,进入安装路径 #cd /usr/local/mysql 进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表 (如果更改安装目录,请修改以下的目录 scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置! 注意:在CentOS 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。 在使用"yum update"更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题 #mv /etc/my.cnf /etc/my_bak.cnf

启动MySQL 添加服务,拷贝服务脚本到init.d目录,并设置开机启动 #cp support-files/mysql.server /etc/init.d/mysql #chkconfig mysql on #service mysql start

(3)配置用户 MySQL启动成功后,root默认没有密码,我们需要设置root密码。 设置之前,我们需要先设置PATH,要不不能直接调用mysql 修改/etc/profile文件,在文件末尾添加 #vi /etc/profile PATH=/usr/local/mysql/bin:$PATH export PATH 保存退出,运行下面的命令,让配置立即生效 #source /etc/profile 现在,我们可以在终端内直接输入mysql进入,mysql的环境了 执行下面的命令修改root密码 #mysql -uroot mysql> mysql> set password for root@localhost = password('123456'); 若要设置root用户可以远程访问,执行 mysql> GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; 四.安装PHP (1)#cd /data 然后把对应的安装包丢进里面 #cd php-5.6.26 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir=/usr/local/jpeg/ --with-png-dir=/usr/local/png --with-freetype-dir=/usr/local/freetype #make 编译PHP #make install

(2)配置PHP #cp php.ini-production /usr/local/php/etc/php.ini#复制php配置文件到安装目录 #rm -rf /etc/php.ini #删除系统自带配置文件 #ln -s /usr/local/php/etc/php.ini /etc/php.ini#添加软链接 #cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件 #vi /usr/local/php/etc/php-fpm.conf #编辑 user = www #设置php-fpm运行账号为www group = www #设置php-fpm运行组为www pid = run/php-fpm.pid #取消前面的分号 :wq!保存退出 设置php-fpm开机启动 #cp /data/php-5.6.26/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录 #chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限 #chkconfig php-fpm on #设置开机启动 #vi /usr/local/php/etc/php.ini #编辑配置文件 在disable_functions =编辑文件里加入 passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname #wq 保存退出 五.配置nginx支持PHP环境 #vi /usr/local/nginx/conf/nginx.conf user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错 index index.php index.html index.htm; #添加index.php

pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Include fastcgi_params; } 取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数, 改为$document_root$fastcgi_script_name,或者使用绝对路径 #/etc/init.d/nginx restart 重启nginx #cd /usr/local/nginx/html/ 进入nginx默认网站根目录 #rm -rf /usr/local/nginx/html/* 删除默认测试页 #vi index.ph 编辑加入下面一段 <?php phpinfo(); ?> :wq! 保存退出 #chown www.www /usr/local/nginx/html/ -R 设置目录所有者 #chmod 700 /usr/local/nginx/html/ -R 设置目录权限 #shutdown -r now 重启系统 重启后生效: 开启 #chkconfig iptables on 关闭 #chkconfig iptables off 六.安装zabbix (1)#cd /data 然后把对应的安装包丢进里面

tar xf zabbix-3.4.12.tar.gz 进入目录,在编译之前安装好依赖包 [root@localhost src]# cd zabbix-3.4.3 [root@localhost zabbix-3.4.3]# yum install -y mysql-devel gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml unixODBC-devel OpenIPMI-devel libxml2-devel libevent-devel

(2)新建一个zabbix账户:.、 #useradd zabbix -s /sbin/nologin

(3)创建zabbix数据库、并赋给zabbix权限: #mysql -uroot -p密码 mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) mysql> grant all on zabbix.* to zabbix@localhost identified by 'zabbix'; Query OK, 0 rows affected (0.02 sec) mysql> flush privileges;

(4)下载zabbix,并且导入数据库,

cd /data/zabbix-3.4.12

cd database/mysql/

mysql -uzabbix -pzabbix zabbix < schema.sql

mysql -uzabbix -pzabbix zabbix < images.sql

mysql -uzabbix -pzabbix zabbix < data.sql

(5)编译安装zabbix_server: [root@monitor zabbix-3.4.12]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc --prefix=/usr/local/zabbix [root@localhost zabbix-3.4.12]# make && make install

(6)编辑nginx.conf支持index.php [root@monitor zabbix-3.4.12]# vim /usr/local/nginx/conf/nginx.conf location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }

(7)修改zabbix文件对应的数据库账号和密码: [root@localhost zabbix-3.4.12]# vim /usr/local/zabbix/etc/zabbix_server.conf DBName=zabbix DBUser=zabbix DBPassword=zabbix

(8)复制启动脚本,并修改相应选项: [root@localhost zabbix-3.4.12]# cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/ [root@localhost zabbix-3.4.12]# cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/

(9)修改两个配置文件把 [root@localhost zabbix-3.4.12]# vim /etc/init.d/zabbix_agentd ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"改成ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd" [root@localhost zabbix-3.4.12]# vim /etc/init.d/zabbix_server ZABBIX_BIN="/usr/local/sbin/zabbix_server"改成ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"

启动: [root@localhost zabbix-3.4.12]# /etc/init.d/zabbix_server start [root@localhost zabbix-3.4.12]# /etc/init.d/zabbix_agentd start [root@localhost zabbix-3.4.12]# chkconfig zabbix_agentd on [root@localhost zabbix-3.4.12]# chkconfig zabbix_server on

修改php.ini文件支持大小,不然web也没容易报错: [root@localhost zabbix-3.4.12]# vim /etc/php.ini max_execution_time = 300 max_input_time = 300 date.timezone =Asia/Shanghai post_max_size = 32M · # vim /etc/php.ini always_populate_raw_post_data = -1 把前面的分号取消掉 重启httpd使php配置生效

复制zabbix的php项目早http目录下,并且给权限: [root@localhost zabbix-3.4.12]# cp -rf frontends/php /usr/local/nginx/html/zabbix [root@localhost zabbix-3.4.12]# chown -R nginx:nginx /usr/local/nginx/html/zabbix/ [root@localhost zabbix-3.4.12]# /usr/local/nginx/sbin/nginx -s reload -s参数包含四个命令分别是 stop/quit/reopen/reload [root@localhost zabbix-3.4.12]# ps -ef |grep php |awk '{print $2}' |xargs kill -9 kill: sending signal to 15570 failed: No such process [root@localhost zabbix-3.4.12]# /usr/local/php/sbin/php-fpm -c /etc/php.ini &

通过网页访问:http://192.168.163.189/zabbix/zabbix.php

这样我们就可以使用中文界面,但我们会发现,有些界面中文是乱码的,所以,我们还要修改字体,在我们的电脑拉取字体上传到zabbix服务器 C:\Windows\Fonts\simkai.ttf

下面的路径是你zabbix放置的web路径 将该字体替换掉当前字体 [root@localhost local]# cd /usr/local/nginx/html/zabbix/fonts/ [root@localhost fonts]# ls DejaVuSans.ttf.bak simkai.ttf

在配置文件中,让其支持中文字体,修改为true [root@localhost fonts]# vim /usr/local/nginx/html/zabbix/include/locales.inc.php 'zhCN' => ['name' => ('Chinese (zh_CN)'), 'display' => true],

最后还要将字体指定为simkai.ttf [root@localhost include]# vim /usr/local/nginx/html/zabbix/include/defines.inc.php define('ZBX_GRAPH_FONT_NAME', 'simkai'); // font file name 或者不改这个配置文件,直接将simkai.ttf 改名为 DejaVuSans.ttfls

1、打开zabbix web界面点击profile出现以下报错信息: scandir() has been disabled for security reasons [profile.php:198 → CView-> 解决: php环境中把scandir写在了disable_functions中。在php.ini文件把disable_functions中的scandir去掉即可。 (重启php-fpm和nginx) https://blog.csdn.net/u011289501/article/details/49303747

C:\zabbix\zabbix_agentd.exe -i -c C:\zabbix\zabbix_agentd.win.conf C:\zabbix\zabbix_agentd.exe -s -c C:\zabbix\zabbix_agentd.win.conf

留意异常关闭,开启需要删除nginx.pid cd /usr/local/nginx/logs/