一.安装mysql,
(设置zabbix数据库字符集为utf8。)
(安装mysql8以上版本时,utf8mb3就是utf8,此处会卡在zabbix的php安装界面,可跳过界面配置。)
1.改密码:
mysql -uroot -p (初始密码为空)
alter user root@localhost identified by '123456';(修改密码)
2.允许远程访问
use mysql
update user set host=’%’ where user='root'; //改 user 表
select host,user from user; 进入user表查询
flush privileges; //刷新权限
3.创建zabbix数据库、用户名和密码
mysql>create database zabbix character set utf8 collate utf8_bin;
mysql>create user zabbix@localhost identified by '123456';
mysql>grant all privileges on zabbix.* to zabbix@localhost;
4.source 命令导入sql文件
mysql > use mydb;
mysql > source /home/gary/all.sql
5.导出sql文件
mysqldump -u username -p mydatabase > mydatabase.sql
二.安装php
需要安装php7以上版本,centos7中版本为php5,可以用rpm安装rh-php73。
三.安装zabbix
#yum install gcc golang net-snmp-devel
#yum install libxml2
#yum install libxml2-devel
#yum install openssl
#yum install openssl-devel
#yum install libcurl
#yum install libcurl-devel
#./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --enable-java --with-mysql --with-net-snmp --with-libcurl --with-libxml2
(configure 时缺啥装啥,不要忘记--enable-agent,不然还要装agent)
#make install
四.安装nginx
centos7中没有nginx的rpm 包。
1.添加Nginx到YUM源
添加CentOS 7 Nginx yum资源库,打开终端,使用以下命令:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安装Nginx
在你的CentOS 7 服务器中使用yum命令从Nginx源服务器中获取来安装Nginx:
sudo yum install -y nginx
Nginx将完成安装在你的CentOS 7 服务器中。
3.启动Nginx
刚安装的Nginx不会自行启动。运行Nginx:
sudo systemctl start nginx.service
如果一切进展顺利的话,现在你可以通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页面;
如果看到这个页面,那么说明你的CentOS 7 中 web服务器已经正确安装。
4.CentOS 7 开机启动Nginx
sudo systemctl enable nginx.service
5.Nginx配置信息
网站文件存放默认目录: /usr/share/nginx/html
网站默认站点配置: /etc/nginx/conf.d/default.conf
自定义Nginx站点配置文件存放目录: /etc/nginx/conf.d/
Nginx全局配置: /etc/nginx/nginx.conf
五.整合nginx和php
1.启动php和nginx
systemctl start nginx.service
systemctl start rh-php73-php-fpm.service
2.启动nginx欢迎界面
输入本地网址:192.168.1.28
3.修改配置文件
修改php配置文件vi /etc/opt/rh/rh-php73/php-fpm.d/www.conf
user=nginx
group=nginx
listen = 127.0.0.1:9000
修改nginx配置文件
vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;# $document_root是root指定的路径
include fastcgi_params;
}
4.配置php。vi /etc/php.ini
post_max_size=64M
max_execution_time=300
max_input_time=300
5.添加php测试页
#vim /usr/share/nginx/html/index.php
<?php
echo phpinfo();
?>
6.重启nginx和php-fpm:
#systemctl restart nginx.service
#systemctl restart rh-php73-php-fpm.service
7.访问php测试界面
http://192.168.1.28(此处IP为zabbix server IP)
六.配置zabbix服务
1.导入数据库
添加zabbix用户;导入数据库建库、配置文件(注意一定要按顺序导入,且当用于安装proxy时,仅需导入第一个即可。)
useradd zabbix -s /sbin/nologin -M
mysql -uroot -p123456 zabbix < /home/zabbix-5.2.0/database/mysql/schema.sql
mysql -uroot -p123456 zabbix < /home/zabbix-5.2.0/database/mysql/images.sql
mysql -uroot -p123456 zabbix < /home/zabbix-5.2.0/database/mysql/data.sql
2.创建zabbix前端目录
#mkdir /usr/share/nginx/html/zabbix
3.拷贝zabbix前端文件
#cp -a /home/zabbix-5.2.0/ui/* /usr/share/nginx/html/zabbix/
4.访问zabbix前端界面
http://192.168.1.28/zabbix/setup.php
根据页面提示进行操作,缺少的包补安装;缺少的*.so可在php.ini中添加
如:
extension=json.so
extension=mbstring.so
extension=gettext.so
extension=gd.so
(按步骤操作不会缺少库文件)
根据页面提示下载文件zabbix.conf.php,并拷贝到/usr/share/nginx/html/zabbix/conf/下。
注: “配置Zabbix前端”的操作中,连接数据库的时候,一直提示
Incorrect default charset for zabbix database: “utf8mb3” instead “utf8”,
遇到该问题时,可跳过zabbix前端界面,直接copy文件zabbix.conf.php,到/usr/share/nginx/html/zabbix/conf/下。
5.修改配置文件
mkdir /var/log/zabbix
chown zabbix:zabbix /var/log/zabbix/
vi /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
6.设置启动项
cp /home/zabbix-5.2.0/misc/init.d/fedora/core/* /etc/init.d/
#修改安装路径
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#' /etc/init.d/zabbix_server
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#' /etc/init.d/zabbix_agentd
service zabbix_server start
service zabbix_agentd start
chkconfig zabbix_server on
chkconfig zabbix_agentd on
systemctl restart zabbix_server.service
systemctl restart zabbix-agentd.service
7.关闭防火墙
systemctl stop firewalld.service #关闭防火墙
systemctl disable firewalld #永久关闭防火墙
8.打开zabbix界面
http://192.168.1.28/zabbix
用户名:Admin
密码:zabbix
问题解决:
1.界面提示:zabbix server is not running,.....
查看zabbix server 的状态:systemctl status zabbix_server.service
zabbix没运行,可能是SELinux安全子系统拦截了。
setenforce 0 //临时关闭
vi /etc/selinux/config #将SELINUX=enforcing的值修改为disabled。//永久关闭,重启服务器生效。
设置服务自启动:
systemctl enable nginx.service
systemctl enable rh-php73-php-fpm.service
systemctl enable zabbix-agent.service
2851

被折叠的 条评论
为什么被折叠?



