zabbix6.0 源码安装

1、软件包准备及linux配置

1.1、软件包

mysql-8.0.28-linux-glibc2.12-x86_64.zip  --》MySQL :: Download MySQL Community Server (Archived Versions)

nginx-1.23.0.tar.gz  

php-8.1.8.tar.gz

yum -y install epel-release

 zabbix-6.0.6.tar.gz

1.2、linux环境配置

1、关闭selinux
 setenforce 0
 
cat /etc/selinux/config
 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
 
2、关闭防火墙(不关闭防火墙就开放端口 80 、9000、3066)
systemctl stop firewalld.service
systemctl disable firewalld.service
 

2、mysql安装

2.1、软连接方便后期升级变动及环境配置

ln -s mysql-8.0.28-linux-glibc2.12-x86_64 /usr/local/mysql

vim /etc/profile  (在文件最后面加这行)
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile

useradd -r -d /data/mysqldb -s /sbin/nologin mysql

2.2、目录设置权限

mkdir -p /var/run/mysql
mkdir -p /var/log/mysql
mkdir -p /data/mysqldb
chown -R mysql.mysql /data/mysqldb
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /var/run/mysql
chown -R mysql.mysql /var/log/mysql
chown -R mysql.mysql /tmp
chmod +x -R /usr/local/mysql

2.3、数据库初始化(无密码数据库初始化)

mysqld --initialize-insecure  --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb

2.4、配置文件修改

原配置文件备份

cp -r  /etc/my.cnf /etc/my.cnf_bak

新配置文件

vim /etc/my.cnf
[mysqld]
user=mysql
datadir=/data/mysqldb
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
server_id=6
symbolic-links=0
 
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid

2.5、system管理配置

vim /usr/lib/systemd/system/mysql.service
 
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

启动mysql 

systemctl daemon-reload
systemctl start mysql.service
systemctl enable mysql.service

密码

mysqladmin -uroot -p  password 123456

2.6、进MySQL配置zabbix库

mysql -u root -p
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@'%' identified with mysql_native_password by '123456';
grant all privileges on zabbix.* to zabbix@'%';
flush privileges;

3、nginx安装

3.1、nginx环境准备

yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++

useradd -M -s /sbin/nologin -M www

3.2、nginx二进制安装

tar -zxf nginx-1.23.0.tar.gz -C /opt/

cd /opt/nginx-1.23.0/
./configure --prefix=/usr/local/nginx --user=www --group=www  --http-client-body-temp-path=/usr/local/nginx/tmp/nginx/client_body --http-proxy-temp-path=/usr/local/nginx/tmp/nginx/proxy --http-fastcgi-temp-path=/usr/local/nginx/tmp/nginx/fastcgi --pid-path=/usr/local/nginx/logs/nginx.pid --lock-path=/usr/local/nginx/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre
make ;make install

3.3、nginx启动加入systemctl

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 -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

3.4、启动nginx

systemctl daemon-reload
systemctl start nginx
systemctl enable nginx

3.5、nginx配置

3.5.1、主配置文件

vim 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.php index.html index.htm;
        }
 
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include  conf.d/*.conf;
}

mkdir -p /opt/nginx-1.23.0/conf

3.5.2、nginx-zabbix配置文件

cat conf.d/zabbix.conf
server {
        listen       8080;
        server_name  localhost;
        location / {
            root   html/zabbix/;
            index  index.php index.html index.htm;
        }
 
        location ~ .*\.(php|php5)?$ {
            root           html/zabbix;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            include        fastcgi.conf;
            include        fscgi.conf;
            include        my-proxy.conf;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

3.5.3、fscgi.conf配置

vim fscgi.conf
# 缓冲区配置

fastcgi_buffering on;             # 默认启用缓冲区
fastcgi_buffers 8 64k;            # 若响应数据大小小于512KB,则会分配8个64KB缓冲区为其缓
                                  # 冲;若大于512KB,则超出的部分会存储到临时文件中
fastcgi_buffer_size 64k;          # 读取FastCGI服务器响应数据第一部分的缓冲区大小为64KB,
                                  # 通常包含响应头信息
fastcgi_busy_buffers_size 128K;   # 繁忙时向客户端发送响应的缓冲区大小为128KB
fastcgi_limit_rate 0;             # 默认不做限制
fastcgi_max_temp_file_size 1024M; # 临时文件中大小为1024MB
fastcgi_temp_file_write_size 64k; # 每次写入临时文件的数据大小为64KB
# fastcgi_temp_path使用默认配置
 
# 请求处理
fastcgi_request_buffering on;     # 默认启用读取整个请求体到缓冲区后再向FastCGI服务器发送请求
fastcgi_pass_request_body on;     # 默认将客户端请求体传递给FastCGI服务器
fastcgi_pass_request_headers on;  # 默认将客户端请求头传递给FastCGI服务器
 
# FastCGI连接配置
fastcgi_connect_timeout 60s;      # 默认Nginx与FastCGI服务器建立连接的超时时间为60s
fastcgi_keep_conn on;             # 启用保持连接
fastcgi_ignore_client_abort on;   # 当客户端关闭连接时,同时关闭与FastCGI服务器的连接
fastcgi_read_timeout 60s;         # 默认连续两个从FastCGI服务器接收数据的读操作之间的间隔
                                  # 时间为60s
fastcgi_send_timeout 60s;         # 默认连续两个发送到FastCGI服务器的写操作之间的间隔时间
                                  # 为60s
fastcgi_socket_keepalive on;      # FastCGI的连接启用so-keepalive socket选项
 
# 响应处理
fastcgi_force_ranges on ;         # 强制启用byte-range请求支持
fastcgi_hide_header X-Powered-By; # 隐藏PHP版本字段
# fastcgi_pass_header无必须传递的特殊头字段属性
 
fastcgi_ignore_headers X-Accel-Redirect X-Accel-Expires X-Accel-Limit-Rate X-Accel-Buffering X-Accel-Charset Expires Cache-Control Set-Cookie Vary;
                                  # 禁止Nginx处理从FastCGI获取响应的头属性字段
 
# 异常处理
fastcgi_intercept_errors on;      # 在FastCGI响应数据中响应码大于等于300时重定向给Nginx
fastcgi_next_upstream   error timeout invalid_header http_500 http_503 http_403 http_404 http_429;  # 当出现指定的条件时,将用户请求传递给upstream
                                            # 中的下一个服务器
fastcgi_next_upstream_timeout 0;            # 不限制将用户请求传递给upstream中的下一个
                                            # 服务器的超时时间
fastcgi_next_upstream_tries 0;              # 不限制将用户请求传递给upstream中的下一个
                                            # 服务器的尝试次数

5.3.6、配置my-proxy.onf

vim my-proxy.conf
#基本的代理参数
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

5.3.7、重启nginx

systemctl restart nginx.service
systemctl status nginx.service

4、php-fpm安装

4.1、依赖包

yum install libxml-devel sqlite-devel libcurl-devel libpng-devel libjpeg-turbo-devel libXpm-devel freetype-devel libicu-devel gcc-c++ libxslt-devel oniguruma-devel libsodium-devel openldap-devel net-snmp-devel libwebp-devel  -y

wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz 
yum install autoconf automake libtool -y
tar -zxvf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh && ./configure
make && make install

wget https://libzip.org/download/libzip-1.2.0.tar.gz --no-check-certificate
tar -zxf libzip-1.2.0.tar.gz
cd libzip-1.2.0/
./configure
make;make install
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

cp -frp /usr/lib64/libldap* /usr/lib/ 

4.2、编译php

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/php --with-freetype --with-jpeg  --with-zlib  --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --enable-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-zip  --enable-soap --with-gettext --enable-opcache --with-xsl --with-webp --with-xpm --with-snmp --with-ldap

vim MakeFile    # 开头是‘EXTRA_LIBS’,结尾加上‘-llber’
make;make install

4.3、配置php

cp php.ini-production /usr/local/php/etc/php.ini
修改php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone =Asia/Shanghai

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

测试php-fpm配置
/usr/local/php/sbin/php-fpm -t -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf 

chown -R www:www /usr/local/php/var

php启动命令
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

4.4、配置systemctl

vim /usr/lib/systemd/system/php-fpm.service

[Unit]
Description=PHP-FPM
After=network.target syslog.target2

[Install]
WantedBy=default.target
Alias=php-fpm.service

[Service]
User=www
Group=www
#User and Group can be set in the php-fpm configure file
Type=forking
#PIDFile=/usr/local/php/var/run/php-fpm.pid
#不需要在这里指定pid文件位置,需要到php-fpm.conf文件中指定
ExecStart=/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf 
ExecStop=/bin/kill -INT $MAINPID
ExecReload=/bin/kill -USR2 $MAINPID
cp /usr/local/php/sbin/php-fpm /etc/init.d/php-fpm
systemctl daemon-reload
systemctl enable php-fpm.service
systemctl start php-fpm.service

 4.5、测试

vim /usr/local/nginx/html/zabbix/nginx-php.php

http://192.168.0.3:8080/nginx-php.php

cat /usr/local/nginx/html/blog/wordpress/php-mysql.php

http://192.168.0.3:8080/php-mysql.php

5、zabbix6.0安装

5.1、创建库表

mysql -uroot -p

source /opt/zabbix-6.0.6/database/mysql/schema.sql;
source /opt/zabbix-6.0.6/database/mysql/images.sql;
source /opt/zabbix-6.0.6/database/mysql/data.sql;
source /opt/zabbix-6.0.6/database/mysql/history_pk_prepare.sql;
source /opt/zabbix-6.0.6/database/mysql/double.sql;

5.2、zabbix环境安装及编译

yum -y install libevent-devel net-snmp-devel libxml2-devel libcurl-devel

./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config  --with-net-snmp --with-libcurl --with-libxml2

make install

mkdir /usr/local/zabbix/log
chown -R zabbix:zabbix /usr/local/zabbix/

5.3、配置文件

vim /usr/local/zabbix/etc/zabbix_server.conf

LogFile=/usr/local/zabbix/log/zabbix_server.log  #日志文件地址,目录没有需要创建并授权
DBHost=localhost  #数据库地址
DBName=zabbix    #数据库名
DBUser=zabbix    #数据库用户名
DBPassword=mypassword  #数据库密码
DBSocket=/var/lib/mysql/mysql.sock  #数据库sock文件路径
DBPort=3306        #数据库端口
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts    #告警脚本存放位置
ExternalScripts=/usr/local/zabbix/externalscripts    #告警脚本存放位置
LogSlowQueries=3000
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf  #自定义监控配置文件

6、配置zabbix-server

创建/usr/lib/systemd/system/zabbix-server.service文件,并输入如下内容:
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/usr/local/zabbix/sbin/zabbix_server
Type=forking
Restart=on-failure
PIDFile=/usr/local/zabbix/log/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target

# 重载系统服务:
$ systemctl daemon-reload 

# 设置开机启动:
$ systemctl enable zabbix-server.service 
#启动服务
$ systemctl start zabbix-server.service

7、zabbix-nginx

cp -r /home/install/zabbix-6.0.6/ui/* /usr/local/nginx/html/zabbix/

测试:

打开浏览器输入地址:http://192.168.0.3:8080/setup.php

8、配置zabbix-agent


cat /etc/zabbix/zabbix_agent2.conf |grep -Ev '^#|^$'
 
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.0.2
ServerActive=192.168.0.2
Hostname=zbx-agent03
Include=/etc/zabbix/zabbix_agent2.d/*.conf
# 创建/usr/lib/systemd/system/zabbix-agentd.service文件,并输入如下内容:
[Unit]
Description=Zabbix monitor agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/usr/local/zabbix/sbin/zabbix_agentd
Type=forking
Restart=on-failure
PIDFile=/usr/local/zabbix/logs/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target

# 重载系统服务:
$ systemctl daemon-reload 

# 设置开机启动:
$ systemctl enable zabbix-agentd.service 
#启动服务
$ systemctl start zabbix-agentd.service

你可能感兴趣的:(sk,centos,linux,运维,1024程序员节)