- 一、服务器信息
操作系统:CentOS Linux release 7.6.1810 (Core)
环境:内网环境,无公网出口
YUM源:本地yum
MySQL版本:5.7.32
Nginx版本:nginx-1.22.0
PHP版本:php-7.4.30
Zabbix版本:zabbix-5.0.27
- 二、关闭防火墙
#systemctl stop firewalld
#systemctl disable firewalld
#setenforce 0
#vim /etc/selinux/config
SELINUX=disabled
下载地址:MySQL :: Download MySQL Community Server (Archived Versions)
3.1、卸载MYSQL
- 查看系统是否安装默认的mysql
# rpm -qa |grep -i mysql
如有,进行卸操作
#rpm -e --nodeps <包名>
- 确认是否卸载完成
#whereis mysql
#cd /;find / -name mysql
#cat /etc/passwd | grep mysql
#cat /etc/shadow | grep mysql
#cat /etc/group | grep mysql
- 删除MySQL用户和组
#userdel mysql
#groupdel mysql
3.2、安装MYSQL
#tar -xvf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
#yum remove mariadb-libs
#yum -y install perl-Data-Dumper
#yum -y install perl-JSON
#rpm -ivh mysql*.rpm
3.3、启动MySQL数据库
#service mysqld start
初始化 MySQL 数据库: [确定]
正在启动 mysqld: [确定]
3.4、设置root密码
- #查看随机密码:
#cat /var/log/mysqld.log |grep password
或
#grep 'temporary password' /var/log/mysqld.log
- #登录mysql数据库:
#mysql -uroot -p
使用得到的随机密码登录(复制生成的随机密码)
设置root密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'PASSWORD';
3.5、设置工具连接MySQL
#mysql -u root -p
mysql> use mysql;
mysql> select host from user where user='root';
mysql> update user set host = '%' where user ='root';
mysql> flush privileges;
mysql> select host from user where user='root';
4.1、安装依赖包
#yum -y install gcc make pcre-devel openssl-devel
4.2、创建Nginx用户
#useradd nginx
4.3、上传并解压nginx源码包
4.4、编译安装nginx
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream --with-http_gzip_static_module --with-pcre
# make && make install
4.5、把nginx命令制作软链接方便使用
# ln -s /usr/local/nginx/sbin/* /usr/local/bin/
4.6、启动Nginx
# nginx
下载地址:PHP: Downloadshttps://www.php.net/downloads
5.1、安装依赖包
# yum -y install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel openldap openldap-devel sqlite-devel oniguruma-devel
5.2、解压php的tar包,添加php用户和组
[root@tools]# cd /tools/
[root@tools]# tar -xvf php-7.4.30.tar.gz
[root@tools]# cd php-7.4.30/
[root@tools]# useradd php -s /sbin/nologin
5.3、编译安装,指定安装在/usr/local/php7
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --enable-bcmath --enable-gd --with-jpeg --with-freetype --enable-mbstring --enable-ftp --enable-sockets --with-gettext --enable-session --with-curl --enable-fpm --with-fpm-user=php --with-fpm-group=php --enable-pdo -enable-tokenizer --with-zip
- 编译安装报错No package 'oniguruma' found
上传下载好的oniguruma-6.7.0-1.el7.x86_64.rpm和oniguruma-devel-6.7.0-1.el7.x86_64.rpm
# rpm -ivh oniguruma-6.7.0-1.el7.x86_64.rpm oniguruma-devel-6.7.0-1.el7.x86_64.rpm
- 编译安装报错No package 'libzip' found
这里还需要手工编译安装libzip依赖包否则configure的时候会报以下错误:意思是 libzip的版本必须大于0.11 且 不能等于1.3.1或者1.7.0
下载地址:https://libzip.org/download/libzip-1.3.2.tar.gz
上传并解压源码包
# cd /tools/
# tar -xvf libzip-1.3.2.tar.gz
# cd libzip-1.3.2
# ./configure && make && make install
# export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
5.4、再次编译安装,指定安装在/usr/local/php7
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --enable-bcmath --enable-gd --with-jpeg --with-freetype --enable-mbstring --enable-ftp --enable-sockets --with-gettext --enable-session --with-curl --enable-fpm --with-fpm-user=php --with-fpm-group=php --enable-pdo -enable-tokenizer --with-zip
# make && make install
5.5、安装ldap扩展模块
# find / -name phpize //找出这个可执行文件
# cd /tools/php-7.4.30/ext/ldap
# /usr/local/php7/bin/phpize //到ldap的目录下执行该命令
# cp -frp /usr/lib64/libldap* /usr/lib/ //拷贝库文件,软链接也行
# ./configure --with-php-config=/usr/local/php7/bin/php-config
# make && make install //编译安装
记住/usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/,需要写在配置文件里。
5.6、参数配置
- 从源码包中拷贝配置文件
# cp php.ini-production /usr/local/php7/etc/php.ini
# vim /usr/local/php7/etc/php.ini
增加两行内容
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/"
extension=ldap.so //增加一行添加ldap模块
- 配置其他参数
max_execution_time = 300
post_max_size = 16M
max_input_time = 300
date.timezone = Asia/Shanghai
5.7、到安装目录修改配置文件名
# cd /usr/local/php7/etc/
# cp php-fpm.conf.default php-fpm.conf
# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
5.8、给php命令设置软链接方便使用
# ln -s /usr/local/php7/bin/* /usr/local/bin
# ln -s /usr/local/php7/sbin/* /usr/local/sbin
5.9、查看下php的版本
# php -v
5.10、启动php
php-fpm是php的管理工具,默认9000端口
# php-fpm
5.11、查看是否加载了ldap模块
# php -m | grep ldap
- 六、配置nginx可以支持php网页
# vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# nginx -t
# nginx -s reload
6.1、编写一个简单的php网页,验证访问nginx的php网页成功
# vim /usr/local/nginx/html/index.php
phpinfo();
?>
6.2、修改下内容测试一下php与mysql的连接
[root]# vim /usr/local/nginx/html/index.php
$mysqli = new mysqli("localhost", "root", "PASSWORD");
if(!$mysqli) {
echo"database error";
}else{
echo"php env successful";
}
$mysqli->close();
?>
- 七、Zabbix安装
下载地址:https://www.zabbix.com/cn/download_sources#50LTS
7.1、上传并解压源码包
# cd /tools/
# tar -xvf zabbix-5.0.27.tar.gz
# cd zabbix-5.0.27/
7.2、新建zabbix用户和组
# groupadd --system zabbix
# cd /home
# mkdir -m 755 zabbix
# chown zabbix:zabbix zabbix/
# useradd --system -g zabbix -d /home/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
7.3、在MySQL新建一个授权账户zabbix
# mysql -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';
7.4、初始化数据库
# cd /tools/zabbix-5.0.27/database/mysql/
# mysql -uzabbix -pHbis@123 zabbix < schema.sql
# mysql -uzabbix -pHbis@123 zabbix < images.sql
# mysql -uzabbix -pHbis@123 zabbix < data.sql
7.4、编译安装Zabbix
# yum -y install net-snmp-devel libevent-devel
# cd /tools/zabbix-5.0.27/
# ./configure --prefix=/home/zabbix/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
# make install
7.5、配置Zabbix_Server
# cd /home/zabbix/zabbix/
# mkdir -m 755 logs
# cd /home/
# chown -R zabbix:zabbix zabbix/
# vi /home/zabbix/zabbix/etc/zabbix_server.conf
LogFile=/home/zabbix/zabbix/logs/zabbix_server.log
PidFile=/home/zabbix/zabbix/logs/tmp/zabbix_server.pid
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=PASSWORD
DBSocket=/var/lib/mysql/mysql.sock
Timeout=10
LogSlowQueries=3000
Include=/home/zabbix/zabbix/etc/zabbix_server.conf.d/*.conf
StatsAllowedIP=127.0.0.1
7.6、安装前端web页面
Zabbix 前端是 PHP 编写的,所以必须运行在支持 PHP 的 Web 服务器上。只需要从ui路径下复制 PHP 文件到 Web 服务器的 HTML 文档目录,即可完成安装,我把整个ui目录都拷贝过去命名为zabbix
# cd /tools/zabbix-5.0.27/
# cp -r ui /usr/local/nginx/html/zabbix/
7.7、配置Zabbix_Agent
# vi /home/zabbix/zabbix/etc/zabbix_agentd.conf
PidFile=/home/zabbix/zabbix/zabbix_agentd.pid
LogFile=/home/zabbix/zabbix/logs/zabbix_agentd.log
Server=Zabbix_Server的IP
ServerActive=Zabbix_Server的IP
Hostname=Zabbix_Agent的IP
Include=/home/zabbix/zabbix/etc/zabbix_agentd.conf.d/*.conf
7.8、启动zabbix_server和zabbix_agent
# cd /home/zabbix/zabbix/sbin/
# ./zabbix_server -f -c ../etc/zabbix_server.conf &
# ./zabbix_agent &
检查下端口是否正常,服务器端监听10051,客户端监听10050
# netstat -antp | grep zabbix
- 八、初始化配置
- 验证访问http://ip:port/zabbix/,进行设置,点击Next Step
- 验证状态是否都是“OK”,点击Next Step
- 配置MySQL信息,点击Next Step
- 配置Zabbix_Server IP,点击Next Step
- 确认配置信息,点击Next Step
- 上传至/usr/local/nginx/html/zabbix/conf/
- 点击Back按钮,再次点击Next Step,并点击Login
- 填写用户名和密码,默认为Admin/zabbix
- 再次确认并点击Next Step
- 安装成功点击Finish
- 进入Zabbix控制台
来源地址:https://blog.csdn.net/zglx0213/article/details/126925708