您好,登錄后才能下訂單哦!
一、準備工作:
1、演示環境:
IP | 操作系統 | 主機名 | 部署軟件包 |
192.168.0.120 | CentOS ? 7.7 x86_64 | zabbix-server | Nginx(nginx-1.16.1.tar.gz) CMake(cmake-3.15.3.tar.gz) Boost ? Library(boost_1_59_0.tar.gz) MySQL(mysql-5.7.27.tar.gz) Libzip(libzip-1.5.2.tar.xz) PHP(php-7.3.9.tar.xz) JDK(jdk-8u221-linux-x64.tar.gz) Zabbix(zabbix-4.2.6.tar.gz) |
2、關閉SELinux和firewalld
3、配置epel源
4、配置虛機時間同步
5、配置主機名
6、配置/etc/hosts文件:
# vim /etc/hosts --> 192.168.0.120 zabbix-server
7、下載所需軟件包:
(1)Nginx:http://nginx.org/en/download.html
(2)CMake:https://cmake.org/download/
(3)Boost Library:http://www.boost.org/
(4)MySQL:https://dev.mysql.com/downloads/mysql/
(5)Libzip:https://libzip.org/download/
(6)PHP:https://www.php.net/downloads.php
(7)JDK:https://www.oracle.com/technetwork/java/javase/downloads/index.html
(8)Zabbix:https://www.zabbix.com/download/
二、搭建LNMP環境:
1、部署Nginx:
(1)安裝開發環境:# yum -y groupinstall "Development Tools"
(2)安裝依賴軟件包:# yum -y install pcre-devel zlib-devel openssl-devel libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed geoip-devel
(3)創建nginx用戶和組:
# groupadd -r nginx
# useradd -g nginx -r -s /sbin/nologin nginx
# id nginx
(4)編譯安裝Nginx:
# tar -xf nginx-1.16.1.tar.gz -C /usr/src
# cd /usr/src/nginx-1.16.1
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module --with-stream_ssl_preread_module --with-compat --with-pcre
# make && make install
(5)配置Nginx環境變量:
# vim /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH
# . /etc/profile.d/nginx.sh
# nginx -v
# nginx -h
(6)啟動Nginx:
# nginx -t
# nginx
# ps aux | grep nginx
# ss -tunlp | grep -w :80
(7)配置Nginx開機自啟:
# vim /etc/rc.d/rc.local
/usr/local/nginx/sbin/nginx
# chmod +x /etc/rc.d/rc.local
(8)瀏覽器訪問http://192.168.0.120
2、部署MySQL:
(1)關閉虛機,添加一塊10G的新硬盤,用于存放MySQL數據:
(2)開啟虛機,創建LVM邏輯卷,方便日后擴容:
a、磁盤分區:
# fdisk -l | grep /dev/sdb
# fdisk /dev/sdb --> n --> p --> 回車 --> 回車 --> 回車 --> t --> 8e --> p --> w
# partx -a /dev/sdb
備注:忽略錯誤提示“partx: /dev/sdb: error adding partition 1”
# cat /proc/partitions
b、創建PV:# pvcreate /dev/sdb1? # pvs
c、創建VG:# vgcreate mysqlvg /dev/sdb1? # vgs
d、創建LV:# lvcreate -l +100%FREE mysqlvg -n mysqldata? # lvs
e、格式化LVM分區:# mke2fs -t ext4 /dev/mysqlvg/mysqldata
f、創建掛載點:# mkdir -pv /data
g、開機自動掛載:
# vim /etc/fstab --> /dev/mysqlvg/mysqldata ?/data ?ext4? defaults? 0? 0
h、掛載分區:# mount -a
i、查看分區信息:
# mount | grep mysqldata
# df -Th
(3)安裝依賴軟件包:
# yum -y install gcc gcc-c++ make libxml2-devel ncurses-devel openssl openssl-devel zlib-devel bison-devel
(4)創建mysql用戶和組:
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin mysql
# id mysql
(5)創建MySQL安裝目錄:# mkdir -pv /usr/local/mysql
(6)修改安裝目錄權限:# chown -R mysql.mysql /usr/local/mysql
(7)創建用于存放MySQL數據目錄:# mkdir -pv /data/mysql
(8)修改數據目錄權限:
# chown -R mysql.mysql /data/mysql
# chmod -R o-rx /data/mysql
(9)刪除CentOS 7.7內置的MariaDB相關組件:
# rpm -qa | grep -i mariadb --> mariadb-libs-5.5.64-1.el7.x86_64
# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
如果之前安裝過MySQL,先刪除:# rpm -qa | grep -i mysql
如果存在/etc/my.cnf配置文件,先刪除:# rm -rf /etc/my.cnf
(10)編譯安裝CMake:
# which cmake
# cmake --version
# tar -xf cmake-3.15.3.tar.gz -C /usr/src
# cd /usr/src/cmake-3.15.3
# ./bootstrap
# gmake && gmake install
# which cmake --> /usr/local/bin/cmake
# cmake --version
備注:MySQL 5.5版本之后,不再使用./configure,而是使用CMake
(11)解壓Boost庫:
# tar -xf boost_1_59_0.tar.gz -C /usr/local
# cd /usr/local
# mv boost_1_59_0 boost
備注:MySQL 5.7版本編譯安裝時需要Boost庫支持,且建議Boost庫版本為1.59.0
(12)編譯安裝MySQL:
# tar -xf mysql-5.7.27.tar.gz -C /usr/src
# cd /usr/src/mysql-5.7.27
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_DEBUG=0 \
-DWITH_BOOST=/usr/local/boost
# make && make install
備注:編譯安裝需要很長時間
(13)創建MySQL配置文件:
# vim /etc/my.cnf
[mysqld]
port=3306
socket=/usr/local/mysql/mysql.sock
datadir=/data/mysql
basedir=/usr/local/mysql
lower_case_table_names=1
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
innodb_file_per_table=1
skip_name_resolve=1
slow_query_log=1
slow_query_log_file=mysql-slow.log
symbolic-links=0
explicit_defaults_for_timestamp=1
server_id=1
sync_binlog=1
innodb_flush_log_at_trx_commit=1
log_bin=mysql-bin
log_bin_index=mysql-bin.index
binlog_format=mixed
[mysqld_safe]
log-error=/var/log/mysql.log
pid-file=/var/run/mysql.pid
(14)初始化MySQL數據庫:
# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
備注:
a、初始化前確保/data/mysql目錄為空
b、MySQL 5.7版本初始化數據庫時不再使用mysql_install_db,而是使用mysqld --initialize
c、參數--defaults-file=/etc/my.cnf要放在所有參數的第一位
d、會顯示root@localhost用戶的初始密碼
(15)配置MySQL環境變量:
# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
# . /etc/profile.d/mysql.sh
# mysql -V
# mysql --help | less
(16)通過mysql.server管理服務進程:
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
(17)配置MySQL開機自啟:
# chkconfig --add mysqld
# chkconfig mysqld on
(18)啟動MySQL:
# systemctl start mysqld.service
# systemctl status mysqld.service
# ps aux | grep mysqld
# ss -tunlp | grep -w :3306
# tail -100 /var/log/mysql.log
(19)配置MySQL安全向導:# mysql_secure_installation
(20)登錄MySQL,創建并授權'root'@'192.168.0.%'用戶遠程管理:
# mysql -uroot -p
mysql> create user 'root'@'192.168.0.%' identified by '123456';
mysql> grant all on *.* to 'root'@'192.168.0.%';
mysql> flush privileges;
3、部署PHP:
(1)安裝依賴軟件包:
# yum -y install gcc gcc-c++ make pcre-devel zlib-devel openssl openssl-devel libxml2-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel expat-devel bzip2-devel curl-devel gmp-devel libc-client-devel recode-devel net-snmp-devel libtidy-devel readline-devel libxslt-devel libicu-devel
(2)創建www用戶和組:
# groupadd -r www
# useradd -g www -r -s /sbin/nologin www
# id www
(3)編譯安裝Libzip:
# tar -xf libzip-1.5.2.tar.xz -C /usr/src
# cd /usr/src/libzip-1.5.2
# mkdir build
# cd build
# cmake ..
# make && make install
備注:
a、不編譯安裝Libzip,會提示“configure: error: Please reinstall the libzip distribution”
b、需要先編譯安裝CMake,之前編譯安裝MySQL時已經安裝過
(4)修改ld.so.conf配置文件:
# vim /etc/ld.so.conf,新增如下代碼:
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
# ldconfig -v
備注:不執行此步驟,在編譯安裝PHP時會提示“configure: error: off_t undefined; check your library configuration”
(5)編譯安裝PHP:
# tar -xf php-7.3.9.tar.xz -C /usr/src
# cd /usr/src/php-7.3.9
# ./configure --prefix=/usr/local/php --disable-rpath --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-litespeed --enable-phpdbg --enable-phpdbg-webhelper --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --enable-sigchild --enable-libgcc --disable-ipv6 --enable-dtrace --with-libxml-dir --with-openssl --with-kerberos --with-pcre-regex --with-zlib --with-zlib-dir --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --disable-fileinfo --with-pcre-dir --enable-ftp --with-openssl-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gettext --with-mhash --enable-intl --enable-mbstring --enable-mbregex --with-mysqli=mysqlnd --with-mysql-sock=/usr/local/mysql/mysql.sock --enable-pcntl -with-pdo-mysql=mysqlnd --with-readline --with-recode --enable-shmop --with-snmp --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --enable-wddx --with-xmlrpc --with-iconv-dir --with-xsl --enable-zip --with-libzip --enable-mysqlnd --with-pear
# make && make install
備注:編譯安裝需要很長時間
(6)創建php.ini配置文件:# cp /usr/src/php-7.3.9/php.ini-production /usr/local/php/etc/php.ini
(7)創建php-fpm.conf配置文件:# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
備注:php-fpm,PHP FastCGI Process Manager,PHP FastCGI進程管理器,通過FastCGI方式,將PHP作為獨立的服務運行
(8)創建并修改www.conf配置文件:
# cd /usr/local/php/etc/php-fpm.d
# cp www.conf.default www.conf
# vim www.conf
修改前 | 修改后 |
listen ? = 127.0.0.1:9000 | listen ? = 192.168.0.120:9000 |
?(9)配置PHP環境變量:
# vim /etc/profile.d/php.sh
export PATH=/usr/local/php/sbin:/usr/local/php/bin:$PATH
# . /etc/profile.d/php.sh
# php -v
# php -h | less
# php-fpm -h
(10)通過php-fpm.service管理服務進程:# cp /usr/src/php-7.3.9/sapi/fpm/php-fpm.service /usr/lib/systemd/system/
(11)啟動php-fpm:
# php-fpm -t
# systemctl start php-fpm.service
# systemctl status php-fpm.service
# ps aux | grep php-fpm
# ss -tunlp | grep 9000
# tail -100 /usr/local/php/var/log/php-fpm.log
(12)配置PHP開機自啟:# systemctl enable php-fpm.service
4、Nginx整合PHP:
(1)修改nginx.conf配置文件:
# cd /usr/local/nginx/conf
# vim nginx.conf
worker_processes? auto;
location / {
root?? html;
index? index.php index.html index.htm;
}
location ~ \.php$ {
root????????? html;
fastcgi_pass?? 192.168.0.120:9000;
fastcgi_index? index.php;
fastcgi_param? SCRIPT_FILENAME? $document_root$fastcgi_script_name;
include?????? fastcgi_params;
}
# nginx -t
# nginx -s reload
(2)創建測試頁:
# vim /usr/local/nginx/html/index.php
<?php
$conn=mysqli_connect("192.168.0.120","root","123456");
if ($conn)
echo "mysqli_connect success";
else
echo "mysqli_connect failure";
mysqli_close();
phpinfo();
?>
備注:如果在新版本PHP中使用舊版本PHP的mysql_connect()函數連接MySQL,會提示“undefined function mysql_connect()”。從PHP 5.5版本開始,MySQL就不推薦使用mysql_connect()函數,屬于廢棄函數,PHP 7中已經徹底不支持,增加了mysqli_connect()函數。從某種意義上說,mysqli是mysql系統函數的增強版,更穩定、更高效、更安全,屬于面向對象,用對象的方式操作驅動MySQL數據庫。
(3)瀏覽器訪問http://192.168.0.120
停止MySQL:# systemctl stop mysqld.service
刷新頁面:
三、搭建Zabbix:
1、部署Zabbix:
(1)安裝依賴軟件包:
# yum -y install gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel libevent-devel zlib-devel openssl openssl-devel fping
(2)創建zabbix用戶和組:
# groupadd -r zabbix
# useradd -g zabbix -r -s /sbin/nologin zabbix
# id zabbix
(3)解壓JDK:
# java -version
# tar -xf jdk-8u221-linux-x64.tar.gz -C /usr/local
# cd /usr/local
# ln -sv jdk1.8.0_221 jdk
備注:編譯安裝Zabbix 4.2.6時如果啟用--enable-java選項,需要配置JDK
(4)配置JDK環境變量:
# vim /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
# . /etc/profile.d/jdk.sh
# echo $JAVA_HOME
# java -version
(5)查找mysql_config路徑:# find / -name mysql_config --> /usr/local/mysql/bin/mysql_config
(6)編譯安裝Zabbix:
# tar -xf zabbix-4.2.6.tar.gz -C /usr/src
# cd /usr/src/zabbix-4.2.6
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --enable-java --with-mysql=/usr/local/mysql/bin/mysql_config --with-libxml2 --with-net-snmp --with-zlib --with-libevent --with-openssl --with-libcurl
# make && make install
(7)配置Zabbix環境變量:
# vim /etc/profile.d/zabbix.sh
export PATH=/usr/local/zabbix/sbin:/usr/local/zabbix/bin:$PATH
# . /etc/profile.d/zabbix.sh
# ln -sv /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20
備注:不執行此步驟,在執行# zabbix_server --version命令時會提示“zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory”
# zabbix_server --version
# zabbix_server -h | less
2、配置Zabbix:
(1)登錄MySQL,創建zabbix數據庫和'zabbix'@'192.168.0.%'用戶,并授權'zabbix'@'192.168.0.%'用戶遠程管理:
# mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user 'zabbix'@'192.168.0.%' identified by '123456';
mysql> grant all on zabbix.* to 'zabbix'@'192.168.0.%';
mysql> flush privileges;
(2)初始化zabbix數據庫:
mysql> use zabbix;
mysql> source /usr/src/zabbix-4.2.6/database/mysql/schema.sql
mysql> source /usr/src/zabbix-4.2.6/database/mysql/images.sql
mysql> source /usr/src/zabbix-4.2.6/database/mysql/data.sql
備注:SQL語句的導入順序不能改變
(3)修改zabbix_server.conf配置文件:
# cd /usr/local/zabbix/etc
# cp zabbix_server.conf zabbix_server.conf.bak
# vim zabbix_server.conf
修改前 | 修改后 |
# ListenPort=10051 | ListenPort=10051 |
LogFile=/tmp/zabbix_server.log | LogFile=/usr/local/zabbix/zabbix_server.log |
# DBHost=localhost | DBHost=192.168.0.120 |
DBName=zabbix | 保持默認 |
DBUser=zabbix | 保持默認 |
# DBPassword= | DBPassword=123456 |
# DBSocket= | DBSocket=/usr/local/mysql/mysql.sock |
# DBPort= | DBPort=3306 |
# ListenIP=127.0.0.1 | ListenIP=192.168.0.120 |
# ? AlertScriptsPath=${datadir}/zabbix/alertscripts | AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts |
# ? ExternalScripts=${datadir}/zabbix/externalscripts | ExternalScripts=/usr/local/zabbix/share/zabbix/externalscripts |
# FpingLocation=/usr/sbin/fping | FpingLocation=/usr/sbin/fping |
# AllowRoot=0 | AllowRoot=0 |
# User=zabbix | User=zabbix |
(4)修改安裝目錄權限:# chown -R zabbix.zabbix /usr/local/zabbix
(5)啟動zabbix_server:
# zabbix_server
# ps aux | grep zabbix_server
# ss -tunlp | grep 10051
# tail -100 /usr/local/zabbix/zabbix_server.log
(6)配置zabbix_server開機自啟:
# vim /etc/rc.d/rc.local
/usr/local/zabbix/sbin/zabbix_server
# chmod +x /etc/rc.d/rc.local
(7)創建Zabbix網頁存放目錄:# mkdir -pv /usr/local/nginx/html/zabbix
(8)復制PHP文件至Zabbix網頁存放目錄:
# cp -a /usr/src/zabbix-4.2.6/frontends/php/* /usr/local/nginx/html/zabbix/
(9)修改Zabbix網頁存放目錄權限:# chown -R nginx.nginx /usr/local/nginx
(10)瀏覽器訪問http://192.168.0.120/zabbix
(11)修改php.ini配置文件:
# vim /usr/local/php/etc/php.ini
修改前 | 修改后 |
post_max_size ? = 8M | post_max_size ? = 16M |
max_execution_time ? = 30 | max_execution_time ? = 300 |
max_input_time ? = 60 | max_input_time ? = 300 |
;date.timezone ? = | date.timezone ? = Asia/Shanghai |
# systemctl restart php-fpm.service
(12)瀏覽器刷新頁面,繼續訪問http://192.168.0.120/zabbix
備注:zabbix用戶沒有權限在nginx目錄中創建文件
(13)按提示下載zabbix.conf.php文件
(14)將下載的zabbix.conf.php文件上傳至/usr/local/nginx/html/zabbix/conf/目錄
(15)修改zabbix.conf.php文件權限:# chown nginx.nginx /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
(16)瀏覽器刷新頁面,繼續訪問http://192.168.0.120/zabbix
(17) 登錄Zabbix,用戶名Admin,密碼zabbix:
(18)修改Admin用戶默認密碼:
Administration --> Users --> Admin --> Change password --> 輸入2次新密碼root@123 --> Update
退出重新登錄:
(19) Zabbix Server暫時停止對自身服務器狀態監控:
Configuration --> Hosts --> 勾選Zabbix server --> Disable
(20)禁用guest用戶:
Administration --> User groups --> 勾選Guests組 --> Disable
Administration --> Users --> guest用戶的狀態已變為Disabled
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。