春风十里不如你 —— Taozi - php
https://xiongan.host/index.php/tag/php/
-
【Zabbix】部署监控软件
https://xiongan.host/index.php/archives/190/
2022-12-15T17:43:00+08:00
介绍zabbix是一个监控软件,其可以监控各种网络参数,保证企业服务架构安全运营,同时支持灵活的告警机制,可以使得运维人员快速定位故障、解决问题。zabbix支持分布式功能,支持复杂架构下的监控解决方案,也支持web页面,为主机监控提供了良好直观的展现。部署安装httpd和php7服务端:[root@srv-tz ~]# yum install -y[root@srv-tz ~]# systemctl enable --now httpd客户端:[root@client01 ~]# yum install -y yum-plugin-priorities && yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm -y
#修改repo配置文件
[root@client01 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/remi-safe.repo
[root@client01 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/remi-safe.repo
#安装php扩展
[root@client01 ~]# yum --enablerepo=remi-safe,epel install php72 php72-php-pear php72-php-mbstring -y
#启动和自启php
[root@client01 ~]# scl enable php72 bash
#查看php版本信息
[root@client01 ~]# php -v
PHP 7.2.34 (cli) (built: Oct 24 2022 10:27:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies编辑脚本文件
[root@client01 ~]# vim /etc/profile.d/php72.sh
#!/bin/bash
source /opt/remi/php72/enable
export X_SCLS="`scl enable php72 'echo $X_SCLS'`"
#安装php从remi源中
[root@client01 ~]# yum --enablerepo=remi-safe,epel -y install php72-php
[root@client01 ~]# systemctl enable --now httpd
#写入页面
[root@client01 ~]# echo '<?php phpinfo(); ?>' > /var/www/html/info.php
#查看页面
[root@client01 ~]# curl http://localhost/info.php | grep 'PHP Version' | tail -1 | sed --e 's/<[^>]*>//g'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 69230 0 69230 0 0 6822k 0 --:--:-- --:--:-- --:--:-- 7511k
PHP Version 7.2.34安装及配置 MariaDB安装环境服务端:[root@srv-tz ~]# yum install centos-release-scl-rh centos-release-scl -y
#修改配置文件
[root@srv-tz ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@srv-tz ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
[root@srv-tz ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@srv-tz ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
#安装
[root@srv-tz ~]# yum --enablerepo=centos-sclo-rh install rh-mariadb103-mariadb-server -y启用 MariaDB 环境#运行mariadb
[root@srv-tz ~]# scl enable rh-mariadb103 bash
#查看版本
[root@srv-tz ~]# mysql -V
mysql Ver 15.1 Distrib 10.3.35-MariaDB, for Linux (x86_64) using EditLine wrapper
#写脚本
[root@srv-tz ~]# vim /etc/profile.d/rh-mariadb103.sh
#!/bin/bash
source /opt/rh/rh-mariadb103/enable
export X_SCLS="`scl enable rh-mariadb103 'echo $X_SCLS'`"
#启动运行
[root@srv-tz my.cnf.d]# systemctl enable --now rh-mariadb103-mariadb
#开始部署安装
[root@srv-tz my.cnf.d]# mysql_secure_installation
开始需要设置一个密码
按照提示进行确认即可最后会提示安装成功
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!安装 Zabbix Server[root@srv-tz ~]# yum install https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm -y
[root@srv-tz ~]# yum-config-manager --enable zabbix-frontend
[root@srv-tz ~]# yum --enablerepo=centos-sclo-rh install zabbix-server-mysql zabbix-web-mysql-scl zabbix-apache-conf-scl zabbix-agent zabbix-get -y配置 Zabbix Server配置 Zabbix Server 数据库#登录数据库
[root@srv-tz ~]# mysql -uroot -p123456
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'password';
Query OK, 0 rows affected (0.028 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
[root@srv-tz ~]# cd /usr/share/doc/zabbix-server-mysql-5.0.30/
[root@srv-tz zabbix-server-mysql-5.0.30]# ls
AUTHORS ChangeLog COPYING create.sql.gz double.sql NEWS README
[root@srv-tz zabbix-server-mysql-5.0.30]# gunzip create.sql.gz
[root@srv-tz zabbix-server-mysql-5.0.30]# mysql -u root -p zabbix < create.sql
输入密码123456设置SElinux[root@srv-tz ~]# setsebool -P zabbix_can_network on
[root@srv-tz ~]# setsebool -P httpd_can_connect_zabbix on
[root@srv-tz ~]# setsebool -P domain_can_mmap_files on
[root@srv-tz ~]# setsebool -P daemons_enable_cluster_mode on
[root@srv-tz ~]# vim zabbix_server.te
module zabbix_server 1.0;
require {
type zabbix_t;
type zabbix_agent_t;
type rpm_exec_t;
type rpm_var_lib_t;
class file { execute execute_no_trans map open };
class capability dac_override;
}
#============= zabbix_t ==============
allow zabbix_t self:capability dac_override;
#============= zabbix_agent_t ==============
allow zabbix_agent_t rpm_var_lib_t:file open;
allow zabbix_agent_t rpm_exec_t:file { execute execute_no_trans map };
[root@srv-tz ~]# checkmodule -m -M -o zabbix_server.mod zabbix_server.te
checkmodule: loading policy configuration from zabbix_server.te
checkmodule: policy configuration loaded
checkmodule: writing binary representation (version 19) to zabbix_server.mod
[root@srv-tz ~]# semodule_package --outfile zabbix_server.pp --module zabbix_server.mod
[root@srv-tz ~]# semodule -i zabbix_server.ppFirewall设置[root@srv-tz ~]# firewall-cmd --add-service={http,https} --permanent
success
[root@srv-tz ~]# firewall-cmd --add-port={10050/tcp,10051/tcp} --permanent
success
[root@srv-tz ~]# firewall-cmd --reload
success配置 Zabbix Agentd[root@srv-tz ~]# vim /etc/zabbix/zabbix_agentd.conf
//* 更改 117 行,指定 Zabbix Server 的 IP
Server=127.0.0.1
//* 更改 158 行,指定 Zabbix Server 的 IP
ServerActive=127.0.0.1
//* 更改 169 行,指定 Zabbix Server 的 FQDN
Hostname=srv-tz
[root@srv-tz ~]# systemctl enable --now zabbix-agent为 Zabbix Server 配置 httpd 服务[root@srv-tz ~]# vim /etc/httpd/conf.d/zabbix.conf
//* 更改 10 行,允许指定网络访问
#Require all granted
Require ip 127.0.0.1 192.168.123.0/24
#定义 zabbix 的 timezone
[root@srv-tz ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
//* 更改 24 行
php_value[date.timezone] = Asia/Shanghai
[root@srv-tz ~]# systemctl enable --now httpd rh-php72-php-fpm访问webhttp:ip/zabbix进行页面安装配置数据库 账号zabbix 密码为password安装成功后默认账号Admin 密码zabbix