麒麟系统V10 SP2 编译安装 Zabbix 6.0.8 +MySQL 8.0.30 + PHP 7.4.30

2022-11-19 09:39:53 浏览数 (3)

系统版本信息

代码语言:javascript复制
cat /etc/kylin-release
nkvers
cat /proc/version

fping 编译安装

fping 官网 http://www.fping.org/

代码语言:javascript复制
wget http://www.fping.org/dist/fping-5.0.tar.gz
tar -zxvf fping-5.0.tar.gz -C /usr/local/fping/
cd /usr/local/fping
./configure --prefix=/usr/local/fping --enable-ipv4 --enable-ipv6
make && make install
ln -s /usr/local/fping/sbin/fping  /usr/sbin/fping
chmod u s /usr/local/fping/sbin/fping

MySQL

下载MySQL 源码包解压

代码语言:javascript复制
wget   https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.17-x86_64-minimal.tar.xz
tar -zxvf mysql-8.0.30-linux-glibc2.17-x86_64-minimal.tar.xz  -C /usr/local/
mv /usr/local/mysql-8.0.30-linux-glibc2.17-x86_64-minimal /usr/local/mysql-8.0.30

创建MySQL用户和用户组

代码语言:javascript复制
groupadd mysql
useradd -M -g mysql -s /sbin/nologin mysql

创建MySQL目录并授权

代码语言:javascript复制
#创建MySQL数据目录
mkdir -p /data/mysql
#创建MySQL日志目录
mkdir -p /var/log/mysql
chown mysql:mysql -R /data/mysql
chown mysql:mysql -R  /var/log/mysql

环境变量

代码语言:javascript复制
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile

创建my.cnf配置文件

代码语言:javascript复制
vim /etc/my.cnf
[server]
[mysqld]
#skip-grant-tables
datadir=/data/mysql
basedir=/usr/local/mysql
socket=/data/mysql/mysql.sock
log-error=/var/log/mysql/mysql.log
max_connections=1000
connect_timeout = 60
wait_timeout=600
interactive_timeout=600
lock_wait_timeout=3600
skip_name_resolve=1
skip_external_locking=1
open_files_limit=65535
explicit_defaults_for_timestamp=1
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow.log
general-log=1
general-log-file=/var/log/mysql/sql_row.log
key_buffer_size=1M
read_buffer_size=4M
read_rnd_buffer_size=2M
table_open_cache=1024
table_definition_cache=1024
table_open_cache_instances=64
thread_cache_size=512
sort_buffer_size=16M
join_buffer_size=64M
bulk_insert_buffer_size=64M
tmp_table_size=64M
max_heap_table_size=776M
symbolic-links=0
max_allowed_packet =512M
bind-address =0.0.0.0
innodb_file_per_table=1
innodb_buffer_pool_size=1G
innodb_buffer_pool_instances=8
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_dump_at_shutdown=1
innodb_log_file_size=1G
innodb_log_buffer_size=32M
innodb_log_files_in_group=2
innodb_flush_log_at_trx_commit=0
innodb_lock_wait_timeout=600
innodb_autoinc_lock_mode=2
innodb_doublewrite=OFF
innodb_thread_concurrency=16
innodb_flush_method=O_DIRECT
innodb_io_capacity=2000
innodb_io_capacity_max=4000
innodb_write_io_threads=32
innodb_read_io_threads=16
innodb_purge_threads=4
innodb_page_cleaners=4
innodb_open_files=65535
innodb_max_dirty_pages_pct=50
innodb_lru_scan_depth=4000
innodb_status_file=1
innodb_change_buffer_max_size=50
innodb_open_files=10000
open_files_limit=10000
[client]
socket=/data/mysql/mysql.sock

初始化数据库(查看/var/log/mysql.log密码)

代码语言:javascript复制
mysqld --defaults-file=/etc/my.cnf --user=mysql  --initialize

启动zabbix 服务

代码语言:javascript复制
# 启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
# 初始化日志
touch /var/log/mysql.log
chown mysql.mysql /var/log/mysql.log
# 启动服务
/etc/init.d/mysql.server start

重置root密码

初始化密码登录MySQL后只能执行修改密码的操作,其它任何操作是不能执行的,使用以下命令修改密码

代码语言:javascript复制
alter user 'root'@'localhost' identified by "q1w2E#R$";
flush privileges;

创建zabbix数据库,创建用户并授权

代码语言:javascript复制
#登录数据库
mysql -uroot -ppassword
#创建zabbix 数据库
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
#创建zabbix 用户
mysql>  create user 'zabbix'@'%' identified by 'password';
#授权localhost 访问
mysql> grant all privileges on zabbix.* to 'zabbix'@'%';
#刷新策略
flush privileges;
#退出
mysql> quit;

更新用户账户密码的存储方式,默认使用caching_sha2_password

代码语言:javascript复制
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
ALTER USER 'zabbix'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

Zabbix 编译安装

创建zabbix用户组

代码语言:javascript复制
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

创建用户家目录

代码语言:javascript复制
mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
chown zabbix:zabbix /usr/lib/zabbix

安装依赖环境

yum install gcc libxml2 libxml2-devel net-snmp net-snmp-devel OpenIPMI OpenIPMI-devel libevent libevent-devel curl curl-devel -y

下载zabbix6.0.8源码包

代码语言:javascript复制
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.8.tar.gz
tar -zvxf zabbix-6.0.8.tar.gz -C /opt && cd  /opt/zabbix-6.0.8/

导入zabbix数据库

代码语言:javascript复制
cd database/mysql
mysql -uzabbix -p zabbix < schema.sql
mysql -uzabbix -p zabbix < images.sql
mysql -uzabbix -p zabbix < data.sql

编译安装zabbix

代码语言:javascript复制
/opt/zabbix-6.0.8/
./configure --prefix=/usr/local/zabbix --enable-server  
--enable-agent --with-mysql --enable-ipv6 --with-net-snmp 
--with-libcurl  --with-libxml2 --with-openipmi
make install

创建链接文件

代码语言:javascript复制
ln -s  /usr/local/mysql-8.0.30/lib/libmysqlclient.so.21 /usr/lib64/

ZabbIx Server 配置文件

代码语言:javascript复制
[root@kylin02 sbin]# egrep -v "*#|^$" /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/zabbix_server.log
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=password
Timeout=4
LogSlowQueries=3000
AllowRoot=1
User=root
StatsAllowedIP=127.0.0.1

PHP 编译安装

安装PHP依赖环境

yum -y install libtool sqlite-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel

yum install openldap openldap-devel -y

拷贝和链接所需必要文件

代码语言:javascript复制
cp -frp /usr/lib64/libldap* /usr/lib/
ln -s /usr/lib64/liblber.so /usr/lib/liblber.so

安装oniguruma-6.9.4

代码语言:javascript复制
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -xvf  oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr --libdir=/lib64
 make && make install

安装libmcrypt

代码语言:javascript复制
wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make && make install

编译安装PHP

下载php7.4源文件,加上超时时间防止下载中断

代码语言:javascript复制
cd /opt
wget --timeout=7200 https://www.php.net/distributions/php-7.4.30.tar.gz
tar -xvf  php-7.4.30.tar.gz
cd php-7.4.30

编辑PHP的配置项

代码语言:javascript复制
./configure --prefix=/usr/local/php 
--with-config-file-path=/usr/local/php/etc 
--enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx 
--enable-inline-optimization --disable-debug --disable-rpath 
--enable-shared --enable-soap  --with-xmlrpc 
--with-openssl --with-mhash  --with-sqlite3 
--with-zlib --enable-bcmath --with-iconv --with-bz2 
--enable-calendar --with-curl --with-cdb --enable-dom 
--enable-exif --enable-fileinfo --enable-filter 
--enable-ftp  --with-openssl-dir --with-zlib-dir 
--enable-gd-jis-conv --with-gettext --with-gmp --with-mhash 
--enable-json --enable-mbstring --enable-mbregex  
--enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 
--with-zlib-dir --with-pdo-sqlite --with-readline --enable-session 
--enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg 
--enable-sysvsem --enable-sysvshm --with-xsl --with-ldap   
--enable-mysqlnd-compression-support --with-pear  
--enable-opcache --disable-fileinfo

编译安装

代码语言:javascript复制
make -j 3 
make install

PHP环境变量

代码语言:javascript复制
echo "export PATH=$PATH:/usr/local/php/bin" >> /etc/profile
source /etc/profile

拷贝PHP配置文件

代码语言:javascript复制
cp  /opt/php-7.4.30/php.ini-production   /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
ln -s /usr/local/php/etc/ /etc/php

修改 /usr/local/php/etc/php-fpm.conf 运行用户和组改为nginx

代码语言:javascript复制
chown nginx.nginx /usr/local/php/etc/php-fpm.conf
chown -R nginx.nginx /etc/php

查看PHP 安装模块

启动php-fpm

代码语言:javascript复制
/usr/local/php/sbin/php-fpm

重启php-fpm

代码语言:javascript复制
kill -USR2 303081

终止php-fpm

代码语言:javascript复制
kill -INT  303081

部署Nginx

安装Nginx所需依赖环境

代码语言:javascript复制
yum install gcc-c   pcre pcre-devel zlib zlib-devel openssl openssl-devel -y

编译安装Nginx

代码语言:javascript复制
#下载Nginx 源码包
wget -c http://nginx.org/download/nginx-1.20.1.tar.gz
#解压
tar -zxvf  nginx-1.20.1.tar.gz -C /opt
#进入到解压目录
cd  nginx-1.20.1/

编译配置

代码语言:javascript复制
./configure   
--with-file-aio --with-ipv6 --with-http_ssl_module 
--with-http_v2_module --with-http_realip_module 
--with-http_addition_module   --with-http_sub_module 
--with-http_dav_module --with-http_flv_module 
--with-http_mp4_module --with-http_gunzip_module 
--with-http_gzip_static_module --with-http_random_index_module 
--with-http_secure_link_module --with-http_degradation_module  
--with-http_slice_module --with-http_perl_module=dynamic 
--with-http_auth_request_module --with-mail=dynamic 
--with-mail_ssl_module --with-pcre --with-pcre-jit 
--with-stream=dynamic --with-stream_ssl_module --with-debug

编译安装

代码语言:javascript复制
make && make install

启动Nginx

代码语言:javascript复制
#进入安装目录,启动服务器
cd /usr/local/nginx
#进入sbin
cd sbin
#启动
./nginx -c /usr/local/nginx/conf/nginx.conf
#后面的-c参数是说指定配置文件
#查看进程
ps -ef | grep nginx

配置nginx开机启动

代码语言:javascript复制
vim /usr/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 reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

创建软链接

代码语言:javascript复制
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

Nginx 配置文件

代码语言:javascript复制
vim /usr/local/nginx/conf/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;
        location / {
            root   html;
            index  index.html index.htm index.php;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ .php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_buffer_size 32k;
            fastcgi_buffers 10240 32k;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

拷贝Zabbix 前端UI文件

代码语言:javascript复制
mkdir -p /usr/local/nginx/html/zabbix
chown nginx:nginx /usr/local/nginx/html/zabbix
cp -r /opt/zabbix-6.0.8/ui/* /usr/local/nginx/html/zabbix

Zabbix Web Install

http://ip/zabbix/setup.php

报错处理

安装freetype

解压并进入源码目录

代码语言:javascript复制
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.gz
tar -zxvf freetype-2.9.tar.gz
cd freetype-2.9
./configure --prefix=/user/local/freetype
make && make install

安装libjpeg

解压并进入源码目录

代码语言:javascript复制
tar -zxvf jpegsrc.v9d.tar.gz
cd jpeg-9d
./configure --prefix=/user/local/libjpeg --enable-shared
make && make install

安装gd扩展,在php的源码报下的ext文件夹进入gd

代码语言:javascript复制
cd /opt/php-7.4.30/ext/gd/
phpize
./configure --with-php-config=/usr/local/php/bin/php-config  --with-jpeg=/user/local/libjpeg  --with-freetype=/user/local/freetype
make && make install

其中--with-php-config是指向安装php后生成的一个配置工具,主要用于扩展的编译配置,其他的参数对应指向先前安装依赖的位置

vim /usr/local/php/etc/php.ini

代码语言:javascript复制
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/gd.so

php 参数调整

代码语言:javascript复制
vim /usr/local/php/etc/php.ini
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
date.timezone = Asia/Shanghai

重启php-fpm

代码语言:javascript复制
kill -USR2 PID

终止php-fpm

代码语言:javascript复制
kill -INT  PID

Zabbix 6.0 UI 中文乱码

在Windows 系统中找到 C:WindowsFonts 中的楷体(常规)字体,通过lrzsz 上传到/usr/local/nginx/html/zabbix/assets/fonts 目录下

代码语言:javascript复制
/usr/local/nginx/html/zabbix/assets/fonts
cp DejaVuSans.ttf DejaVuSans.ttf.bak
mv simkai.ttf DejaVuSans.ttf
chmod  755 DejaVuSans.ttf

0 人点赞