目录
Centos7下Zabbix5.0.12源码安装
目的主要通过源码的安装,加深对zabbix-server相关的印象,直接上步骤如下
准备文件,源码下载
cd /home/testuser
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.12.tar.gz
关闭防火墙和selinux
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config && setenforce 0
修改主机名和修改时区
hostnamectl set-hostname zabbixserver
timedatectl set-timezone Asia/Shanghai
timedatectl status
编译前准备
yum install -y gcc gcc-c++
yum install -y mysql-devel
yum install -y libxml2-devel
yum install -y unixODBC*
yum install -y net-snmp-devel libevent-devel curl-devel
编译安装zabbix服务(testuser身份)
由于zabbix不能以root启动,因此这里采用安装在testuser用户目录下,并在安装完成后以testuser用户启动,如果编绎提示没有文件权限,则进行chown授权,如下chown -R testuser:testuser /home/testuser/zabbix-5.0.12.tar.gz
####切换到testuser账号下
su - testuser
tar -zxvf /home/testuser/zabbix-5.0.12.tar.gz -C /home/testuser/
cd zabbix-5.0.12
./configure --prefix=/home/testuser/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc
make install
mysql安装并准备zabbix数据库(testuser身份下安装)
详细的安装mysql可参考链接: centos7非root用户安装5.7.34版本mysql(二进制安装方式),这里安装mysql-5.7.32
切换到testuser身份下
su - testuser
- ####解压文件,建立数据目录
tar -xvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -C /home/testuser
cd /home/testuser
mv mysql-5.7.32-linux-glibc2.12-x86_64 mysql-5.7.32
mkdir /home/testuser/mysql-5.7.32/data
mkdir /home/testuser/mysql-5.7.32/conf
- ####准备数据库配置文件
cat > /home/testuser/mysql-5.7.32/conf/my.cnf << EOF
[client]
default-character-set=utf8mb4
[mysql]
port = 3306
socket = /home/testuser/mysql-5.7.32/data/mysql.sock
default-character-set=utf8mb4
[mysqld]
port = 3306
default_storage_engine=InnoDB
basedir = /home/testuser/mysql-5.7.32
datadir = /home/testuser/mysql-5.7.32/data
socket = /home/testuser/mysql-5.7.32/data/mysql.sock
character-set-client-handshake = FALSE
character-set-server=utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
max_connections = 2000
max_allowed_packet = 128M
innodb_file_per_table = 1
tmp_table_size = 134217728
max_heap_table_size = 134217728
#thread_cache_size=64
#innodb_buffer_pool_size = 8589934592
lower_case_table_names=1
log-bin = mysql-bin
max_binlog_size = 1024M
expire_logs_days = 1
log_slave_updates = 1
server-id = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
EOF
- ####修改mysql环境变量
cat >> /home/testuser/.bashrc << EOF
export PATH=/home/testuser/mysql-5.7.32/bin:\$PATH
EOF
source .bashrc
ln -s /home/testuser/mysql-5.7.32/data/mysql.sock /tmp/mysql.sock
- ####初始化数据库,初始化的结果控制台会输出root的初始密码。
mysqld --defaults-file=/home/testuser/mysql-5.7.32/conf/my.cnf --user=testuser --initialize
- ####启动数据库
/home/testuser/mysql-5.7.32/bin/mysqld_safe --defaults-file=/home/testuser/mysql-5.7.32/conf/my.cnf --user=testuser &
- ####修改root密码
###修改root密码,root登录mysql后执行:
alter user user() identified by "123456";
flush privileges;
导入Zabbix数据库基础数据
- ####在数据库上建立数据库
mysql -hlocalhost -uroot -p123456
create database zabbix character set utf8 collate utf8_bin;
- ####授权用户:
GRANT all ON zabbix.* TO zabbix@'%' IDENTIFIED BY 'zabbix';
flush privileges;
- ####导入数据
cd /home/testuser/zabbix-5.0.12/database/mysql/
use zabbix
source schema.sql
source images.sql
source data.sql
修改zabbix server配置文件
- ####vi /home/testuser/zabbix/etc/zabbix_server.conf指定数据库账号,密码,端口,socket等等
DBHost=localhost #数据库连接使用VIP
DBUser=zabbix
DBPassword=zabbix
DBSocket=/home/testuser/mysql-5.7.32/data/mysql.sock
DBPort=3306
- ####配置指标数据输出到文件夹,可供filebeat采集并入kafka
ExportDir=/home/testuser/zabbix/jsondata
ExportFileSize=256M
- ####其他配置,可根据自己的需求按需要调整,比如日志的路径或Pid修改成别的目录(可选)
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
- 把目录建好并授权给testuser用户
mkdir /home/testuser/zabbix/jsondata
chown -R testuser:testuser /home/testuser/zabbix
启动zabbix_server
切换成以testuser用户身份启动zabbix-server
##如果用户在root下,操作此步骤进行用户切换
su testuser
##启动zabbix-server
/home/testuser/zabbix/sbin/zabbix_server -c /home/testuser/zabbix/etc/zabbix_server.conf
启动agent(可选)
以testuser用户身份启动zabbix_agentd
##如果用户在root下,操作此步骤进行用户切换
su testuser
##启动zabbix_agentd
/home/testuser/zabbix/sbin/zabbix_agentd -c /home/testuser/zabbix/etc/zabbix_agentd.conf
相关进程截图如下,可以看到zabbix-server和zabbix-agentd都启动成功
Zabbix-Web安装
- ####安装remi的repo库,安装后才能进行php73的安装
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
- ####安装php73,zabbix5.0.12要求php7.2以上。
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json
yum install -y php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache
yum install -y php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip
yum install -y php73-php-recode php73-php-snmp php73-php-soap php73-php-xml php73-php-ldap
- ####安装nginx
##安装nginx的repo库,安装后才能进行nginx的安装
yum install -y http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
##nginx软件安装
yum install -y nginx
- ####vi /etc/nginx/nginx.conf,在nginx.conf文件中加入php-frm相关配置,配置nginx.conf,在nginx server段配置两个location段,
location / {
root /usr/share/nginx/html/;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /usr/share/nginx/html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
- ####拷贝zabbix的网页文件部署到web服务下
cd /home/testuser/zabbix-5.0.12/ui
cp -r * /usr/share/nginx/html/
- ####进行php.ini中相关配置
##php相关参数
sed -i 's/^post_max_size = 8M$/post_max_size = 16M/' /etc/opt/remi/php73/php.ini
sed -i 's/^max_execution_time = 30$/max_execution_time = 300/' /etc/opt/remi/php73/php.ini
sed -i 's/^max_input_time = 60$/max_input_time = 300/' /etc/opt/remi/php73/php.ini
sed -i 's/^;date.timezone =$/date.timezone = Asia\/Shanghai/' /etc/opt/remi/php73/php.ini
##mysql相关参数
sed -i 's/^mysql.default_socket =$/mysql.default_socket = \/home\/testuser\/mysql-5.7.32\/data\/mysql.sock /' /etc/opt/remi/php73/php.ini
sed -i 's/^pdo_mysql.default_socket=$/pdo_mysql.default_socket= \/home\/testuser\/mysql-5.7.32\/data\/mysql.sock /' /etc/opt/remi/php73/php.ini
sed -i 's/^mysqli.default_socket =$/mysqli.default_socket = \/home\/testuser\/mysql-5.7.32\/data\/mysql.sock /' /etc/opt/remi/php73/php.ini
- ####启动php73-php-fpm和nginx
systemctl start php73-php-fpm
systemctl start nginx
- ####进行web访问http://192.168.56.101/
- ####登陆测试
地址:http://192.168.56.101/index.php
账号/密码:Admin/zabbix
按如下图修改web界面为中文,User settings -> Language(Chinese zh_CN) -> update
update后变成中文界面了.
Zabbix-Web趋势图中文乱码处理
- ####默认的字体位于/usr/share/nginx/html/assets/fonts/DejaVuSans.ttf,不支持中文,先备份旧的文件,然后将windows的字体,我这里用的是win10下的,位于c:/windows/Fonts/simsun.ttc ,上传到linux服务器/usr/share/nginx/html/assets/fonts/目录,然后改名,
cd /usr/share/nginx/html/assets/fonts
mv DejaVuSans.ttf DejaVuSans.ttf.default
mv simsun.ttc DejaVuSans.ttf
windows10字体位置截图:
修改前:
修改后,可以看到中文问题解决。