1. 程式人生 > >基於rhel7.2的Zabbix平臺搭建和部署(一)

基於rhel7.2的Zabbix平臺搭建和部署(一)

linux 監控軟件 zabbix nginx mysql php lnmp

基於rhel7.2的zabbix平臺搭建和部署(一)


一、實驗環境:

(1)虛擬機:rhel7.2 x86_64

(2)數據庫:mysql5.7.13

(3)nginx1.10.2

(4)PHP5.6.27

(5)zabbix

二、安裝編譯工具及庫文件

[[email protected] ~]# yum-y install make apr* autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel

三、安裝mysql5.7.13

(1)安裝具體步驟,請參考我的博文:http://wutengfei.blog.51cto.com/10942117/1931482

(2)mysql安裝完畢後,看一下mysql的服務

[[email protected] ~]# ps -ef |grep mysql

技術分享

[[email protected]

/* */ ~]# netstat -lnp |grep mysql

技術分享

(3)防火墻開啟3306端口例外

[[email protected] ~]# firewall-cmd --permanent --add-port=3306/tcp

success

[[email protected] ~]# firewall-cmd --reload

success

技術分享

(4)數據庫密碼:123456

四、安裝nginx1.10.2

(1)解壓zlib和pcre

[[email protected] src]# tar -zxvf zlib-1.2.8.tar.gz

[[email protected] src]# tar -zxvf pcre-8.39.tar.gz

說明:不需要編譯,只需要解壓就行。

(2)創建組賬戶和用戶賬戶

[[email protected] ~]# groupadd www

[[email protected] ~]# useradd -g www -s /sbin/nologin www

[[email protected] ~]# grep www /etc/passwd

www:x:1000:1000::/home/www:/sbin/nologin

(3)下載安裝nginx

[[email protected] src]# tar -zxvf nginx-1.10.3.tar.gz

[[email protected] src]# cd nginx-1.10.3

[[email protected] nginx-1.10.3]# ./configure --prefix=/usr/local/nginx1.10 --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/src/pcre-8.39 --with-zlib=/usr/src/zlib-1.2.8 --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www && make && make install

(4)做軟鏈接

[[email protected] nginx-1.10.3]# ln -s /usr/local/nginx1.10/sbin/nginx /usr/local/sbin/

(5)nginx語法檢查

[[email protected] nginx-1.10.3]# nginx -t

技術分享

(6)啟動nginx並查看服務

[[email protected] nginx-1.10.3]# netstat -lnp |grep nginx

技術分享

(7)防火墻開啟80端口例外

[[email protected] ~]# firewall-cmd --permanent --add-port=80/tcp

success

[[email protected] ~]# firewall-cmd --reload

success

技術分享

(8)在一臺客戶端訪問測試

技術分享

五、安裝php5.6.27

(1)安裝libmcrypt

[[email protected] src]# tar -zxvf libmcrypt-2.5.7.tar.gz

[[email protected] src]# cd libmcrypt-2.5.7

[[email protected] libmcrypt-2.5.7]# ./configure && make && make install

(2)做軟鏈接

[[email protected] ~]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20.3.0 /usr/local/mysql/lib/libmysqlclient_r.so

(3)安裝php

[[email protected] src]# tar -zxvf php-5.6.27.tar.gz

[[email protected] src]# cd php-5.6.27

[[email protected] php-5.6.27]# ./configure --prefix=/usr/local/php5.6 --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/usr/local/mysql/mysql.sock --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-zlib --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt--with-curl && make && make install

(4)拷貝樣例配置文件並修改

[root@ php-5.6.27]# cp php.ini-production /etc/php.ini

[root@ php-5.6.27]# vim /etc/php.ini

在/etc/php.ini配置文件中修改如下內容:

技術分享 //設置時區


技術分享//禁止顯示php版本的信息


技術分享//支持php短標簽


技術分享//上傳文件大小

技術分享//php腳本最大執行時間

技術分享

//以秒為單位對通過POST、GET以及PUT方式接收數據時間進行限制


技術分享

技術分享

(5)創建php-fpm服務啟動腳本

[root@ php-5.6.27]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@ php-5.6.27]# chmod +x /etc/init.d/php-fpm

[root@ php-5.6.27]# chkconfig --add php-fpm

[root@ php-5.6.27]# chkconfig php-fpm on

[root@ php-5.6.27]# chkconfig --list |grep php


Note: This output shows SysV services only and does not include native

systemd services. SysV configuration data might be overridden by native

systemd configuration.


If you want to list systemd services use ‘systemctl list-unit-files‘.

To see services enabled on particular target use

‘systemctl list-dependencies [target]‘.

php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off

技術分享

(6)提供php-fpm配置文件並編輯

[root@ php-5.6.27]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf

[root@ php-5.6.27]# vim /usr/local/php5.6/etc/php-fpm.conf

在配置文件中修改如下內容:

技術分享

技術分享

技術分享

技術分享

技術分享

技術分享

技術分享

(7)啟動php-fpm服務並查看

[root@ ~]# service php-fpm start

Starting php-fpm done

[root@ ~]# netstat -lnp |grep php-fpm

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3203/php-fpm: maste

技術分享

六、配置nginx支持php

[root@ ~]# vim /usr/local/nginx1.10/conf/nginx.conf

user www www;

worker_processes 4;


#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;


#pid logs/nginx.pid;



events {

worker_connections 1024;

}



http {

include mime.types;

default_type application/octet-stream;


#log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘

# ‘$status $body_bytes_sent "$http_referer" ‘

# ‘"$http_user_agent" "$http_x_forwarded_for"‘;


#access_log logs/access.log main;


sendfile on;

#tcp_nopush on;


#keepalive_timeout 0;

keepalive_timeout 65;


#gzip on;


server {

listen 80;

server_name localhost;


charset utf-8;


#access_log logs/host.access.log main;


location / {

root html;

index index.php index.html index.htm;

}


#error_page 404 /404.html;


# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

location /ststus {

stub_status on;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

include fastcgi.conf;

}


# deny access to .htaccess files, if Apache‘s document root

# concurs with nginx‘s one

#

#location ~ /\.ht {

# deny all;

#}

}



# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;


# location / {

# root html;

# index index.html index.htm;

# }

#}



# HTTPS server

#

#server {

# listen 443 ssl;

# server_name localhost;


# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;


# ssl_session_cache shared:SSL:1m;

# ssl_session_timeout 5m;


# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;


# location / {

# root html;

# index index.html index.htm;

# }

#}

}

[root@ ~]# nginx -t

nginx: the configuration file /usr/local/nginx1.10/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx1.10/conf/nginx.conf test is successful

技術分享

[root@ ~]# nginx

[root@ ~]# netstat -lnp |grep nginx

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3302/nginx: master

技術分享

七、測試LNMP

(1)進入nginx默認的網頁根目錄,創建test.php的測試頁:

[root@ ~]# vim /usr/local/nginx1.10/html/test1.php

<?php

echo "PHP解析正常";

?>

[root@ ~]# vim /usr/local/nginx1.10/html/test2.php

<?php

$link=mysql_connect(‘localhost‘,‘root‘,‘123456‘);

if($link) echo "ok";

mysql_close();

?>

(2)在客戶端上測試

有兩種方法:

方法一:使用curl命令

[root@ ~]# curl localhost/test1.php

PHP解析正常

[root@ ~]# curl localhost/test2.php

ok

方法二:使用瀏覽器

技術分享

技術分享

以上就是LNMP部署過程!


本文出自 “聖騎士控魔之手” 博客,請務必保留此出處http://wutengfei.blog.51cto.com/10942117/1931869

基於rhel7.2的Zabbix平臺搭建和部署(一)