博主本人热爱学习,读者阅读过程中如果发现有错误的地方或是有更好的实现方式,请与本人联系(qq:1805608587),或是在评论区留言,谢谢!
文章说明:本文是作者原创,请尊重个人劳动成果,转载需注明出处
说明:在MySQL5.7.x、NGINX1.4.x安装完成的基础上进行zabbix的安装。由于zabbix需要LAMP或是LNMP的环境,所以还必须安装PHP。
1.PHP7安装
PHP7
官网:https://www.php.net/downloads.php
本次下载版本:
https://www.cnblogs.com/phpshangxiaobai/p/10864525.html
1.1.环境准备
[root@lnmp01 ~]# cd /opt/php/
[root@lnmp01 php]# yum install epel-release -y
[root@lnmp01 php]# yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel mysql-devel
[root@lnmp01 php]# groupadd www
[root@lnmp01 php]# useradd -g www ww
1.2.编译安装
[root@lnmp01 php]# tar -zxvf php-7.2.0.tar.gz
[root@lnmp01 php]# cd php-7.2.0/
[root@lnmp01 php-7.2.0]# cp -frp /usr/lib64/libldap* /usr/lib/
[root@lnmp01 php-7.2.0]# mkdir -p /data/webserver/php
[root@lnmp01 php-7.2.0]# ./configure --prefix=/data/webserver/php --with-config-file-path=/data/webserver/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-mcrypt --with-libmbfl --enable-ftp --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm
[root@lnmp01 php-7.2.0]# make -j 8
[root@lnmp01 php-7.2.0]# make install
[root@lnmp01 php-7.2.0]# cp php.ini-development /data/webserver/php/etc/php.ini
[root@lnmp01 php-7.2.0]# cp /data/webserver/php/etc/php-fpm.conf.default /data/webserver/php/etc/php-fpm.conf
[root@lnmp01 php-7.2.0]# cp /data/webserver/php/etc/php-fpm.d/www.conf.default /data/webserver/php/etc/php-fpm.d/www.conf
[root@lnmp01 php-7.2.0]#
1.3.设置环境变量
[root@lnmp01 nginx]# vim /etc/profile
export php=/data/webserver/php/sbin
export PATH=$PATH:$php
[root@lnmp01 nginx]# source /etc/profile
[root@lnmp01 nginx]# php-fpm
[root@lnmp01 nginx]# netstat -ntulp|grep 9000
2.MySQL设置
2.1.创建zabbix账户密码
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create database zabbix character set u^C8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to 'zabbix'@'%' identified by '123456';
mysql> flush privileges;
2.2.导入数据
[root@lnmp01 ~]# cd /opt/zabbix/zabbix-4.4.7/database
[root@lnmp01 database]# cd mysql/
[root@lnmp01 mysql]# mysql -uzabbix -p123456 -h localhost zabbix <schema.sql
[root@lnmp01 mysql]# mysql -uzabbix -p123456 -h localhost zabbix <images.sql
[root@lnmp01 mysql]# mysql -uzabbix -p123456 -h localhost zabbix <data.sql
3.NGINX设置
zabbix
官网:https://www.zabbix.com/cn/download
3.1.配置NGINX支持PHP文件
(安装完成PHP后进行)
[root@lnmp01 ~]# cd /usr/local/nginx/conf/
[root@lnmp01 conf]# mv nginx.conf nginx.conf.bak
[root@lnmp01 conf]# cat nginx.conf.bak |grep -v '#'|grep -v ^$>nginx.conf
[root@lnmp01 conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
index index.html index.php index.html;
root /data/zabbix/ ;
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;
}
location ~ /status {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
[root@lnmp01 conf]#
3.2.测试验证
4.zabbix4.4安
4.1.编译安装
[root@lnmp01 zabbix]# pwd
/opt/zabbix
[root@lnmp01 zabbix]# tar -zxvf zabbix-4.4.7.tar.gz
[root@lnmp01 zabbix]# cd zabbix-4.4.7/
[root@lnmp01 zabbix-4.4.7]# groupadd zabbix
[root@lnmp01 zabbix-4.4.7]# useradd -g zabbix zabbix
[root@lnmp01 zabbix-4.4.7]# mkdir -p /usr/local/zabbix
[root@lnmp01 zabbix-4.4.7]# find / -name "mysql_config"
[root@lnmp01 zabbix-4.4.7]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql=/usr/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
[root@lnmp01 zabbix-4.4.7]# make -j 8
[root@lnmp01 zabbix-4.4.7]# make install
[root@lnmp01 bin]# vim /etc/profile
export zabbix01=/usr/local/zabbix/bin
export PATH=$PATH:$zabbix01
export zabbix02=/usr/local/zabbix/sbin
export PATH=$PATH:$zabbix02
[root@lnmp01 bin]# source /etc/profile
4.2.编辑配置文件
[root@lnmp01 ~]# cd /usr/local/zabbix/etc/
[root@lnmp01 etc]# cat zabbix_server.conf|egrep -v '#|^$'
LogFile=/tmp/zabbix_server.log
DBHost=192.168.247.101
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
[root@lnmp01 etc]#
[root@lnmp01 etc]# mv zabbix_server.conf zabbix_server.conf.bak
[root@lnmp01 etc]# cat zabbix_server.conf.bak |egrep -v '#'|grep -v '^$' >zabbix_server.conf
[root@lnmp01 local]# chown -R zabbix.zabbix /usr/local/zabbix/*
启动:
[root@lnmp01 local]# zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
[root@lnmp01 local]# zabbix_agentd
[root@lnmp01 local]# netstat -ntulp|grep 1005
4.3.配置web
[root@lnmp01 ~]# mkdir -p /data/zabbix
[root@lnmp01 ~]# cp -a /opt/zabbix/zabbix-4.4.7/frontends/php/* /data/zabbix/
修改NGINX根目录:
root /data/zabbix/ ;
访问验证:
初始密码:zabbix/admin
4.4.错误
出现fail的回去调整到相应的值即可
[root@lnmp01 ~]# cat /data/webserver/php/etc/php.ini|grep -v ';'|grep -v '^$'
[PHP]
short_open_tag = ON
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = off
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 32M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
date.timezone = Asia/Shanghai
[filter]
[iconv]
[intl]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = On
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = On
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
[Assertion]
zend.assertions = 1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[dba]
[opcache]
[curl]
[openssl]
[root@lnmp01 ~]#
4.5.重启PHP
php 5.3.3 以后的php-fpm 不再支持 php-fpm 以前具有的 php-fpm (start|stop|reload)等命令,需要使用信号控制:
master进程可以理解以下信号
1.INT, TERM 立刻终止
2.QUIT 平滑终止
3.USR1 重新打开日志文件
4.USR2 平滑重载所有worker进程并重新载入配置和二进制模块
[root@lnmp01 ~]# ps -ef |grep php|grep -v grep|awk '{print $2}'|xargs kill -USR2
设置中文: