CentOS7 LNMP環境搭建Zabbix3.0
阿新 • • 發佈:2019-02-04
安裝前的環境安裝
yum install -y autoconf make automake imake cmake gcc gcc-c++ libaio libaio-devel bzr bison expat-devel libtool ncurses5-devel gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel
yum install pcre*
yum install openssl*
yum install epel-release
yum clean all
yum repolist
安裝MySql 5.7
- 首先下載MySQL Yum repository,CentOS 7對應的下載連結如下
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
- 下載完成之後安裝下載好的rpm檔案
yum localinstall mysql57-community-release-el7-7.noarch.rpm
- 安裝完成之後驗證MySQL YUM repository
yum repolist enabled | grep "mysql.*-community.*"
如下圖所示,表示驗證成功:
安裝最新版的MySQL
yum install mysql-community-server
- 安裝完成之後啟動並檢視MySQL狀態:
service mysqld start
service mysqld status
- 手動驗證MySQL安裝的版本:
mysql --version
- 安裝MySQL 5.7之後,MySQL會生成一個隨機密碼
在/var/log/mysqld.log檔案中,使用如下命令檢視密碼:
grep 'temporary password' /var/log/mysqld.log
- 記錄密碼之後,執行 mysql_secure_installation初始化MySQL,初始化過程中會提示輸入隨機密碼
mysql_secure_installation
- 使用新設定的密碼連線MySQL:(ps:有密碼複雜要求)
mysql -u root -p
- 至此,MySQL 5.7安裝完成。
安裝Nginx
- 首先下載Nginx的最新穩定版,本示例使用的版本是1.10.2,下載之後解壓壓縮包:
tar zxvf nginx-1.10.2.tar.gz
- 進入解壓之後的Nginx目錄,執行configure
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre
- 編譯安裝
make
make install
- 測試Nginx
/usr/local/nginx/sbin/nginx -t
安裝PHP
- 首先安裝開發軟體包:
yum -y groupinstall "Development Tools"
- 下載PHP最新穩定版,解壓安裝包,本示例使用的是PHP 5.6.27
tar -zxvf php-5.6.27.tar.gz
- 切換到PHP目錄,執行configure:
./configure -prefix=/usr/local/php -with-config-file-path=/usr/local/php/etc -with-bz2 -with-curl -enable-ftp -enable-sockets -disable-ipv6 -with-gd -with-jpeg-dir=/usr/local -with-png-dir=/usr/local -with-freetype-dir=/usr/local -enable-gd-native-ttf -with-iconv-dir=/usr/local -enable-mbstring -enable-calendar -with-gettext -with-libxml-dir=/usr/local -with-zlib -with-pdo-mysql=mysqlnd -with-mysqli=mysqlnd -with-mysql=mysqlnd -enable-dom -enable-xml -enable-fpm -with-libdir=lib64 -enable-bcmath
make
make install
- 複製安裝包中的php.ini-production到 /usr/local/php/etc/php.ini
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default.conf php-fpm.conf
- 測試PHP安裝是否成功。
/usr/local/php/sbin/php-fpm -t
- 測試成功之後啟動PHP
cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
service php-fpm start
- 新增到開機啟動
chkconfig php-fpm on
- 檢查是否啟動
ps aux |grep php-fpm
netstat -ant |grep 9000
配置Nginx執行PHP
- 修改Nginx配置檔案如下
vim /usr/local/nginx/conf/nginx.conf
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
- 建立PHP測試網頁
vim /usr/local/nginx/html/test.php
<?php
phpinfo();
?>
- 啟動nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
在瀏覽器中輸入localhost/test.php,測試php頁面
配置PHP引數,Zabbix的硬體要求
vim /usr/local/php/etc/php.ini
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
- 重啟PHP
service php-pfm stop
service php-pfm start
安裝Zabbix
- 下載安裝zabbix的YUM源
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
- 安裝Zabbix
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-get
- 安裝之後進入MySQL資料庫,建立Zabbix資料庫(密碼有複雜要求)
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'zabbixpass';
flush privileges;
- 匯入Zabbix到資料庫
cd /usr/share/doc/zabbix-server-mysql-3.0.1/
zcat create.sql.gz |mysql -uroot -ppass zabbix
- 配置zabbix使用者
groupadd zabbix
useradd -g zabbix -s /bin/false zabbix
- 配置Zabbix伺服器端
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpass
- 拷貝zabbix檔案到html目錄
cd /usr/share/
cp -r zabbix /usr/local/nginx/html
chown -R zabbix:zabbix /etc/zabbix
chown -R zabbix:zabbix /usr/share/zabbix
chown -R zabbix:zabbix /usr/lib/zabbix
- Zabbix加入開機啟動並啟動
systemctl enable zabbix-server
systemctl start zabbix-server
在瀏覽器中測試Zabbix
錯誤現象
- 在網頁開啟zabbix時報錯
Warning: require_once(/etc/zabbix/web/maintenance.inc.php): failed to open stream: Permission denied in /usr/local/nginx/html/zabbix/include/classes/core/ZBase.php on line 269
Fatal error: require_once(): Failed opening required '/etc/zabbix/web/maintenance.inc.php' (include_path='.:/usr/local/php/lib/php') in /usr/local/nginx/html/zabbix/include/classes/core/ZBase.php on line 269
- 解決辦法
chmod -R 755 /etc/zabbix/web/
錯誤現象
網頁訪問失敗
解決辦法
關閉防火牆
systemctl disable firewalld
systemctl stop firewalld