rpm包 lnmp
創(chuàng)新互聯(lián)公司-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比東港網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式東港網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋東港地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴(lài)。
nginx-主機(jī) : 172.16.40.99
php-fpm-主機(jī) : 172.16.40.11
mariadb-主機(jī) : 172.16.40.88
一.安裝,配置nginx-主機(jī): 172.16.40.99
安裝:
# yum install nginx
# nginx 啟動(dòng)
# nginx -s stop 停止
# nginx -t 測(cè)試配置文件是否正確
# nginx -s reload 重載配置文件
配置兩個(gè)虛擬主機(jī):
# vim /etc/nginx/conf.d/vhosts1.conf
server {
listen 80;
server_name www1.ryanpeng.com;
root /data/vhost/www1;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 172.16.40.11:9000;
fastcgi_param SCRIPT_FILENAME /data/vhost/www1$fastcgi_script_name;
(表示以.php結(jié)尾的文件傳給php-fpm來(lái)處理,此處地址是php服務(wù)器地址)
include fastcgi_params;
}
}
# vim /etc/nginx/conf.d/vhosts2.conf
server {
listen 80;
server_name www2.ryanpeng.com;
root /data/vhost/www2;
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 172.16.40.11:9000;
fastcgi_param SCRIPT_FILENAME /data/vhost/www2$fastcgi_script_name;
include fastcgi_params;
}
}
# mkdir -pv /data/vhost/www{1,2}
www{1,2} (目錄下添加測(cè)試頁(yè),測(cè)試nginx是否正常運(yùn)行虛擬主機(jī))
index.php (用于轉(zhuǎn)向php-fpm主機(jī))
###--帶緩存項(xiàng)的虛擬主機(jī)配置文件--###
server {
listen 80;
root /data/vhost/www1;
location ~ \.php$ {
fastcgi_cache_valid 200 1m;
fastcgi_cache one;
fastcgi_cache_key $uri;
fastcgi_cache_min_uses 2;
fastcgi_cache_methods GET;
fastcgi_index index.php;
fastcgi_pass 172.16.40.11:9000;
fastcgi_param SCRIPT_FILENAME /data/vhost/www1$fastcgi_script_name;
include fastcgi_params;
}
location / {
rewrite /(.*)$ https://www1.ryanpeng.com/$1;
}
}
###--https的虛擬主機(jī)配置文件80端口變?yōu)?43--###
server {
listen 443 ssl;
root /data/data/www1;
ssl on;
ssl_certificate www1.cacert;
ssl_certificate_key www1.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 1m;
ssl_ciphers HIGH:!aNULL:!MD5;
location ~ \.php$ {
fastcgi_cache_valid 200 1m;
fastcgi_cache one;
fastcgi_cache_key $uri;
fastcgi_cache_min_uses 2;
fastcgi_cache_methods GET;
fastcgi_index index.php;
fastcgi_pass 172.16.40.11:9000;
fastcgi_param SCRIPT_FILENAME /data/data/www1$fastcgi_script_name;
include fastcgi_params;
}
}
二.安裝配置php-fpm主機(jī): 172.16.40.11
安裝:
# rpm -q php ###確保之前沒(méi)有php程序
# yum install php-fpm php-MySQL php-mbstring
# mkdir /var/lib/php/session
# useradd -r nginx
# chown nginx.nginx /var/lib/php/session/
配置:
# vim /etc/php-fpm.d/www.conf
listen = 172.16.40.11:9000 (設(shè)置php服務(wù)器監(jiān)聽(tīng)地址即監(jiān)聽(tīng)本地能夠與外部通信的地址)
listen.allowed_clients = 172.16.40.99(監(jiān)聽(tīng)具有httpd服務(wù)的IP地址)
# mkdir -pv /data/vhost/www{1,2}
# vim /data/vhost/www1/index.php
This is vhost1
phpinfo();
?>
# vim /data/vhost/www2/index.php
This is vhost2
phpinfo();
?>
分別測(cè)試 www1.ryanpeng.com,www2.ryanpeng.com 看nginx與php-fpm是否連接成功
三.安裝配置mariadb主機(jī): 172.16.40.88
安裝啟動(dòng):
# yum install mariadb-server
# systemctl start mariadb.service
創(chuàng)建數(shù)據(jù)庫(kù)及授權(quán)用戶(hù):
MariaDB [(none)]> grant all on db.* to 'dbuser'@'172.16.%.%' identified by "dbpasswd";
MariaDB [(none)]> CREATE DATABASE db;
在php服務(wù)器(172.16.40.11)上建立php測(cè)試頁(yè),測(cè)試php主機(jī)是否可以正常連接數(shù)據(jù)庫(kù)主機(jī)
# vim /data/vhost/www1/index.php
$conn = mysql_connect('172.16.40.88','dbuser','dbpasswd');
if ($conn)
echo "ok";
else
echo "NO";
phpinfo();
?>
測(cè)試連接是否成功,若顯示ok則證明連接成功;
四.分別在虛擬主機(jī)1,2上部署WordPress和phpMyadmin
在php-fpm主機(jī)(172.16.40.11)上,下載 phpMyAdmin-4.0.5-all-languages.zip 和 wordpress-4.3.1-zh_CN.zip ;
將解壓后的文件 wordpress phpMyAdmin-4.0.5-all-languages 分別移動(dòng)到/data/vhost/下的www1和www2 目錄中;
部署WordPress
# cd /data/vhost/www1/wordpress/
# cp wp-config-sample.php wp-config.php
# vim wp-config.php
define('DB_NAME', 'wpdb');
/** MySQL數(shù)據(jù)庫(kù)用戶(hù)名 */
define('DB_USER', 'wpuser');
/** MySQL數(shù)據(jù)庫(kù)密碼 */
define('DB_PASSWORD', 'wppasswd');
/** MySQL主機(jī) */
define('DB_HOST', '172.16.40.88');
# scp -r wordpress/ 172.16.40.99:/data/vhost/www1/
部署phpMyadmin
# cd /data/vhost/www2
# ln -sv phpMyAdmin-4.0.5-all-languages phpMyAdmin (創(chuàng)建軟鏈接,方便回滾)
# cd phpMyAdmin
# cp config.sample.inc.php config.sample.php
# vim config.sample.php
$cfg['blowfish_secret'] = 'jACG7X2usbnwzg=='; (使用openssl rand -base64 10生成)
$cfg['Servers'][$i]['host'] = '172.16.40.88'; (數(shù)據(jù)庫(kù)服務(wù)器地址)
$cfg['Servers'][$i]['user'] = 'dbuser';
$cfg['Servers'][$i]['password'] = 'dbpass';
# scp -r phpMyAdmin/ 172.16.40.99:/data/vhost/www2/
分別登錄兩個(gè)虛擬機(jī),測(cè)試WordPress和phpMyadmin
五.在php-fpm(172.16.40.11)主機(jī)上安裝xcache:
安裝php-xache
# yum -y install php-xcache
# systemctl restart php-fpm.service
配置文件做簡(jiǎn)單的配置
# vim /etc/php.d/xcache.ini
xcache.size = 300M
在裝載xcache前后進(jìn)行壓力測(cè)試
#ab -n 10000 -c 1000 http://www1.ryanpeng.com/wordpress | http://www2.ryanpeng.com/phpmyadmin