Zabbix 4 - 01:源码安装服务

Zabbix 4 - 01:源码安装服务_第1张图片

 

关于 Zabbix 需要知道

 

Zabbix 作为运维常用的服务器以及业务监控工具已经不是一两天的事情,所以如果早些年你还在纠结到底是使用 nagios 还是 zabbix 我还能理解,但在 2020 年,Prometheus 都已经泛滥的年代,你还在纠结,那就是你个人的问题了。

另外说明一下,其实工具很多功能都已经很完善,很多时候不完善的只是使用者而已。

现在是 2020 年 1 月 2 日,之所以再次写这类关于 Zabbix 的文章,其实是理由很简单,服务器做了迁移嘛,整套服务重新安装,这时候就得升级一下一辈子都懒得动的监控系统,顺便整理一下并尝尝新版本的鲜。

至于 Zabbix 到底是啥和究竟能干啥,相信会看这种文章的大多心里是有底的。

这里说下个人对于在官方文档中提到的几个 Zabbix 的几个功能组件的看法:

Server:接收来自 agent 端的监控数据并做相应的处理,是 Zabbix 的核心。

数据库:用于存储监控数据与服务配置信息。

Web:图形化显示和配置 Zabbix 数据和服务器监控信息。

Proxy:相当于中转机器,在特殊的网络环境中作为 Server 和 Agent 之间的”中间人“。

Agent:客户端,收集监控数据并传递给 Server 端。

大概就是这些,如果想了解更多,还是自个儿去研究官方文档,我们作为 User 差不多就行了:

https://www.zabbix.com/documentation/4.0/zh/manual/introduction/overview

 

 

关于服务选型

 

1. 关于源码安装的问题:

之所以在 docker 已经这么方便的今天依旧选择源码安装,原因很简单,个人喜欢定制化,规范化公司服务安装的标准而已。

2. 服务选型:

Zabbix 选择目前最新的版本 4.4.4,更新时间 Dec 19, 2019。

MySQL 还是 Percona 的 5.7 版本,没有选择 8,因为公司都是这个版本没必要特殊,但是本次准备换个数据库引擎 Tokudb。Tokudb 尤其适合密集型插入场景,压缩比很高。

PHP 是 7 版本,Nginx 则是最新版本 1.16。

3. Zabbix 下载地址:

https://www.zabbix.com/download_sources

当然,也可以去我的网盘下载:

MySQL 下载地址:

链接:https://pan.baidu.com/s/1eojo3VzAX_jBltLMuIF_Ew 

提取码:tw4a

Nginx 下载地址:

链接:https://pan.baidu.com/s/1-6uNiRe64NeqLVIdDsSIWA
提取码:ahwj

PHP 下载地址:

链接:https://pan.baidu.com/s/1jytOtIQ7Rz8tbFgtg7_6EA
提取码:dfb4

Zabbix 下载地址:

链接:https://pan.baidu.com/s/144ClGiDYCYofKnBtmGXUuQ
提取码:e1yn

具体安装包如下:

安装包
系统版本
CentOS Linux release 7.6.1810
Nginx 源码安装依赖安装包:
echo-nginx-module-master.zip
nginx-1.16.0.tar.gz
nginx-upload-module-master.zip
nginx-upstream-fair-master.zip
ngx_cache_purge-master.zip
ngx-fancyindex-master.zip
ngx_http_proxy_connect_module-master.zip
ngx_http_status_code_counter-master.zip
openssl-1.1.1c.tar.gz
pcre-8.43.tar.gz
zlib-1.2.11.tar.gz
MySQL 源码安装依赖安装包:
percona-server-5.7.11-4.tar.gz
cmake-3.5.2.tar.gz
boost_1_59_0.tar.gz
PHP 源码安装依赖安装包:
php-7.0.30.tar.gz
libiconv-1.14.tar.gz
Zabbix 源码安装依赖安装包:
zabbix-4.4.4.tar.gz

 

 

编译安装 LNMP 环境 - NGINX

 

1. 创建基础目录用于存放安装包:

cd /data/install_packages
mkdir nginx php mysql zabbix
mkdir /data/service
mkdir -p /data/logs/nginx

将对应的安装包存放到相应的目录!

 

2. 编译安装 Nginx:

# 安装依赖
yum -y install zip unzip gcc gcc-c++ automake autoconf libtool make glibc gd-devel pcre-devel libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel libevent libevent-devel patch

# 进入安装包存放目录
cd nginx

# 解压
unzip echo-nginx-module-master.zip
unzip nginx-upload-module-master.zip
unzip nginx-upstream-fair-master.zip
unzip ngx_cache_purge-master.zip
unzip ngx-fancyindex-master.zip
unzip ngx_http_proxy_connect_module-master.zip
unzip ngx_http_status_code_counter-master.zip
tar -zxf nginx-1.16.0.tar.gz
tar -zxf openssl-1.1.1c.tar.gz
tar -zxf pcre-8.43.tar.gz
tar -zxf zlib-1.2.11.tar.gz

# 安全配置:隐藏 nginx 版本
sed -i 's#"nginx/"#"WEB-SERVER/"#g' /data/install_packages/nginx/nginx-1.16.0/src/core/nginx.h
sed -i 's#"NGINX"#"WEB-SERVER"#g' /data/install_packages/nginx/nginx-1.16.0/src/core/nginx.h
sed -i 's#"Server: nginx"#"Server: WEB-SERVER"#g' /data/install_packages/nginx/nginx-1.16.0/src/http/ngx_http_header_filter_module.c
sed -i 's#"
nginx
" CRLF##g
' /data/install_packages/nginx/nginx-1.16.0/src/http/ngx_http_special_response.c # 打补丁 sed -i 's/default_port/no_port/g' /data/install_packages/nginx/nginx-upstream-fair-master/ngx_http_upstream_fair_module.c cd /data/install_packages/nginx/nginx-1.16.0 patch -p1 < /data/install_packages/nginx/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_101504.patch # 编译安装 ./configure --prefix=/data/service/nginx \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-http_flv_module \ --with-http_ssl_module \ --with-http_mp4_module \ --with-stream \ --with-http_realip_module \ --with-http_v2_module \ --with-http_sub_module \ --with-http_image_filter_module \ --with-pcre=/data/install_packages/nginx/pcre-8.43 \ --with-openssl=/data/install_packages/nginx/openssl-1.1.1c \ --with-zlib=/data/install_packages/nginx/zlib-1.2.11 \ --add-module=/data/install_packages/nginx/echo-nginx-module-master \ --add-module=/data/install_packages/nginx/nginx-upload-module-master \ --add-module=/data/install_packages/nginx/nginx-upstream-fair-master \ --add-module=/data/install_packages/nginx/ngx_cache_purge-master \ --add-module=/data/install_packages/nginx/ngx-fancyindex-master \ --add-module=/data/install_packages/nginx/ngx_http_proxy_connect_module-master \ --add-module=/data/install_packages/nginx/ngx_http_status_code_counter-master make && make install

 

3. 配置 nginx 配置文件和开机启动:

cd /data/service/nginx/conf/
mkdir vhosts tcp
vi nginx.conf

内容如下:

user  root root;
worker_processes  4;
error_log  /data/logs/nginx/error.log;
pid        /data/logs/nginx/nginx.pid;
worker_rlimit_nofile 65535;
events {
    use epoll;
    worker_connections  65535;
}
 
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 $request_time $upstream_response_time $upstream_addr $upstream_status';

    access_log /data/logs/nginx/access.log  main;
 
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 30m;
   
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_param HTTP_PROXY "";
   
    # 隐藏后端服务器的相关参数
    proxy_hide_header X-Powered-By;
    proxy_hide_header X-Forwarded-For;
    proxy_hide_header X-AspNet-Version;
    proxy_hide_header X-AspNetMvc-Version;
    proxy_hide_header Via;
    proxy_hide_header X-Varnish;
    proxy_hide_header Server;

    proxy_connect_timeout 300s;
    proxy_read_timeout 300s;
    proxy_send_timeout 300s;
   
    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 5;
    gzip_disable "MSIE [1-6]\.";
    gzip_types text/plain text/css text/xml application/javascript application/x-javascript;
    gzip_vary on;
   
    include vhosts/*.conf;
}

include /data/service/nginx/conf/tcp/*.conf;

配置开机启动:

chmod 755 /etc/rc.local 
echo "" >> /etc/rc.local 
echo "# NGINX STARTUP" >> /etc/rc.local 
echo "/data/service/nginx/sbin/nginx &" >> /etc/rc.local

检查配置:

/data/service/nginx/sbin/nginx -t

Nginx 安装完成!

 

 

编译安装 LNMP 环境 - MySQL(时间稍长)

 

1. 基础配置:

mkdir -p /data/logs/mysql-3306/tmp
mkdir -p /data/backup/mysql-3306
useradd mysql -s /usr/sbin/nologin
chown -R mysql.mysql /data/logs/mysql-3306

# 关闭大页内存
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

# 安装依赖
yum -y install gcc gcc-devel gcc-c++ gcc-c++-devel libaio-devel boost boost-devel autoconf* automake* zlib* libxml* ncurses-devel ncurses libgcrypt* libtool* cmake openssl openssl-devel bison bison-devel unzip numactl-devel net-snmp-devel net-snmp-utils readline* jemalloc

 

2. 编译安装 MySQL:

# 解压
cd /data/install_packages/mysql/
tar -zxf cmake-3.5.2.tar.gz 
tar -xzf boost_1_59_0.tar.gz 
tar -zxf percona-server-5.7.11-4.tar.gz

# 编译安装 CMAKE
cd cmake-3.5.2
./configure
gmake && make install

# 查看安装结果
cmake --version

# 编译安装 MySQL
cd ../percona-server-5.7.11-4

cmake . -DCMAKE_INSTALL_PREFIX=/data/service/mysql-3306 \ 
-DWITH_BOOST=/data/install_packages/mysql/boost_1_59_0/ \
-DMySQL_DataDIR=/data/service/mysql-3306/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_EDITLINE=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DZLIB_INCLUDE_DIR:PATH=/usr/include \
-DENABLE_DOWNLOADS=1

make -j4 && make install

 

3. 配置 MySQL 并初始化:

vi /etc/my.cnf

内容如下:

[mysql]
port=3306
prompt=3306/\\u [\\d]>
socket=/data/logs/mysql-3306/mysql.sock

[mysqld]
port=3306
user=mysql
federated
pid-file=/data/logs/mysql-3306/mysqld.pid
socket=/data/logs/mysql-3306/mysql.sock
log-error=/data/logs/mysql-3306/error.log
basedir=/data/service/mysql-3306
datadir=/data/service/mysql-3306/data
server_id=100
symbolic-links=0
autocommit=1
character_set_server=utf8
skip_name_resolve=1
max_connections=5000
max_connect_errors=5000
join_buffer_size=128M
tmp_table_size=64M
tmpdir=/data/logs/mysql-3306/tmp
max_allowed_packet=64M
interactive_timeout=1200
wait_timeout=600
read_buffer_size=8M
read_rnd_buffer_size=8M
sort_buffer_size=8M
slow_query_log=1
long_query_time=3
slow_query_log_file=/data/logs/mysql-3306/slow.log
log_queries_not_using_indexes=0
log_slow_admin_statements=0
expire_logs_days=90
min_examined_row_limit=100
master_info_repository=TABLE
relay_log_info_repository=TABLE
log-bin=/data/service/mysql-3306/data/mysql-bin
sync_binlog=5
gtid_mode=on
enforce_gtid_consistency=1
log_slave_updates=1
binlog_format=row
relay_log=/data/logs/mysql-3306/relay.log
relay_log_recovery=1
binlog_gtid_simple_recovery=1
slave_skip_errors=ddl_exist_errors
innodb_buffer_pool_size=8G
innodb_buffer_pool_instances=1
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_dump_at_shutdown=1
innodb_lock_wait_timeout=30
innodb_print_all_deadlocks=1
innodb_sort_buffer_size=8M 
log_timestamps=SYSTEM
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
skip-grant-tables

初始化:

/data/service/mysql-3306/bin/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/lxserver/service/mysql-3306 --datadir=/lxserver/service/mysql-3306/data --user=mysql

配置启动脚本:

# 创建启动方式
cp /data/service/mysql-3306/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
sed -i 's/^basedir=$/&\/data\/service\/mysql-3306/g' /etc/init.d/mysqld
sed -i 's/^datadir=$/&\/data\/service\/mysql-3306\/data/g' /etc/init.d/mysqld

# 添加环境变量
echo "" >> /etc/profile
echo "# MySQL" >> /etc/profile
echo "export MYSQL_HOME=/data/service/mysql-3306" >> /etc/profile
echo 'export PATH=$PATH:${MYSQL_HOME}/bin' >> /etc/profile

# 生效环境变量
source /etc/profile

# 添加开机启动
echo "" >> /etc/rc.local
echo "# MYSQL STARTUP" >> /etc/rc.local
echo "/etc/init.d/mysqld start &" >> /etc/rc.local

 

4. 启动 MySQL 并初始化用户:

/etc/init.d/mysqld start

登录 MySQL:

mysql

执行下面的 SQL 设置密码:

update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
quit;

替换配置重启 MySQL:

# 取消免密配置,重启数据库
sed -i 's%skip-grant-tables%#skip-grant-tables%g' /etc/my.cnf
/etc/init.d/mysqld restart

登录:

mysql -uroot -p

执行 SQL:

alter user 'root'@'localhost' identified by '123456';
grant all on *.* to root@'%' identified by '123456' with grant option;
flush privileges;
quit;

 

5. 添加 Tokudb:

登录 MySQL:

mysql -uroot -p

执行如下 SQL:

INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_background_job_status SONAME 'ha_tokudb.so';
show engines;
quit;

结果如图:

Zabbix 4 - 01:源码安装服务_第2张图片

MySQL 安装完成!

 

 

编译安装 LNMP 环境 - PHP

 

1. 基础配置:

# 创建目录
mkdir -p /data/logs/php/tmp
chmod -R 777 /data/logs/php# 创建监听用户
useradd php -s /usr/sbin/nologin

# 安装依赖
yum -y install libmcrypt-devel mcrypt mhash gd-devel ncurses-devel libxml2-devel bzip2-devel libcurl-devel curl-devel libjpeg-devel libpng-devel freetype-devel net-snmp-devel openssl-devel libmcrypt-devel

 

2. 安装 PHP:

# 解压
cd /data/install_packages/php/
tar -zxf libiconv-1.14.tar.gz 
tar -zxf php-7.0.30.tar.gz 

# 安装 libiconv
cd libiconv-1.14/srclib/
sed -i -e '/gets is a security/d' ./stdio.in.h
cd ..
./configure --prefix=/usr/local/libiconv
make && make install

# 编译安装 PHP
cd ../php-7.0.30
./configure --prefix=/data/service/php \
--with-config-file-path=/data/service/php/etc \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-pcre-regex \
--with-zlib \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-dba \
--with-libxml-dir \
--enable-ftp \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-mhash \
--enable-mbstring \
--with-mcrypt \
--enable-pcntl \
--enable-xml \
--disable-rpath \
--enable-shmop \
--enable-sockets \
--enable-zip \
--enable-bcmath \
--with-snmp \
--disable-ipv6 \
--with-gettext  \
--enable-fpm \
--with-fpm-user=php \
--with-fpm-group=php \
--with-openssl

make && make install

 

3. 配置 PHP:

# 复制配置文件
cd /data/service/php/etc/
cp php-fpm.conf.default php-fpm.conf
cp /data/install_packages/php/php-7.0.30/php.ini-production .
mv php.ini-production php.ini

# 修改 php.ini 配置
sed -i 's#;date.timezone =#date.timezone = PRC#g' php.ini 
sed -i 's#expose_php = On#expose_php = Off#g' php.ini 
sed -i 's#^;cgi.fix_pathinfo=1#cgi.fix_pathinfo=1#g' php.ini 
sed -i 's#disable_functions =#disable_functions =exec,system,eval,passthru,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,fsocket,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server#g' php.ini 
sed -i 's#max_execution_time = 30#max_execution_time = 300#g' php.ini 
sed -i 's#max_input_time = 60#max_input_time = 300#g' php.ini 
sed -i 's#post_max_size = 8M#post_max_size = 24M#g' php.ini 
sed -i 's#upload_max_filesize = 2M#upload_max_filesize = 4M#g' php.ini
sed -i 's#pdo_mysql.default_socket=#pdo_mysql.default_socket= /data/logs/mysql-3306/mysql.sock#g' php.ini 
sed -i 's#mysqli.default_socket =#mysqli.default_socket = /data/logs/mysql-3306/mysql.sock#g' php.ini 
sed -i 's#;session.save_path = "/tmp"#session.save_path = "/data/logs/php/tmp"#g' php.ini

# 修改 www.conf 配置
cd php-fpm.d/
cp www.conf.default www.conf
sed -i 's#;rlimit_files = 1024#rlimit_files = 65535#g' www.conf
sed -i 's#;listen.owner = php#listen.owner = www#g' www.conf
sed -i 's#;listen.group = php#listen.group = www#g' www.conf
sed -i 's#;listen.mode = 0660#listen.mode = 0660#g' www.conf

 

4. 配置启动:

# 配置启动脚本
cp /data/install_packages/php/php-7.0.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

# 启动服务
/etc/init.d/php-fpm start

# 配置开机自启动
echo '' >> /etc/rc.local
echo '# PHP STARTUP' >> /etc/rc.local
echo '/etc/init.d/php-fpm start &' >> /etc/rc.local

PHP 安装完成!

 

5. 测试 LNMP 环境:

# 添加 PHP 测试页面
echo '
phpinfo();
?>' > /tmp/index.php

# 添加 nginx 配置
vi /data/service/nginx/conf/vhosts/php.conf

内容如下:

server {
    listen 80;
    server_name localhost;
    root /tmp;
    index index.php index.html index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
   
    location ~ .*\.(php)?$ {
        expires -1s;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
    }
}

启动 Nginx:

/data/service/nginx/sbin/nginx

访问结果如下:

Zabbix 4 - 01:源码安装服务_第3张图片

到此 LNMP 环境搭建完成!最终的服务安装目录结构如下:

|-- install_packages
|   |-- mysql
|   |-- nginx
|   |-- php
|   `-- zabbix
|-- logs
|   |-- mysql-3306
|   |-- nginx
|   `-- php
|-- service
|   |-- mysql-3306
|   |-- nginx
|   `-- php

 

 

安装 Zabbix Server

 

先来看看我们使用 Zabbix 具体是怎样工作的:

Zabbix 4 - 01:源码安装服务_第4张图片

 

1. 基础配置:

创建数据库:

mysql -uroot -p

执行如下 SQL:

create database zabbix default character set utf8 collate utf8_general_ci;
grant all on zabbix.* to zbxuser@'127.0.0.1' identified by '123456';
flush privileges;
quit;

创建服务器用户和相关目录:

mkdir /lxserver/logs/zabbix
useradd zabbix -s /usr/sbin/nologin
chown -R zabbix:zabbix /lxserver/logs/zabbix/

 

2. 编译安装 Zabbix Server:

# 解压
cd /data/install_packages/zabbix
tar -zxf zabbix-4.4.4.tar.gz
cd zabbix-4.4.4/

# 编译安装
./configure --prefix=/data/service/zabbix \
--enable-server \
--enable-agent \
--with-mysql=/data/service/mysql-3306/bin/mysql_config \
--with-net-snmp \
--with-libcurl \
--with-libxml2

make && make install

 

3. 修改数据库脚本并导入:

# 修改表的存储引擎
cd /data/install_packages/zabbix/zabbix-4.4.4/database/mysql
sed -i "s#ENGINE=InnoDB#ENGINE=tokudb#g" schema.sql

# 导入数据
mysql -uroot -p zabbix < /data/install_packages/zabbix/zabbix-4.4.4/database/mysql/schema.sql 
mysql -uroot -p zabbix < /data/install_packages/zabbix/zabbix-4.4.4/database/mysql/images.sql 
mysql -uroot -p zabbix < /data/install_packages/zabbix/zabbix-4.4.4/database/mysql/data.sql 

 

4. 修改 Zabbix Server 配置:

cd /data/service/zabbix/etc/
vim zabbix_server.conf

主要修改以下配置:

LogFile=/data/logs/zabbix/zabbix_server.log
PidFile=/data/logs/zabbix/zabbix_server.pid
DBHost=127.0.0.1
DBName=zabbix
DBUser=zbxuser
DBPassword=123456
DBSocket=/data/logs/mysql-3306/mysql.sock
DBPort=3306

 

5. 添加启动脚本:

cp /data/install_packages/zabbix/zabbix-4.4.4/misc/init.d/fedora/core/zabbix_server /etc/init.d/
vim /etc/init.d/zabbix_server

修改如下:

Zabbix 4 - 01:源码安装服务_第5张图片

修改下面的启动命令:

Zabbix 4 - 01:源码安装服务_第6张图片

 

6. 配置 MySQL 的 lib,否则可能会报错:error while loading shared libraries:

echo "/data/service/mysql-3306/lib" >> /etc/ld.so.conf
ldconfig

 

7. 启动 Zabbix Server:

# 启动
/etc/init.d/zabbix_server start

# 配置开机自启动
echo '' >> /etc/rc.local
echo '# ZABBIX SERVER STARTUP' >> /etc/rc.local
echo '/etc/init.d/zabbix_server start &' >> /etc/rc.local

 

8. 查看进程:

netstat -tlunp | grep zabbix

可以看到启动的 10051 端口!

 

 

配置 Zabbix Web UI

 

在 Zabbix 配置 完成之后,那只是后端服务,用户需要访问则需要前端页面,这就涉及 Web UI 部署。

1. 将前端文件移动到指定目录:

mkdir /data/service/zabbix-web
cp -r /data/install_packages/zabbix/zabbix-4.4.4/frontends/php /data/service/zabbix-web/
chmod 777 -R /data/service/zabbix-web/php

 

2. 配置 nginx:

cd /data/service/nginx/conf/vhosts/
rm -f php.conf 
vi zabbix.conf

内容如下:

#############################################################
# Zabbix
#############################################################
server {
    listen 80;
    server_name localhost;
    root /data/service/zabbix-web/php;
    index index.php index.html index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ .*\.(php)?$ {
        expires -1s;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
    }
}

重载 Nginx:

/lxserver/service/nginx/sbin/nginx -s reload

 

3. 访问配置:

如果点击没有反应,则去服务器查看 /data/logs/php 的目录权限是否全为 777,没有则设置为 777:

Zabbix 4 - 01:源码安装服务_第7张图片

 

下面如果有报错的配置,则需要去 php.ini 配置文件中将值调整为相应的参数并重启 PHP:

Zabbix 4 - 01:源码安装服务_第8张图片

 

配置数据库连接:

Zabbix 4 - 01:源码安装服务_第9张图片

 

配置这个 Zabbix 的名称,主机我采用本机的 IP 地址,便于区分:

Zabbix 4 - 01:源码安装服务_第10张图片

 

确认配置:

Zabbix 4 - 01:源码安装服务_第11张图片

 

配置完成:

Zabbix 4 - 01:源码安装服务_第12张图片

 

登录测试,初始用户密码为:Admin / zabbix

Zabbix 4 - 01:源码安装服务_第13张图片

 

如图所示:

Zabbix 4 - 01:源码安装服务_第14张图片

 

汉化 Web UI:

Zabbix 4 - 01:源码安装服务_第15张图片

 

更新后查看:

Zabbix 4 - 01:源码安装服务_第16张图片

 

 

安装 Zabbix Agent

 

选择一台其他主机作为需要监控的主机,安装 agent。

1. 基础配置:

# 创建用户和目录
useradd zabbix -s /usr/sbin/nologin
mkdir -p /data/install_packages/zabbix
mkdir -p /data/logs/zabbix
mkdir -p /data/service
chown -R zabbix.zabbix /data/logs/zabbix

# 安装依赖
yum install -y net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel pcre*

 

2. 编译安装:

cd /data/install_packages/zabbix
tar -zxf zabbix-4.4.4.tar.gz 
cd zabbix-4.4.4/
./configure --prefix=/data/service/zabbix --enable-agent
make && make install

 

3. 配置 agent:

cd /data/service/zabbix/etc/
vim zabbix_agentd.conf

配置如下:

PidFile=/data/logs/zabbix/zabbix_agentd.pid
LogFile=/data/logs/zabbix/zabbix_agentd.log
Server=192.168.0.100
ListenPort=10050
ServerActive=192.168.0.100
Hostname=192.168.0.50

注意:Server 和 ServerActive 都配置 Server 的 IP 地址,Hostname 为了便于区分不通的机器使用本机的 IP 地址,当然你也可以自己给他取名字。

 

4. 配置启动:

chown -R zabbix.zabbix /data/service/zabbix
cp /data/install_packages/zabbix/zabbix-4.4.4/misc/init.d/tru64/zabbix_agentd /etc/init.d/
chmod 755 /etc/init.d/zabbix_agentd
vim /etc/init.d/zabbix_agentd

修改如下:

建立命令软链接:

ln -s /data/service/zabbix/sbin/* /usr/local/sbin/
ln -s /data/service/zabbix/bin/* /usr/local/bin/

启动服务并配置开机自启动:

# 启动
/etc/init.d/zabbix_agentd start

# 配置开机自启动
echo '' >> /etc/rc.local
echo '# ZABBIX AGENT STARTUP' >> /etc/rc.local
echo '/etc/init.d/zabbix_agentd start &' >> /etc/rc.local

当然,对于 Server 端的 agent 我们在编译 Server 的时候就编译了,只需要按照上面的配置好就行。

配置好后启动起来就会发现之前的告警没了:

Zabbix 4 - 01:源码安装服务_第17张图片

 

到此基础的安装完成! 

你可能感兴趣的:(Zabbix 4 - 01:源码安装服务)