Zabbix Server 4.2.0 安装(Mysql8.0 + Php72 + Nginx1.14.2)
#安装依赖环境
yum install curl curl-devel net-snmp net-snmp-devel perl-DBI ntddate libxml2-devel libevent-devel yum-utils pcre pcre-devel openssl openssl-devel zlib zlib-devel gcc gcc-c++
安装java
yum list java* yum install -y java-1.8*
#添加zabbix用户
useradd zabbix
下载zabbix源码并解压
wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.2.0/zabbix-4.2.0.tar.gz tar zxvf zabbix-4.2.0.tar.gz
一、安装mysql8.0数据库并导入数据
1、安装
yum仓库下载MySQL:
yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum安装MySQL:
yum install mysql-community-server mysql-community-devel mysql-connector-c++-devel
启动MySQL服务:
systemctl start mysqld
检查MySQL服务状态:
systemctl status mysqld
查看初始密码(如无内容直接跳过):
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log 2019-04-10T11:46:17.947193Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: yf*wL6H(ZNoV
2、 创建zabbix数据库及账号
mysql -uroot -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
创建zabbix数据库
create database zabbix default character set utf8;
创建本地用户和远程用户(需要使用native的用户认证方式)
create user 'zabbix'@'localhost' identified with mysql_native_password by 'Zabbix@1234'; create user 'zabbix'@'127.0.0.1' identified with mysql_native_password by 'Zabbix@1234'; create user 'zabbix'@'%' identified with mysql_native_password by 'Zabbix@1234';
给zabbix数据库授权
grant all privileges on zabbix.* to "zabbix"@"localhost"; grant all privileges on zabbix.* to "zabbix"@"127.0.0.1" ; grant all privileges on zabbix.* to "zabbix"@"%" ; flush privileges; exit
导入zabbix初始化数据
cd zabbix-4.2.0 mysql -uzabbix -pZabbix@1234 zabbix < database/mysql/schema.sql mysql -uzabbix -pZabbix@1234 zabbix < database/mysql/images.sql mysql -uzabbix -pZabbix@1234 zabbix < database/mysql/data.sql
二、安装php72
安装php72的源
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum install remi-release-7.rpm
安装php72
yum install -y php72-php-devel php72-php-fpm php72-php-mbstring php72-php-memcache php72-php-redis php72-php-mysqli php72-php-mysqlnd php72-php-pdo php72-php-bcmath php72-php-dom php72-php-gd php72-php-gmp php72-php-igbinary php72-php-imagick php72-php-mcrypt php72-php-pdo_mysql php72-php-posix php72-php-simplexml php72-php-opcache php72-php-xsl php72-php-xmlwriter php72-php-xmlreader php72-php-xml php72-php-swoole php72-php-zip php72-php-fileinfo
查看php版本
php72 -v
三、安装nginx
创建用户nginx,以该用户的身份执行nginx
cd ~ useradd -s /bin/false -M nginx
下载nginx源码包并解压到当前目录
wget http://nginx.org/download/nginx-1.14.2.tar.gz tar -zxf nginx-1.14.2.tar.gz
编译安装
生成Makefile文件
cd nginx-1.14.2 ./configure --user=nginx --group=nginx --prefix=/opt/nginx/ --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module
编译源代码并安装
make && make install
创建nginx命令软链接到环境变量
ln -s /opt/nginx/sbin/* /usr/local/sbin/
四、安装zabbix
创建zabbix agent日志目录,并授权zabbix用户
mkdir /var/log/zabbix/ && chown zabbix:zabbix /var/log/zabbix
编译安装
cd ~ cd zabbix-4.2.0 ./configure --prefix=/usr/local/zabbix --sysconfdir=/opt/zabbix --enable-server --enable-agent --with-net-snmp --enable-java --with-libxml2 --with-libcurl --with-libxml2 --with-mysql make && make install
参照如下参数修改zabbix server的配置文件
vim /opt/zabbix/zabbix_server.conf LogFile=/var/log/zabbix/zabbix_server.log PidFile=/tmp/zabbix_server.pid DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix DBSocket=/var/lib/mysql/mysql.sock Timeout=30 AlertScriptsPath=/opt/zabbix/scripts LogSlowQueries=3000 JavaGateway=127.0.0.1 JavaGatewayPort=10052 StartJavaPollers=5
拷贝启动文件并授权
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ cp misc/init.d/fedora/core/zabbix_server /etc/init.d/ chmod +x /etc/init.d/zabbix_agentd chmod +x /etc/init.d/zabbix_server
根据安装目录修改zabbix_server和zabbix_agentd启动目录
vim /etc/init.d/zabbix_agentd vim /etc/init.d/zabbix_server BASEDIR=/usr/local 修改成下面的安装目录 BASEDIR=/usr/local/zabbix
启动zabbix_agent和zabbix_server
systemctl start zabbix_agentd systemctl start zabbix_server
五、安装web界面
修改php配置
vim /etc/opt/remi/php72/php.ini
配置如下
max_execution_time=300 memory_limit=128M post_max_size=16M upload_max_filesize=8M max_input_time=300 session.auto_start = 0 mbstring.func_overload = 0 date.timezone="Asia/Shanghai" always_populate_raw_post_data=-1 #添加
拷贝zabbi web到httpd目录
mkdir /var/www/html -p cp -a frontends/php/* /var/www/html
配置nginx,创建一个新的配置文件和配置文件目录
mv /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.bak mkdir /opt/nginx/conf/vhosts vim /opt/nginx/conf/nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log; #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 /opt/nginx/conf/vhosts/*.conf; }
在/opt/nginx/conf/vhosts里添加server{}字段
vim /opt/nginx/conf/vhosts/zabbix.conf server{ listen 80; server_name 192.168.230.102; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~.php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|css|htm|bmp|js|svg)$ { root /var/www/html; } }
启动nginx和php72-php-fpm
systemctl start php72-php-fpm systemctl enable php72-php-fpm nginx -c /opt/nginx/conf/nginx.conf
目录 返回
首页