一、實(shí)驗(yàn)環(huán)境準(zhǔn)備
Rhel 7.6 x86_64(server)
192.168.163.72
Rhel 6.5 x86_64(agent)
192.168.163.61
均已配置操作安裝光盤為YUM源
安裝包準(zhǔn)備如下圖:
二、實(shí)驗(yàn)內(nèi)容
源碼安裝zabbix,以及相關(guān)的nginx、PHP、mysql
添加zabbix服務(wù)器自身到監(jiān)控里
添加一臺(tái)agent客戶端
三、前期準(zhǔn)備
(1)?關(guān)閉selinux及防火墻
#sed -ri '/^SELINUX=*/cSELINUX=disabled' /etc/selinux/config
#setenforce 0
#systemctl stop firewalld.service && systemctl disable firewalld.service
(2)?安裝目錄準(zhǔn)備
#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
創(chuàng)建軟鏈接的目的是方便日后升級(jí)維護(hù)使用
(3)?創(chuàng)建普通用戶
#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)?創(chuàng)建所需要的文件及文件夾
#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登錄認(rèn)證
vim /etc/my.cnf
[mysqld]
datadir=/mnt/hg/mysql-last/data??????????????#數(shù)據(jù)存儲(chǔ)的地方
socket=/mnt/hg/mysql-last/mysql.sock?????????#sock文件的路徑
skip-grant-tables?????????????????????????????#跳過登錄認(rèn)證
user=mysql
explicit_defaults_for_timestamp=true
[mysqld_safe]
log-error=/mnt/hg/mysql-last/log/mariadb.log??#錯(cuò)誤日志存放的地方
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
重新加載環(huán)境變量
#source /etc/profile
③?初始化及啟動(dòng)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/
④?導(dǎo)入zabbix初始庫
#tar -xvf zabbix-4.2.1.tar.gz
#cd zabbix-4.2.1/database/mysql/
#mysql -u root -p
在mysql里執(zhí)行:
>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;
⑤?恢復(fù)需要密碼登錄mysql
vim /etc/my.cnf
去掉skip-grant-tables
重新啟動(dòng)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
重新加載環(huán)境變量
#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; ?####暫時(shí)僅修改啟動(dòng)用戶即可
(6)?啟動(dòng)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)?拷貝服務(wù)和配置文件
#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)?啟動(dòng)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)?測(cè)試PHP效果
① 編寫測(cè)試頁面
vim /mnt/hg/nginx-last/html/index.php
<?php
phpinfo();
?>
② 重新加載nginx配置,測(cè)試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
默認(rèn)賬號(hào)admin,默認(rèn)密碼zabbix
(8)?添加第一臺(tái)服務(wù)器監(jiān)控(即監(jiān)控zabbix server自身)
① 啟動(dòng)zabbix服務(wù)端
#zabbix_server
② 啟動(dòng)zabbix客戶端
#zabbix_agentd
③ 添加第一臺(tái)服務(wù)器
(9)?添加第二胎服務(wù)器監(jiān)控
① 安裝客戶端
#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
③ 啟動(dòng)zabbix客戶端
#/mnt/hg/zabbix-last/sbin/zabbix_agentd
④ 添加新的host主機(jī)監(jiān)控
來源:
http://www.icode9.com/content-4-219701.html