Zabbix监控多台服务器及公司官网

我要开发同款
闫泽亮2022年04月06日
550阅读

作品详情

需要准备环境:MySQL 5.6,PHP 7.2,Nginx,CentOS 7(或者Alibaba Cloud Linux)注意:YUM安装zabbix5.0的话,下载下来的yum资源中自带PHP7.2以及NGINX。如果服务器已存在PHP其他版本和NGINX,请修改php的监听端口,以及在原有的NGINX配置中做一下NGINX代理转发。修改PHP监听端口方法:/etc/php-fpm.d/www.conf中的listen = 127.0.0.1:9000改为listen = 127.0.0.1:8999/etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf新建NGINX代理配置:server { listen 8001; server_name example.com; root /usr/share/zabbix; index index.php; location = /favicon.ico { log_not_found off; } location / { try_files $uri $uri/ =404; } location /assets { access_log off; expires 10d; } location ~ /\.ht { deny all; } location ~ /(api\/|conf[^\.]|include|locale|vendor) { deny all; return 404; } location ~ [^/]\.php(/|$) { fastcgi_pass unix:/var/opt/rh/rh-php72/run/php-fpm/zabbix.sock;# fastcgi_pass unix:/var/opt/rh/rh-php73/run/php-fpm/zabbix.sock; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; fastcgi_param DOCUMENT_ROOT /usr/share/zabbix; fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name; fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; }}下载安装zabbix5.0官方镜像网址——》https://www.zabbix.com/download选择完毕适用于自己系统的软件适配包。(因为没有适配Alibaba Cloud Linux,这里可以默认选择CentOS7,区别在于待会安装zabbix前端web组件时,需要解决一下依赖关系。如果不解决依赖关系,yum安装会报错。)a.安装zabbix软件的yum源rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpmyum clean allb.安装zabbix服务端以及客户端yum install zabbix-server-mysql zabbix-agent注意:如果此处报错,没有PHP7.2环境,请先安装PHP7.2环境,以及对应的php-mysqlnd组件,安装方法如下:安装PHP7.2yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-develsystemctl enable php-fpm.servicesystemctl start php-fpm.service 安装php-mysqlnd依赖yum install -y php72w-mysqlndc.安装zabbix前端展示页面yum install centos-release-scl编辑配置文件 /etc/yum.repos.d/zabbix.repo并且启动zabbix-frontend描述文件,把配置文件中的enable=0,修改为enable=1。[zabbix-frontend]...enabled=1...注意:此处yum install centos-release-scl报错已加载插件:fastestmirror, langpacksRepository base is listed more than once in the configurationRepository updates is listed more than once in the configurationRepository extras is listed more than once in the configurationLoading mirror speeds from cached hostfile * webtatic: uk.repo.webtatic.com没有可用软件包 alibaba-release-scl。错误:无须任何处理原因是因为我们在官网下载Zabbix 5.0版本时选择的是CentOS7的版本。但是我们的服务器操作系统是Alibaba Cloud Linux。导致yum匹配源错误导致。cat /etv/redhat-releaseAlibaba Cloud Linux (Aliyun Linux) release 2.1903 LTS (Hunting Beagle) 解决方法:rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl-rh/2/3.el7.centos/noarch/centos-release-scl-rh-2-3.el7.centos.noarch.rpmrpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl/2/3.el7.centos/noarch/centos-release-scl-2-3.el7.centos.noarch.rpm安装完CentOS7的SCL之后,再次执行yum install centos-release-scl已加载插件:fastestmirror, langpacksRepository base is listed more than once in the configurationRepository updates is listed more than once in the configurationRepository extras is listed more than once in the configurationLoading mirror speeds from cached hostfile * centos-sclo-rh: mirrors.aliyun.com * centos-sclo-sclo: mirrors.aliyun.com * webtatic: uk.repo.webtatic.comcentos-sclo-rh | 3.0 kB 00:00:00 centos-sclo-sclo | 3.0 kB 00:00:00 (1/2): centos-sclo-sclo/x86_64/primary_db | 300 kB 00:00:00 (2/2): centos-sclo-rh/x86_64/primary_db | 3.2 MB 00:00:00 无须任何处理出现centos-sclo-sclo/x86_64/primary_db和centos-sclo-rh/x86_64/primary_db则证明成功重新执行一下 : yum install zabbix-server-mysql zabbix-agent安装zabbix前端展示页面,此时可以解决所有报错提示。d.创建初始数据库登录服务器创建数据库和用户注意:如果mysql未添加到环境变量当中,此处的命令行内使用绝对路径:/opt/zbox/run/mysql/mysqlmysql -uroot -p输入密码mysql> create database zabbix character set utf8 collate utf8_bin;mysql> create user zabbix@localhost identified by 'password';mysql> grant all privileges on zabbix.* to zabbix@localhost;mysql> quit;导入初始架构和数据,系统将提示您输入新创建的密码。zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbixe. 为Zabbix server配置数据库编辑配置文件 /etc/zabbix/zabbix_server.conf(注意,此处需要设置刚刚数据库内设置的密码)DBPassword=passwordf. 为Zabbix前端配置PHP编辑配置文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf, 删除'listen' 和 'server_name' 字符前的注释符号listen 80;server_name example.com;如果80端口被占用,请修改为其他端口编辑配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf, 增加 nginx 到listen.acl_users 字段后面listen.acl_users = apache,nginx默认为listen.acl_users = apache,增加一个nginx把PHP配置文件中时区前的注释删掉,并且由原来的Europe/Riga改为Asia/Shanghai或者Asia/Chongqing; php_value[date.timezone] = Europe/Riga删掉文件中的 " ; " 符号,修改时区为亚洲上海或者亚洲重庆。g.启动zabbix server和agent进程启动Zabbix server和agent进程,并为它们设置开机自启:systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpmsystemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpmh.配置zabbix前端访问http://[域名] 或者http://[IP : prot]
查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论