CENtos7源码安装zabbix (v6.0.12)

 

CENtos7源码安装zabbix (v6.0.12)

此文只限于安装zabbix,前期得安装好nginx跟mysql。

 


 

Centos7源码安装zabbix6

一、zabbix_server编译安装

##创建数据库zabbix

create database zabbix character set utf8 collate utf8_bin;

 

##创建用户及设置主机为所有

create user 'zabbix'@'%' identified by 'zabbix';

 

##zabbix用户授权

grant all privileges on zabbix.* to 'zabbix'@'%' with grant option;

 

##修改用户密码验证方式

alter user 'zabbix'@'%' identified with mysql_native_password by 'zabbix';

 

#查看用户

select user,host,plugin from mysql.user;

 

#刷新

flush PRIVILEGES;

 

##查看最大连接数

show variables like 'max_connections';

 

#设置最大连接数为1000

set global max_connections=1000;二丶安装zabbix6.1

 

1.解压在官网上下载的zabbix源码包

 

#创建zabbix目录

mkdir /usr/local/zabbix

#解压

tar -zxvf zabbix-6.0.12.tar.gz -C /usr/local/zabbix/

2.创建用户账户

 

(1)对于所有 Zabbix 守护进程,需要一个非特权用户,如果从非特权用户帐户启动 Zabbix 守护程序,它将以该用户身份运行。

 

(2)然而,如果一个守护进程以“root”启动,它会切换到“zabbix”用户,且这个用户必须存在。在 Linux系统中,可以使用下面命令建立一个用户(该用户属于自己的用户组,“ zabbix”)

 

#创建zabbix组

groupadd --system Zabbix

 

#创建zabbix用户

useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" Zabbix

3.初始化数据

(登录至mysql)

mysql -uroot -p

use  zabbix

source /opt/zabbix-6.0.12/database/mysql/schema.sql

 

source /opt/zabbix-6.0.12/database/mysql/images.sql[A1] 

 

source /opt/zabbix-6.0.12/database/mysql/data.sql

4.安装编译所需的依赖

这里根据启用的模块不一样,所需要的依赖也不一样

yum install gcc mysql-devel libevent-devel libcurl-devel libxml2-devel libssh2-devel OpenIPMI-devel net-snmp-devel go java-devel -y

 

5.进行编译安装

去到软件包解压目录zabbix-6.0.12中

cd zabbix-6.0.12

 

./configure --prefix=/usr/local/zabbix [A2]  --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-ssh2 --enable-java

 

配置完成如下图所示,这里可以看到我们启用了java gatewayagent等等

 

接着进行安装

make install

安装完成后,可以看下所安装的目录的内容

# tree /usr/local/zabbix/
/usr/local/zabbix/
├── bin
│   ├── zabbix_get
│   ├── zabbix_js
│   └── zabbix_sender
├── etc
│   ├── zabbix_agent2.conf
│   ├── zabbix_agentd.conf
│   ├── zabbix_agentd.conf.d
│   ├── zabbix_server.conf
│   └── zabbix_server.conf.d
├── lib
│   └── modules
├── sbin
│   ├── zabbix_agentd
│   ├── zabbix_java
│   │   ├── bin
│   │   │   └── zabbix-java-gateway-6.0.3.jar
│   │   ├── lib
│   │   │   ├── android-json-4.3_r3.1.jar
│   │   │   ├── logback-classic-1.2.9.jar
│   │   │   ├── logback-console.xml
│   │   │   ├── logback-core-1.2.9.jar
│   │   │   ├── logback.xml
│   │   │   └── slf4j-api-1.7.32.jar
│   │   ├── settings.sh
│   │   ├── shutdown.sh
│   │   └── startup.sh
│   └── zabbix_server
└── share
    ├── man
    │   ├── man1
    │   │   ├── zabbix_get.1
    │   │   └── zabbix_sender.1
    │   └── man8
    │       ├── zabbix_agentd.8
    │       └── zabbix_server.8
    └── zabbix
        ├── alertscripts
        └── externalscripts
 
17 directories, 22 files
 

6.修改zabbix_server配置文件

cp /usr/local/zabbix/etc/zabbix_server.conf{,.bak}
 
# grep -v -E "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/log/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=127.0.0.1
DBPort=3306
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix
StartPollers=12
StartTrappers=30
StartDiscoverers=50
StartHTTPPollers=100
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
CacheSize=4G
CacheUpdateFrequency=1200
ValueCacheSize=12G
Timeout=4
AlertScriptsPath=/usr/local/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/externalscripts
FpingLocation=/sbin/fping
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
 

 

7.创建相关配置目录及权限设置

mkdir -p /usr/local/zabbix/{alertscripts,externalscripts,log}
mkdir /var/run/zabbix
 
chown zabbix.zabbix /var/run/zabbix/
chown zabbix.zabbix /usr/local/zabbix/ -R
 

8.配置systemd启动

cat <<EOF > /etc/systemd/system/zabbix-server.service

[Unit]

 

Description=Zabbix Server

 

After=syslog.target network.target network-online.target

 

Wants=network.target network-online.target

 

[Service]

 

Type=simple

 

User=root

 

ExecStart=/usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf

 

RemainAfterExit=yes

 

PIDFile=/var/run/zabbix/zabbix_server.pid

 

[Install]

 

WantedBy=multi-user.target

 

9.加入开机启动并启动

systemctl daemon-reload
 
systemctl enable zabbix-server --now

 

二、安装zabbix-web(PHP)

这里采用nginx+php部署来支撑zabbix-web,这样在后期如果有漏洞,也方便对应升级维护,如nginx有漏洞,可以直接把nginx升级即可。

 

1.配置yum

这里使用清华大学的yum

yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm -y

2.安装php

yum install php74-php php74-php-fpm php74-php-ldap php74-php-bcmath php74-php-mbstring php74-php-common php74-php-gd php74-php-mysql php74-php-xml php74-php-cli php74-php-devel php74-php-pecl-memcached php74-php-pecl-redis php74-php-opcache -y

3.配置php.ini

(使用清华大学yum安装的php配置文件路径在/etc/opt/remi/php74/

cp /etc/opt/remi/php74/php.ini{,.bak}
 

vim /etc/opt/remi/php74/php.ini

[PHP][A3]     

expose_php = Off[A4] 

short_open_tag = On[A5]    

cgi.fix_pathinfo=1[A6] 

max_execution_time = 300[A7]  

max_input_time = 300[A8] 

memory_limit = 256M[A9]  

post_max_size = 100M[A10]      

upload_max_filesize = 10M[A11] 

[Date][A12]    

date.timezone = Asia/Shanghai

4.配置php-fpm.conf

vim /etc/opt/remi/php74/php-fpm.conf
include=/etc/opt/remi/php74/php-fpm.d/*.conf
error_log = /var/opt/remi/php74/log/php-fpm/error.log

5、启动php并加入开机启动

systemctl enable --now php74-php-fpm.service

备注:如果需要卸载老版本php可以使用以下命令进行卸载

rpm -qa |grep php|xargs -i rpm -e {} –nodeps
 

三、配置nginx

1.修改nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

 

#user  nobody;

worker_processes  1;

 

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

 

#pid        logs/nginx.pid;

 

 

events {

    worker_connections  1024;

}

 

 

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"';

 

    #access_log  logs/access.log  main;

 

    sendfile            on;

    tcp_nopush          on;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 4096;

    #tcp_nopush     on;

 

    #keepalive_timeout  0;

 

    #gzip  on;

 

    server {

    listen       80;

        listen       [::]:80;

        server_name  _;

        root         /usr/local/nginx/html/zabbix;

        index index.php  index.html index.htm;

 

        include /etc/nginx/default.d/*.conf;

 

 

        location ~ \.php$ {

            root /usr/local/nginx/html/zabbix;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;

            fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;

            include        fastcgi_params;

        }

 

    location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|css|htm|bmp|js|svg)$ {

            root           /usr/local/nginx/html/zabbix;

         }

 

 

        error_page 404 /404.html;

        location = /404.html {

        }

 

        error_page 500 502 503 504 /50x.html;

        location = /50x.html {

        }

 

 

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

 

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           html;

        #    fastcgi_pass   127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

 

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

 

 

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

 

 

    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;

 

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

 

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

 

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

 

}

 

2.启动nginx并加入开机启动

systemctl enable --now nginx
systemctl  start  nginx
 

到这里就可以进行访问配置的地址和端口进行 zabbix-web 安装了

四、Web界面配置

1.访问Web界面

如下图,并选择自己所使用的语言

2.基础环境检测              

3.配置数据库连接信息

4.配置主机名称和时区

5.检查配置

6.如果出现下图,按照图中提示,下载文件,保存到对应提示路径中。

7.配置完成后如下图所示,点击完成。

 

8.进入登陆界面

(默认账号/密码:Admin/zabbix)

 

五、配置zabbix_agentd

1.zabbix_agentd配置文件

cp /usr/local/zabbix/etc/zabbix_agentd.conf{,.bak}

PidFile=/var/run/zabbix/zabbix_agentd.pid

LogFile[A13] =/var/log/zabbix/zabbix_agentd.log

LogFileSize=1024 [A14] 

Server[A15] =192.168.10.100 

ServerActive=192.168.10.100[A16] 

ListenPort=10050 [A17] 

ListenIP=0.0.0.0[A18] 

Hostname[A19] =Api1Bearead

EnableRemoteCommands=1[A20] 

Timeout=3[A21]   

Include=/etc/zabbix/zabbix_agentd.d/[A22]   

AllowRoot=0 [A23] 

 

2.配置zabbix-agented启动脚本

cat <<EOF > /etc/systemd/system/zabbix-agentd.service

 

[Unit]

 

Description=Zabbix Server

 

After=syslog.target network.target network-online.target

 

Wants=network.target network-online.target

 

[Service]

 

Type=simple

 

User=root

 

ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf

 

RemainAfterExit=yes

 

PIDFile=/var/run/zabbix/zabbix_agentd.pid

 

[Install]

 

WantedBy=multi-user.target

 

3.加入开机启动并启动

systemctl daemon-reload

 

systemctl enable zabbix-agentd --now

 

4.查看状态

# systemctl status zabbix-agent
● zabbix-agent.service - Zabbix Agent
   Loaded: loaded (/etc/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled)
   Active: active (exited) since Wed 2022-04-13 18:56:50 CST; 7s ago
  Process: 2243 ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf (code=exited, status=0/SUCCESS)
 Main PID: 2243 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/zabbix-agent.service
           ├─2245 /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
           ├─2246 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
           ├─2247 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
           ├─2248 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
           ├─2249 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
           └─2250 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
 
Apr 13 18:56:50 test systemd[1]: Started Zabbix Agent.

5.再次检查状态

(此时可以看到可用的机器数为1了)

 

 


 

posted @ 2023-01-13 13:53  禾子、  阅读(770)  评论(0编辑  收藏  举报