Zabbix 4.0编译安装
一、Mysql数据库安装
1. 卸载mysql和mariadb相关软件并创建mysql用户
rpm -e --nodeps mariadb-libs
useradd -d /home/mysql mysql
mkdir -p /home/mysql/data
chown -R mysql.mysql /home/mysql/data
2. 安装已经下载好的mysql的rpm安装包
MYSql包下载地址:
http://mirrors.ustc.edu.cn/mysql-repo/yum/mysql-5.7-community/el/7/x86_64/
yum localinstall mysql-community-{client,common,libs,server,devel,libs-compat}-5.7.21-1.el7.x86_64.rpm
3. 初始化Mysql并指定数据目录
mysqld --initialize --user=mysql --datadir=/home/mysql/data
4. 修改配置文件vi /etc/my.cnf
[client]
socket=/home/mysql/data/mysql.sock
[mysqld]
user=mysql
basedir=/usr
datadir=/home/mysql/data
port=3306
pid-file=/var/lib/mysql/whTgpZascbDB011025835.pid
plugin-dir=/usr/lib64/mysql/plugin
character_set_server=utf8
init_connect='SET NAMES utf8'
socket=/home/mysql/data/mysql.sock
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
symbolic-links=0
log-error=/var/log/mysqld.log
socket=/home/mysql/data/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
max_connections = 500
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
join_buffer_size = 128M
tmp_table_size = 128M
max_allowed_packet = 500M
read_buffer_size = 16M
read_rnd_buffer_size = 32M
sort_buffer_size = 32M
event_scheduler = 1
5. 启动服务
systemctl start mysqld && systemctl enable mysqld
6. 查看进程
[root@localhost ~]# ps -ef | grep mysql
mysql 12060 1 0 14:09 ? 00:00:07 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 25228 25210 0 14:52 pts/0 00:00:00 grep --color=auto mysql
[root@localhost ~]#
7.修改数据库root密码
grep password /var/log/mysqld.log
mysqladmin -uroot -p'K97!#vl0*kvt' password 'Zabbix1234#' #初始密码K97!#vl0*kvt
8. 登录数据库并创建zabbix库
mysql> create database zabbix;
二、编译安装Zabbix Server
1. 创建zabbix用户
useradd zabbix
2.安装zabbix的支持功能依赖包
yum -y install gcc libxml2-devel net-snmp-devel libevent-devel curl-devel mysql-devel
3. 编译安装
tar -xf zabbix-4.0.5.tar.gz
cd zabbix-4.0.5
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql
make && make install
三、为数据库用户授权
1. 导入数据
mysql -uroot -p zabbix < database/mysql/schema.sql
mysql -uroot -p zabbix < database/mysql/images.sql
mysql -uroot -p zabbix < database/mysql/data.sql
2. 创建用户并授权
mysql> grant all on zabbix.* to zabbix@'%' identified by 'Zabbix1234#';
mysql> flush privileges;
四、启动服务
1. 修改zabbix_server配置文件
vi /usr/local/zabbix/etc/zabbix_server.conf
SourceIP=172.21.58.236 #内网IP
LogFile=/usr/local/zabbix/etc/zabbix_server.log
PidFile=/usr/local/zabbix/etc/zabbix_server.pid
DBHost=8.129.174.142
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix1234#
Timeout=4
LogSlowQueries=3000
2. 修改zabbix目录权限
chown -R zabbix. /usr/local/zabbix/
3. 启动服务
cp misc/init.d/fedora/core/zabbix_server /etc/init.d
vi /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix
service zabbix_server start
4. 查看端口
netstat -luntp | grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 18374/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 18374/zabbix_server
5. 添加并启动zabbix_agentd服务
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d
vi /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix
vi /usr/local/zabbix/etc/zabbix_agentd.conf
Server=xxx.xxx.xxx.xxx
ServerActive=xxx.xxx.xxx.xxx
Hostname=xxx.xxx.xxx.xxx
6.启动
service zabbix_agentd start
chkconfig --add zabbix_agentd && chkconfig zabbix_agentd on
五、Nginx安装配置
1. 编译安装Nginx
yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel # 依赖包
tar -xf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre # http_ssl_module支持https;stub_status_module支持监控状态
make && make install
chown -R nobody. /usr/local/nginx # nobody用户运行nginx安全性比较高
2. 修改Nginx配置vi /usr/local/nginx/conf/nginx.conf
user nobody;
worker_processes 4;
events {
worker_connections 1024;
}
http {
client_max_body_size 20m;
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/local/nginx/html;
index index.html index.htm index.php;
location /nginx_status {
stub_status on;
}
}
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 300;
}
}
}
3.启动
# /usr/local/nginx/sbin/nginx // 启动nginx服务
# nginx -s stop/reload // 停服务/加载配置 (nginx -v/-V 查看版本)
4.设置服务启动
vi /lib/systemd/system/nginx.service
[Unit]
Description=nginx # 描述服务
After=network.target # 描述服务类型
[Service]
Type=forking # 后台运行
ExecStart=/usr/local/nginx/sbin/nginx # 运行
ExecReload=/usr/local/nginx/sbin/nginx -s reload # 重启
ExecStop=/usr/local/nginx/sbin/nginx -s quit # 停止
PrivateTmp=true # 给服务分配独立的临时空间
[Install]
WantedBy=multi-user.target # 多用户
chmod +x /lib/systemd/system/nginx.service
systemctl start nginx && systemctl enable nginx
# 启动服务并设置开机自启
六、Web前端安装配置
1. 编译安装PHP5.6
PHP包下载地址:
https://www.php.net/releases/
tar -xf php-5.6.31.tar.bz2 #yum install bzip2
cd php-5.6.31
yum install -y libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel freetype-devel gd openldap-devel openssl-devel
./configure --prefix=/usr/local/php --enable-fpm --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --enable-gd-native-ttf --enable-pdo --with-pdo-mysql --with-gettext --enable-sockets --enable-bcmath --enable-xml --with-bz2 --with-freetype-dir=/usr/local --with-libxml-dir=/usr/local --with-zlib --with-curl --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-ldap --with-libdir=lib64 # --enable-fpm启用php-fpm
make && make install
2. 启动php-fpm服务
cp php.ini-production /usr/local/php/lib/php.ini # php.ini文件
vi /usr/local/php/lib/php.ini
date.timezone = Asia/Shanghai
post_max_size = 20M
upload_max_filesize = 20M
max_execution_time = 300
max_input_time = 300
memory_limit = 512M
always_populate_raw_post_data = -1
cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
/usr/local/php/sbin/php-fpm &
# 启动php-fpm服务,监听9000端口;如果要停服务就直接杀父进程
3. 设置php-fpm服务开机自启
vi /etc/rc.d/rc.local
/usr/local/php/sbin/php-fpm &
chmod +x /etc/rc.d/rc.local
4. 拷贝PHP数据文件
rm /usr/local/nginx/html/* -rf
cd zabbix-4.0.5
cp -a frontends/php/* /usr/local/nginx/html
chown -R nobody. /usr/local/nginx/html
5. 配置Zabbix前端
通过浏览器访问Zabbix首页(http://IP),根据向导一步步进行配置。