Ubuntu 22.04基于lnmp环境部署Zabbix 6.0 LTS

小柒博客 评论24字数 2276阅读7分35秒阅读模式

一、lnmp简介

LNMP代表的就是:Linux系统下(Nginx+MySQL(MariaDB)+PHP)这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:ubuntu、centos、ubuntu、fedora、gentoo等。

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发。

MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,属于Oracle旗下产品。MySQL是最流行的关系型数据库管理系统之一,在WEB应用方面,MySQL是最好的RDBMS(Relational Database Management System,关系数据库管理系统)应用软件之一。

PHP(Hypertext Preprocessor)是一种广泛使用的开源服务器端脚本语言,尤其适用于Web开发。它最初由Rasmus Lerdorf于1994年创建,旨在简化网页开发过程。PHP可以嵌入到HTML中,并与多种数据库集成,最常用的是MySQL。其灵活性、易学性和强大的社区支持使得PHP成为开发动态网页和Web应用程序的首选语言之一。PHP代码在服务器上执行,生成的HTML发送到客户端,从而实现网页的动态交互。它广泛应用于各种Web开发项目,包括内容管理系统、电子商务平台和社交媒体网站。

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

二、Zabbix简介

zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent。

zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。

三、Ubuntu 22.04基于lnmp环境部署Zabbix

1、安装Nginx

1)安装Nginx

root@ubuntu:~# apt -y update

root@ubuntu:~# apt -y install nginx

2、安装MySQL

1)安装MySQL

root@ubuntu:~# apt -y install mysql-server

2)登录MySQL

root@ubuntu:~# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.40-0ubuntu0.22.04.1 (Ubuntu)

 

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> select version();

+-------------------------+

| version()                 |

+-------------------------+

| 8.0.40-0ubuntu0.22.04.1 |

+-------------------------+

1 row in set (0.00 sec)

3)配置MySQL

root@ubuntu:~# cp /etc/mysql/mysql.conf.d/mysqld.cnf{,_bak}

root@ubuntu:~# sed -i '/pid-file/s/# //' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/socket/s/# //' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/3306/s/# //' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/bind-address/s/127.0.0.1/0.0.0.0/g' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/datadir/s/# //' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i -e '/max_connections/s/# //' -e '/max_connections/s/151/1000/' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/general_log/s/# //g' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/slow_query_log/s/# //g' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/server-id/s/# //' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/log_bin/s/# //' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/binlog_expire_logs_seconds/s/# //' /etc/mysql/mysql.conf.d/mysqld.cnf

root@ubuntu:~# sed -i '/max_binlog_size/s/100M/512M/' /etc/mysql/mysql.conf.d/mysqld.cnf

4)重启MySQL

root@ubuntu:~# systemctl restart mysql

5)配置root密码

root@ubuntu:~# mysql -u root 2>/dev/null -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'G7#Wv8eDQbwdEBCL';"

root@ubuntu:~# mysql -uroot -pG7#Wv8eDQbwdEBCL

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 8.0.40-0ubuntu0.22.04.1 (Ubuntu)

 

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql>

3、安装PHP

1)安装PHP

root@ubuntu:~# apt -y install php-fpm php-mysqli php-redis php-mbstring php-gd php-xml php-bcmath php-ldap php-mysql

2)配置PHP

# 配置www.conf

root@ubuntu:~# cp /etc/php/8.1/fpm/pool.d/www.conf{,_bak}

root@ubuntu:~# sed -i 's/^listen = .*/listen = 0.0.0.0:9000/' /etc/php/8.1/fpm/pool.d/www.conf

root@ubuntu:~# sed -i -e "/pm.max_requests/s/;//" -e '/pm.max_requests/s/500/3000/' /etc/php/8.1/fpm/pool.d/www.conf

root@ubuntu:~# sed -i '/pm.status_listen/s/;//' /etc/php/8.1/fpm/pool.d/www.conf

root@ubuntu:~# sed -i '/pm.status_path/s/;//' /etc/php/8.1/fpm/pool.d/www.conf

root@ubuntu:~# sed -i 's/www-data/nginx/g' /etc/php/8.1/fpm/pool.d/www.conf

# 配置php.ini

root@ubuntu:~# cp /etc/php/8.1/fpm/php.ini{,_bak}

root@ubuntu:~# sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#' /etc/php/8.1/fpm/php.ini

root@ubuntu:~# sed -i '/post_max_size/s/8M/16M/' /etc/php/8.1/fpm/php.ini

root@ubuntu:~# sed -i '/max_execution_time/s/30/300/' /etc/php/8.1/fpm/php.ini

root@ubuntu:~# sed -i '/max_input_time/s/60/300/' /etc/php/8.1/fpm/php.ini

root@ubuntu:~# useradd -s /sbin/nologin nginx

3)重启PHP-FPM

root@ubuntu:~# systemctl restart php8.1-fpm.service

root@ubuntu:~# systemctl status php8.1-fpm.service

4、安装Zabbix

1)安装依赖包

root@ubuntu:~# apt -y update

root@ubuntu:~# apt -y install snmp gcc make libmysqlclient-dev libghc-curl-dev libxml2 libxml2-dev libsnmp-dev libopenipmi-dev libevent-dev libpcre3 libpcre3-dev

2)下载Zabbix软件包

root@ubuntu:~# apt -y install wget

root@ubuntu:~# wget -c https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.36.tar.gz

3)安装中文语言包

root@ubuntu:~# apt -y install language-pack-zh-hans

root@ubuntu:~# sed -i "/zh_CN.UTF-8/s/# //" /etc/locale.gen

4)安装常用中文字体

root@ubuntu:~# apt -y install fonts-wqy-microhei fonts-wqy-zenhei xfonts-wqy

5)解压

root@ubuntu:~# tar xf zabbix-6.0.36.tar.gz

6)预编译

root@ubuntu:~# cd zabbix-6.0.36/

root@ubuntu:~/zabbix-6.0.36# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-openipmi

7)编译及安装

root@ubuntu:~/zabbix-6.0.36# make && make install

8)配置Zabbix

root@ubuntu:~/zabbix-6.0.36# cp /usr/local/zabbix/etc/zabbix_server.conf{,_bak}

root@ubuntu:~/zabbix-6.0.36# cp /usr/local/zabbix/etc/zabbix_agentd.conf{,_bak}

9)创建软连接

root@ubuntu:~/zabbix-6.0.36# ln -sf /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/

10)拷贝Web到Nginx发布目录

root@ubuntu:~/zabbix-6.0.36# cp -a ~/zabbix-6.0.36/ui /usr/share/nginx/html/zabbix-6.0.36

11)授权

root@ubuntu:~/zabbix-6.0.36# chown -R nginx:nginx /usr/share/nginx/html/zabbix-6.0.36/

12)配置Zabbix_Server

root@ubuntu:~/zabbix-6.0.36# vim /usr/local/zabbix/etc/zabbix_server.conf

LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=www.yangxingzhen.com
Timeout=30
LogSlowQueries=3000

13)配置Zabbix_Agent

root@ubuntu:~/zabbix-6.0.36# vim /usr/local/zabbix/etc/zabbix_agentd.conf

LogFile=/tmp/zabbix_agentd.log
Server=localhost
ServerActive=localhost
Hostname=192.168.3.137
UnsafeUserParameters=1
AllowKey=system.run[*]
LogFileSize=10
Timeout=30

14)配置系统服务

root@ubuntu:~/zabbix-6.0.36# cp misc/init.d/tru64/zabbix_* /etc/init.d/

root@ubuntu:~/zabbix-6.0.36# chmod +x /etc/init.d/zabbix_*

15)创建Zabbix用户

root@ubuntu:~/zabbix-6.0.36# useradd -s /sbin/nologin zabbix

16)创建Zabbix数据库

root@ubuntu:~/zabbix-6.0.36# mysql -uroot -pG7#Wv8eDQbwdEBCL 2>/dev/null -e "create database zabbix character set utf8 collate utf8_bin;"

root@ubuntu:~/zabbix-6.0.36# mysql -uroot -pG7#Wv8eDQbwdEBCL 2>/dev/null -e "create user zabbix@'localhost' identified by 'www.yangxingzhen.com';"

root@ubuntu:~/zabbix-6.0.36# mysql -uroot -pG7#Wv8eDQbwdEBCL 2>/dev/null -e "grant all on zabbix.* to zabbix@'localhost';"

root@ubuntu:~/zabbix-6.0.36# mysql -uroot -pG7#Wv8eDQbwdEBCL 2>/dev/null -e "flush privileges;"

17)导入Zabbix数据库

root@ubuntu:~/zabbix-6.0.36# mysql -uroot -p"G7#Wv8eDQbwdEBCL" 2>/dev/null zabbix < ~/zabbix-6.0.36/database/mysql/schema.sql

root@ubuntu:~/zabbix-6.0.36# mysql -uroot -p"G7#Wv8eDQbwdEBCL" 2>/dev/null zabbix < ~/zabbix-6.0.36/database/mysql/images.sql

root@ubuntu:~/zabbix-6.0.36# mysql -uroot -p"G7#Wv8eDQbwdEBCL" 2>/dev/null zabbix < ~/zabbix-6.0.36/database/mysql/data.sql

18)启动Zabbix

root@ubuntu:~/zabbix-6.0.36# /etc/init.d/zabbix_server start

Zabbix server started.

root@ubuntu:~/zabbix-6.0.36# /etc/init.d/zabbix_agentd start

Zabbix agent started.

19)查看Zabbix进程和端口

root@ubuntu:~/zabbix-6.0.36# netstat -lntup |egrep "10050|10051"

root@ubuntu:~/zabbix-6.0.36# ps -ef |egrep "zabbix_server|zabbix_agentd"

20)配置Nginx

root@ubuntu:~/zabbix-6.0.36# vim /etc/nginx/nginx.conf

    user nginx nginx;
    worker_processes auto;
    pid /var/run/nginx.pid;
events {
    use epoll;
    worker_connections 10240;
    multi_accept on;
    }
http {
    include mime.types;
    default_type application/octet-stream;
    log_format json escape=json
                    '{"访问者IP":"$remote_addr",'
                    '"访问时间":"$time_iso8601",'
                    '"访问页面":"$uri",'
                    '"请求返回时间":"$request_time/S",'
                    '"请求方法类型":"$request_method",'
                    '"请求状态":"$status",'
                    '"请求体大小":"$body_bytes_sent/B",'
                    '"访问者搭载的系统配置和软件类型":"$http_user_agent",'
                    '"虚拟服务器IP":"$server_addr"}';
    access_log /var/log/nginx/access.log json;
    error_log /var/log/nginx/error.log warn;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 120;
    tcp_nodelay on;
    server_tokens off;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 64k;
    gzip_http_version 1.1;
    gzip_comp_level 4;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    client_max_body_size 512m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    large_client_header_buffers 4 4k;
    client_header_buffer_size 4k;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;
    include /etc/nginx/conf.d/*.conf;
}

# 创建引用目录

root@ubuntu:~/zabbix-6.0.36# mkdir -p /etc/nginx/conf.d

# 创建Zabbix配置文件

root@ubuntu:~/zabbix-6.0.36# vim /etc/nginx/conf.d/zabbix.conf

server {
    listen 80;
    server_name localhost;
    access_log /var/log/nginx/access_zabbix.log json;
    error_log /var/log/nginx/error_zabbix.log warn;
    location / {
    root /usr/share/nginx/html/zabbix-6.0.36;
    index index.php index.html index.htm;
    }
    location ~* \.php$ {
    root /usr/share/nginx/html/zabbix-6.0.36;
    fastcgi_connect_timeout 300s;
    fastcgi_send_timeout 300s;
    fastcgi_read_timeout 300s;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
}

21)重载Nginx

root@ubuntu:~/zabbix-6.0.36# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

root@ubuntu:~/zabbix-6.0.36# systemctl reload nginx

root@ubuntu:~/zabbix-6.0.36# systemctl status nginx

22)Zabbix Web配置

1、浏览器访问:http://192.168.3.137,如下图所示

Ubuntu 22.04基于lnmp环境部署Zabbix 6.0 LTS

2、检查必要条件

3、配置数据库连接信息

4、配置Zabbix Server名称

5、安装成功

6、登录Zabbix

# 输入默认用户名:Admin和密码:zabbix,如下图所示

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信号已复制
微信公众号
微信扫一扫,关注我!
weinxin
公众号已复制
小柒博客
  • 本文由 小柒博客 发表于 2024年11月26日 14:31:12
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/10370.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证