一、实验环境准备
Rhel 7.6 x86_64(server)192.168.163.72
Rhel 6.5 x86_64(agent)192.168.163.61
均已配置操作安装光盘为YUM源
安装包准备如下图:
二、实验内容
源码安装zabbix,以及相关的nginx、PHP、mysql
添加zabbix服务器自身到监控里
添加一台agent客户端
三、前期准备
(1) 关闭selinux及防火墙
#sed -ri '/^SELINUX=*/cSELINUX=disabled' /etc/selinux/config
#setenforce 0
#systemctl stop firewalld.service && systemctl disable firewalld.service
(2) 安装目录准备
#mkdir -pv /mnt/hg/{mysql-5.7.26,nginx-1.16.0,php-7.2.17,zabbix-4.2.1}
#mkdir -pv /mnt/hg/mysql-5.7.26/data
#ln -s /mnt/hg/mysql-5.7.26 /mnt/hg/mysql-last
#ln -s /mnt/hg/nginx-1.16.0 /mnt/hg/nginx-last
#ln -s /mnt/hg/php-7.2.17 /mnt/hg/php-last
#ln -s /mnt/hg/zabbix-4.2.1 /mnt/hg/zabbix-last
创建软链接的目的是方便日后升级维护使用
(3) 创建普通用户
#useradd -s /sbin/nologin mysql
#useradd -s /sbin/nologin nginx
#useradd -s /sbin/nologin zabbix
四、安装并配置mysql
(1) 解压mysql-5.7.26.tar.gz与boost_1_59_0.tar.gz
#tar -xvf mysql-5.7.26.tar.gz
#tar -xvf boost_1_59_0.tar.gz -C /mnt/hg/
(2) 安装依赖包
#yum install -y cmake gcc gcc-c++ openssl-devel ncurses-devel
(3) 编译安装
#cd mysql-5.7.26
#cmake \
-DCMAKE_INSTALL_PREFIX=/mnt/hg/mysql-5.7.26 \
-DMYSQL_DATADIR=/mnt/hg/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_unicode_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_BOOST=/mnt/hg/boost_1_59_0
#make -j4 && make install
(4) 创建所需要的文件及文件夹
#mkdir -pv /mnt/hg/mysql-last/log
#touch /mnt/hg/mysql-last/log/mariadb.log
#touch /mnt/hg/mysql-last/log/mariadb.pid
(5) 更改mysql-5.7.26文件夹的拥有者和拥有组
#cd /mnt/hg && chown mysql:mysql -R mysql-5.7.26
(6) mysql初始化操作
① 编辑/etc/my.cnf,跳过mysql登录认证
vim /etc/my.cnf
[mysqld]
datadir=/mnt/hg/mysql-last/data#数据存储的地方
socket=/mnt/hg/mysql-last/mysql.sock#sock文件的路径
skip-grant-tables#跳过登录认证
user=mysql
explicit_defaults_for_timestamp=true
[mysqld_safe]
log-error=/mnt/hg/mysql-last/log/mariadb.log#错误日志存放的地方
pid-file=/mnt/hg/mysql-last/log/mariadb.pid
② 添加mysql命令至PATH变量中
vim /etc/profile
####mysql path
export PATH=$PATH:/mnt/hg/mysql-last/support-files
export PATH=$PATH:/mnt/hg/mysql-last/bin
重新加载环境变量
#source /etc/profile
③ 初始化及启动mysql
#mysqld --initialize --user=mysql --basedir=/mnt/hg/mysql-last --datadir=/mnt/hg/mysql-last/data
#mysql.server start
#ln -s /mnt/hg/mysql-last/mysql.sock /tmp/
④ 导入zabbix初始库
#tar -xvf zabbix-4.2.1.tar.gz
#cd zabbix-4.2.1/database/mysql/
#mysql -u root -p
在mysql里执行:
>use mysql;
>create database zabbix default character set utf8;
>update user set authentication_string = password('hg'), password_expired = 'N', password_last_changed = now() where user = 'root';
>use zabbix;
>source schema.sql;
>source images.sql;
>source data.sql;
>quit;
⑤ 恢复需要密码登录mysql
vim /etc/my.cnf
去掉skip-grant-tables
重新启动mysql
#mysql.server restart
添加lib文件
#echo "/mnt/hg/mysql-last/lib" > /etc/ld.so.conf.d/mysql.conf
#ldconfig -v
五、安装并配置nginx
(1) 解压nginx-1.16.0.tar.gz
#tar -xvf nginx-1.16.0.tar.gz && cd nginx-1.16.0/
(2) 编译安装
#./configure --prefix=/mnt/hg/nginx-1.16.0 --user=nginx --group=nginx --without-select_module --without-poll_module --with-http_ssl_module --with-pcre --with-debug
#make -j4
#make install
(3) 添加nginx命令至PATH变量中
vim /etc/profile
####nginx path
export PATH=$PATH://mnt/hg/nginx-last/sbin
重新加载环境变量
#source /etc/profile
(4) 更改nginx-1.16.0文件夹的拥有者和拥有组
#cd /mnt/hg/
#chown nginx:nginx -R nginx-1.16.0
(5) 修改nginx.conf配置文件
vim /mnt/hg/nginx-last/conf/nginx.conf
user nginx; ####暂时仅修改启动用户即可
(6) 启动nginx
#nginx
六、安装并配置php
(1) 解压php-7.2.17.tar.gz
#tar -xvf php-7.2.17.tar.gz && cd php-7.2.17
(2) 安装依赖包
#yum install -y libxml2-devel openssl-devel net-snmp net-snmp-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel bzip2 bzip2-devel freetype-devel gmp-devel readline-devel libxslt-devel fontconfig
#make -j4
#make install
(3) 更改php-7.2.17文件夹的拥有者和拥有组
#cd /mnt/hg
#chown nginx:nginx -R php-7.2.17
(4) 拷贝服务和配置文件
#cd ~/zabbix/php-7.2.17
#cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
#cp /mnt/hg/php-7.2.17/etc/{php-fpm.conf.default,php-fpm.conf}
#cp /mnt/hg/php-7.2.17/etc/php-fpm.d/www.conf{.default,}
#cp php.ini-production /mnt/hg/php-7.2.17/lib/php.ini
(5) 修改php.ini配置文件
vim /mnt/hg/php-last/lib/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = PRC
(6) 启动PHP
#systemctl start php-fpm.service && systemctl enable php-fpm.service
(7) 编辑nginx.conf配置文件,使nginx支持PHP
vim /mnt/hg/nginx-last/conf/nginx.conf
location ~ "\.php$" {
root /mnt/hg/nginx-last/html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /mnt/hg/nginx-last/html$fastcgi_script_name;
include fastcgi_params;
}
(8) 测试PHP效果
① 编写测试页面
vim /mnt/hg/nginx-last/html/index.php
phpinfo();
?>
② 重新加载nginx配置,测试index.php页面
#nginx -s reload
七、安装并配置zabbix
(1) 安装依赖包
#yum localinstall -y libevent-devel-2.0.21-4.el7.x86_64.rpm
(2) 编译安装
#cd zabbix-4.2.1
#./configure --prefix=/mnt/hg/zabbix-4.2.1 --enable-server --enable-agent --with-mysql=/mnt/hg/mysql-last/bin/mysql_config --enable-ipv6 --with-netsnmp --with-libcurl --with-libxml2
#make -j4
#make install
(3) 添加zabbix命令至PATH变量中
vim /etc/profile
####zabbix path
export PATH=$PATH://mnt/hg/zabbix-last/sbin
(4) 修改zabbix_server.conf配置文件
vim /mnt/hg/zabbix-last/etc/zabbix_server.conf
DBUser=root
DBPassword=hg
(5) 拷贝zabbix页面至nginx,使nginx加载zabbix页面
#cp -R frontends/php/* /mnt/hg/nginx-last/html/
(6) 重新加载nginx配置,并访问index.php
#nginx -s reload
(7) 初始化zabbix
默认账号admin,默认密码zabbix
(8) 添加第一台服务器监控(即监控zabbix server自身)
① 启动zabbix服务端
#zabbix_server
② 启动zabbix客户端
#zabbix_agentd
③ 添加第一台服务器
(9) 添加第二胎服务器监控
① 安装客户端
#tar -xvf zabbix-4.2.1.tar.gz
#mkdir /mnt/hg && cd zabbix-4.2.1
#./configure --prefix=/mnt/hg/zabbix-4.2.1 --enable-agent
#make && make install
#ln -s /mnt/hg/zabbix-4.2.1/ /mnt/hg/zabbix-last
② 修改配置文件
Vim /mnt/hg/zabbix-last/etc/zabbix_agentd.conf
Server=192.168.163.72
ServerActive=192.168.163.72
Hostname=hg62
③ 启动zabbix客户端
#/mnt/hg/zabbix-last/sbin/zabbix_agentd
④ 添加新的host主机监控