PHP编译参考
为了减少不必要的支持库报错,最好先安装执行编译前需要的支持库软件
yum install -y net-snmp net-snmp-devel libcurl-devel libevent-devel java* openldap-devel && cp -frp /usr/lib64/libldap* /usr/lib/
php编译安装参数参考
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/loca/php-pfm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysqli=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl --enable-bcmath --enable-sockets --with-gettext --with-ldap --with-crypt
zabbix安装(上)
首先到官网去下载希望部署的zabbix版本
官网地址:www.zabbix.com
下载后执行解压,把tar.gz的打包文件解压出来
[root@localhost src]# wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.13/zabbix-3.4.13.tar.gz
--2018-09-10 17:03:18-- https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.13/zabbix-3.4.13.tar.gz
Resolving jaist.dl.sourceforge.net (jaist.dl.sourceforge.net)... 150.65.7.130, 2001:df0:2ed:feed::feed
Connecting to jaist.dl.sourceforge.net (jaist.dl.sourceforge.net)|150.65.7.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17507365 (17M) [application/x-gzip]
Saving to: ‘zabbix-3.4.13.tar.gz’
100%[====================================================>] 17,507,365 43.5KB/s in 8m 39s
2018-09-10 17:11:58 (33.0 KB/s) - ‘zabbix-3.4.13.tar.gz’ saved [17507365/17507365]
[root@localhost src]# tar zxf zabbix-3.4.13.tar.gz -C .
进入解压目录执行zabbix的安装编译参数,如确少某个支持插件,请安装报错信息分析并安装该支持库或插件
为了减少不必要的支持库报错,最好先安装执行编译前需要的支持库软件
yum install -y net-snmp net-snmp-devel libcurl-devel libevent-devel java* openldap-devel && cp -frp /usr/lib64/libldap* /usr/lib/
安装ladp插件后需要拷贝命令路径 cp -frp /usr/lib64/libldap* /usr/lib/ 然后再执行./configure
[root@localhost zabbix-3.4.13]# yum install -y net-snmp net-snmp-devel libcurl-devel libevent-devel java* openldap-devel && cp -frp /usr/lib64/libldap* /usr/lib/
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.yun-idc.com
Package libcurl-devel-7.29.0-46.el7.x86_64 already installed and lates
进入解压目录后执行需要的编译选项等参数
./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --enable-java
如需要监控tomcat服务,需要添加JMX监控支持 --enable-java
如果编译报错configure: error: Unable to find "javac" executable in path 就是添加--enable-java后没有支持库造成的
这时候就需要安装sudo yum install java*安装一下
执行过程
[root@localhost src]# tar zxf zabbix-3.4.13.tar.gz -C .
[root@localhost src]# cd zabbix-3.4.13
[root@localhost zabbix-3.4.13]# ls
aclocal.m4 build conf configure database include m4 man NEWS src
AUTHORS ChangeLog config.guess configure.ac depcomp INSTALL Makefile.am misc README upgrades
bin compile config.sub COPYING frontends install-sh Makefile.in missing sass
[root@localhost zabbix-3.4.13]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --enable-java
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
--------------------省略
Configuration: 这里可以看下zabbix开启的各项功能和没开启的支持
Detected OS: linux-gnu
Install path: /usr/local/zabbix
Compilation arch: linux
Compiler: gcc
Compiler flags: -g -O2
--------------省略
Enable Java gateway: yes
Java gateway details:
Java compiler: javac
Java archiver: jar
LDAP support: no
IPv6 support: no
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* *
***********************************************************
configure完成后再对解压目录执行make和make install来完成安装
至此zabbix编译安装完成,接下来就是创建运行用户、配置文件和在数据库中导入zabbix的初始数据表,这些完成后zabbix才能正常显示页面给我们
[root@localhost zabbix-3.4.13]# make && make install
---------------省略执行过程
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/local/src/zabbix-3.4.13'
make[1]: Leaving directory `/usr/local/src/zabbix-3.4.13'
[root@localhost zabbix-3.4.13]# echo $?
0
接下来创建zabbix运行用户,不允许用户登录、不创建用户家目录
[root@localhost /]# useradd -M zabbix -s /sbin/nologin
在解压的zabbix目录下找到frontends/php这个目录,它下面存放的是zabbix的网页源码文件,需要拷贝到安装目录/usr/local/zabbix目录下,在/usr/local/zabbix安装目录下,需要定义一个站点文件存放的目录,这个在后面配置也会提及
[root@localhost zabbix-3.4.13]# cp -rf /usr/local/src/zabbix-3.4.13/frontends/php /usr/local/zabbix/php
[root@localhost zabbix-3.4.13]# ll -h !$
ll -h /usr/local/zabbix/php
total 1.2M
-rw-r--r-- 1 root root 31K Sep 10 17:51 actionconf.php
-rw-r--r-- 1 root root 4.4K Sep 10 17:51 adm.gui.php
---------省略
把zabbix的安装目录给予zabbix的用户所属组所属主权限
[root@localhost zabbix]# chown -R zabbix:zabbix /usr/local/zabbix/
[root@localhost zabbix]# ll -h
total 4.0K
drwxr-xr-x 2 zabbix zabbix 45 Sep 11 13:15 bin
drwxr-xr-x 5 zabbix zabbix 166 Sep 11 13:15 etc
drwxr-xr-x 2 zabbix zabbix 6 Sep 11 13:15 lib
drwxr-xr-x 14 nobody nobody 4.0K Sep 11 13:43 php
把php网页源码文件则全部给予nobody用户所属主所属组权限,查看网页源码文件权限(以一个文件来判断)
[root@localhost zabbix-3.4.13]# chown -R nobody:nobody /usr/local/zabbix/php/*
[root@localhost zabbix-3.4.13]# ll /usr/local/zabbix/php/adm.gui.php
-rw-r--r-- 1 nobody nobody 4426 Sep 10 17:51 /usr/local/zabbix/php/adm.gui.php
数据库上的操作
登入数据库服务器,创建zabbix使用的库,然后授权安装zabbix那台服务器的访问用户、密码和ip地址,授权ip是安装zabbix的服务器ip,如果zabbix和数据库同用一台服务器的话,那么授权对象可以是本机回环地址或者localhost
mysql> create database zabbix;
Query OK, 1 row affected (0.03 sec)
mysql> grant all on zabbix.* to zabbix_user@192.168.1.234 identified by 'xiang@123';
Query OK, 0 rows affected, 1 warning (0.12 sec)
把zabbix安装目录下的zabbix初始的库表导入刚刚创建的zabbix空库中,初始库表一般在zabbix解压后的tar.gz目录下,所以安装过程中这个目录不要着急着先删除,这样的话你会找不到需要的文件的
[root@localhost mysql]# pwd
/usr/local/src/zabbix-3.4.13/database/mysql
[root@localhost mysql]# ls
data.sql images.sql schema.sql
把sql语句导入数据库,这里导入zabbix库时需要注意的是,导入数据库执行这些sql文件是按照顺序来的,否则导入会提示没有这个字段或其他字段的数据,这是因为一开始的表结构就没有建好,需要安装下面参考严格去导入sql执行文件
[root@localhost mysql]~ mysql -uroot -ppwd@123 zabbix
[root@localhost mysql]~ mysql -uroot -ppwd@123 zabbix
[root@localhost mysql]~ mysql -uroot -ppwd@123 zabbix
sql数据创建完成后我们再给zabbix拷贝服务启动文件,并给予可执行权限。如果还要想监控zabbix本机的话,需要拷贝zabbix_agentd的启动文件,而zabbix_agentd在编译时也是已近安装过了的
[root@localhost /]# cp /usr/local/src/zabbix-3.4.13/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
[root@localhost /]# chmod +x /etc/init.d/zabbix_server
[root@localhost /]# cp /usr/local/src/zabbix-3.4.13/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
[root@localhost /]# chmod +x /etc/init.d/zabbix_agentd
修改配置文件的三个步骤(三个配置文件需要修改)
步骤一
为了减少错误,如果你的安装路径在/usr/local/zabbix这个目录,请直接复制下面的启动文件直接命名为/etc/init.d/zabbix_server
[root@localhost /]# mkdir /usr/local/zabbix/src
#!/bin/bash
. /etc/init.d/functions
BASEDIR=/usr/local/zabbix
BINARY_NAME=zabbix_server
FULLPATH=$BASEDIR/sbin/$BINARY_NAME
PIDFILE=/tmp/$BINARY_NAME.pid
ERROR=0
STOPPING=0
if [ -f $PIDFILE ] && [ -s $PIDFILE ]
then
PID=`cat $PIDFILE`
if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null && [ $BINARY_NAME == `ps -e | grep $PID | awk '{print $4}'` ]
then
STATUS="$BINARY_NAME (pid `pidof $APP`) running.."
RUNNING=1
else
rm -f $PIDFILE
STATUS="$BINARY_NAME (pid file existed ($PID) and now removed) not running.."
RUNNING=0
fi
else
if [ `ps -e | grep $BINARY_NAME | head -1 | awk '{ print $1 }'` ]
then
STATUS="$BINARY_NAME (pid `pidof $APP`, but no pid file) running.."
else
STATUS="$BINARY_NAME (no pid file) not running"
fi
RUNNING=0
fi
# functions
start() {
if [ $RUNNING -eq 1 ]
then
echo "$0 $ARG: $BINARY_NAME (pid $PID) already running"
else
action $"Starting $BINARY_NAME: " $FULLPATH
touch /usr/local/zabbix/src/$BINARY_NAME
fi
}
stop() {
echo -n $"Shutting down $BINARY_NAME: "
killproc $BINARY_NAME
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /usr/local/zabbix/src/$BINARY_NAME
RUNNING=0
}
# logic
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $BINARY_NAME
;;
restart)
stop
sleep 10
start
;;
help|*)
echo $"Usage: $0 {start|stop|status|restart|help}"
cat <
start - start $BINARY_NAME
stop - stop $BINARY_NAME
status - show current status of $BINARY_NAME
restart - restart $BINARY_NAME if running by sending a SIGHUP or start if not running
help - this screen
EOF
exit 1
;;
esac
exit 0
步骤二
修改zabbix_server的服务配置文件,指定提供数据存储的数据库服务器ip,指定在数据库中授权zabbix访问的库、用户和密码
指定zabbix监听端口,默认10051,可自定义修改成其他端口号
[root@localhost zabbix]# vim /usr/local/zabbix/etc/zabbix_server.conf
ListenPort=10051
DebugLevel=1
LogFile=/tmp/zabbix_server.log
DBHost=192.168.1.234
DBName=zabbix
DBUser=zabbix
DBPassword=xiang@123
说明
DebugLevel=5 错误日志记录级别,用于安装时排查错误,日志保存在LogFile定义的目录,如这里的/tmp/zabbix_server.log
默认设置为空
0 - Zabbix进程启动和停止的基本信息
1 -关键信息
2 -错误信息
3 -警告
4 -调试(产生大量信息)
5 -扩展调试(产生更多信息)
步骤三
配置zabbix的php源码文件页面中的配置文件,指定zabbix连接用户的账户和服务器ip等信息,指定zabbix监听端口,默认10051,可自定义修改成其他端口号
[root@localhost tmp]# vim /usr/local/zabbix/php/conf/zabbix.conf.php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '192.168.1.234';
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix_user';
$DB['PASSWORD'] = 'xiang@123';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = '127.0.0.1';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
zabbix安装(中)
访问zabbix设置页面,有时会出现检查不通过的情况,按照报错修改php.ini的配置文件大都能解决这个问题,不过在这里我修改了php.ini文件,但是重启php后还是报错这些信息,php的配置未生效
上面遇到的报错可以修改php-fpm.conf这个文件,把报错的项写入配置文件中也是可以的,重启php后检测通过
[root@localhost etc]# vim php-fpm.conf
php_admin_value[post_max_size] = 32M
php_admin_value[max_execution_time] = 300
php_admin_value[date.timezone] = 'Asia/Shanghai'
设置链接数据库的信息(授权访问的用户名和密码)
php访问的页面配置文件报错,在这个路径下创建该文件,文件所属主所属组为nobody,即nginx的运行用户,配置文件内容可以在本章中找到。注意,这个文件设置为777权限才能正常被zabbix加载
安装过程中报错小结
检查mysqlclient库支持,如果出现问题,需要拷贝数据库配置中的so.文件到/usr/lib64目录当中
[root@localhost sbin]# ./usr/loca/zabbix/etc/zabbix_server
./zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
[root@localhost sbin]# cp /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20
按照这篇文章直接复制/etc/init.d/zabbix_server文件就不会可能出现这个错误
这里报错的
zabbix_server[3746]: Starting zabbix_server: /etc/init.d/functions: line 573: /usr/local/zabbix/zabbix/sbi...rectory
表明在启动文件找不到所安装的zabbix启动文件的路径,需要确认启动脚本中的服务安装路径与你的zabbix实际路径要一致
如遇到启动无报错但是没有zabbix进程和监听端口的,也是这个原因,因为启动脚本执行这个路径时不会把报错信息直接输出到终端里显示
[root@localhost tmp]# systemctl status zabbix_server.service
● zabbix_server.service - SYSV: Starts and stops Zabbix Server using chkconfig
Loaded: loaded (/etc/rc.d/init.d/zabbix_server; bad; vendor preset: disabled)
Active: active (exited) since Tue 2018-09-11 22:57:19 CST; 8s ago
Docs: man:systemd-sysv-generator(8)
Process: 3746 ExecStart=/etc/rc.d/init.d/zabbix_server start (code=exited, status=0/SUCCESS)
Sep 11 22:57:19 localhost.localdomain systemd[1]: Starting SYSV: Starts and stops Zabbix Server using chkconfig...
Sep 11 22:57:19 localhost.localdomain zabbix_server[3746]: Starting zabbix_server: /etc/init.d/functions: line 573: /usr/local/zabbix/zabbix/sbi...rectory
Sep 11 22:57:19 localhost.localdomain zabbix_server[3746]: [FAILED]
Sep 11 22:57:19 localhost.localdomain systemd[1]: Started SYSV: Starts and stops Zabbix Server using chkconfig.
Hint: Some lines were ellipsized, use -l to show in full.
systemctl启动警告,这是因为zabbix_server还没有在systemctl的运行库中建立服务启动,按照提示执行systemctl daemon-reload就可以了
[root@localhost tmp]# systemctl start zabbix_server.service
Warning: zabbix_server.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@localhost tmp]# systemctl daemon-reload
zabbix启动后在访问默认主页要配置的时候,报了一个php函数错误
在编译php时添加--enable-bamath编译参数
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/loca/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysqli=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl --enable-bamath
make编译过程中报错ldap.o的模块支持
/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_scanf'
/usr/bin/ld: note: 'ber_scanf' is defined in DSO /lib64/liblber-2.4.so.2 so try adding it to the linker command line
/lib64/liblber-2.4.so.2: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
libtool: unrecognized option `-export-dynamic'
Try `libtool --help' for more information.
make: *** [sapi/cli/php] Error 1
/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_scanf'
/usr/bin/ld: note: 'ber_scanf' is defined in DSO /lib64/liblber-2.4.so.2 so try adding it to the linker command line
/lib64/liblber-2.4.so.2: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
解决办法
./configure后
在编译的目录找到并编辑MakeFile文件
找到 开头是 'EXTRA_LIBS' 这一行 在结尾加上 '-llber'
然后执行 make && make install
zabbix忘记密码
zabbix忘记密码,登入数据库修改密码,zabbix的密码是使用md5加密算法加密的,需要用到密码转换工具
[root@localhost php-7.1.21]# echo -n pwd@123 | openssl md5
(stdin)= b757f97c9ff375ae14b1260e690fb210
[root@localhost php-7.1.21]# mysql -uroot -p
mysql> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update users set passwd='b757f97c9ff375ae14b1260e690fb210' where userid = '1';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
zabbix安装(下)
启动监控服务器端的zabbix_server的服务
[root@localhost src]# /etc/init.d/zabbix_server start
Starting zabbix_server (via systemctl): [ OK ]
[root@localhost src]# netstat -ntlp
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:80 0.0.0.0:* LISTEN 2331/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2040/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2429/master
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 96149/zabbix_server
tcp6 0 0 :::3306 :::* LISTEN 2620/mysqld
tcp6 0 0 :::22 :::* LISTEN 2040/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2429/master
被监控服务器上安装zabbix_agentd客户端
下载或拷贝到相同的zabbix的tar包,解压到/usr/local/src/目录下,执行./configure....编译安装
[root@localhost zabbix-3.4.13]# ./configure --prefix=/usr/local/zabbix_agentd --enable-agent
------------省略内容
LDAP support: no
IPv6 support: no
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* *
***********************************************************
[root@localhost zabbix-3.4.13]# make && make install
Making all in src
make[1]: Entering directory `/usr/local/src/zabbix-3.4.13/src'
Making all in libs
make[2]: Entering directory `/usr/local/src/zabbix-3.4.13/src/libs'
创建zabbix运行用户并设置安装目录的属主属组,拷贝zabbix_agentd的服务启动文件来启动客户端监听进程
[root@localhost zabbix-3.4.13]# useradd -M -s /sbin/nologin zabbix
[root@localhost zabbix-3.4.13]# cp /usr/local/zabbix_agentd/sbin/zabbix_agentd /etc/init.d/zabbix_agentd
[root@localhost zabbix-3.4.13]# chmod +x /etc/init.d/zabbix_agentd
[root@localhost zabbix-3.4.13]# /etc/init.d/zabbix_agentd start
[root@localhost zabbix-3.4.13]# ps -aux |grep zabbix
编辑zabbix_agentd的配置文件,来和服务器进行通信,服务监听最少配置如下
server指定服务端监听的ip地址,只允许这个ip来读取监控数据 serveractive指定主动模式还是被动模式的监听ip,如果设置为127.0.01这种的ip,则只能使用被动模式,需要等服务器端来拉取请求数据
Hostname 在zabbix监控添加的时候需要指定的主机名,主动模式下在zabbix内结合监听ip来填写,被监控的服务器主机名对应服务器ip,监控数据收集上来后zabbix才能够正确判断这些数据都是哪台服务器的
[root@localhost zabbix-3.4.13]# vim /usr/local/zabbix_agentd/etc/zabbix_agentd.conf
Server=192.168.1.234
ServerActive=192.168.1.234
Hostname=www.host.1
启动服务并查看zabbix_agentd监听的ip
[root@localhost zabbix-3.4.13]# /etc/init.d/zabbix_agentd
[root@localhost zabbix-3.4.13]# ps -aux |grep zabbi
zabbix 12859 0.0 0.0 18828 744 ? S 13:43 0:00 /etc/init.d/zabbix_agentd
zabbix 12860 0.0 0.0 18828 796 ? S 13:43 0:00 /etc/init.d/zabbix_agentd: collector [idle 1 sec]
zabbix 12861 0.0 0.0 18828 488 ? S 13:43 0:00 /etc/init.d/zabbix_agentd: listener #1 [waiting for connection]
zabbix 12862 0.0 0.0 18828 488 ? S 13:43 0:00 /etc/init.d/zabbix_agentd: listener #2 [waiting for connection]
zabbix 12863 0.0 0.0 18828 488 ? S 13:43 0:00 /etc/init.d/zabbix_agentd: listener #3 [waiting for connection]
zabbix 12864 0.0 0.0 18828 848 ? S 13:43 0:00 /etc/init.d/zabbix_agentd: active checks #1 [idle 1 sec]
root 12866 0.0 0.0 112652 960 pts/0 R+ 13:43 0:00 grep --color=auto zabbi
[root@localhost zabbix-3.4.13]# netstat -ntlp
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 1586/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2416/master
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 12859/zabbix_agentd
tcp6 0 0 :::22 :::* LISTEN 1586/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2416/master