rpm包方式实现LNMP
rpm包 lnmp
nginx-主机 : 172.16.40.99
php-fpm-主机 : 172.16.40.11
mariadb-主机 : 172.16.40.88
一.安装,配置nginx-主机: 172.16.40.99
安装:
# yum install nginx
# nginx 启动
# nginx -s stop 停止
# nginx -t 测试配置文件是否正确
# nginx -s reload 重载配置文件
配置两个虚拟主机:
# 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结尾的文件传给php-fpm来处理,此处地址是php服务器地址)
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} (目录下添加测试页,测试nginx是否正常运行虚拟主机)
index.php (用于转向php-fpm主机)
###--带缓存项的虚拟主机配置文件--###
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的虚拟主机配置文件80端口变为443--###
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主机: 172.16.40.11
安装:
# rpm -q php ###确保之前没有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 (设置php服务器监听地址即监听本地能够与外部通信的地址)
listen.allowed_clients = 172.16.40.99 (监听具有httpd服务的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();
?>
分别测试 www1.ryanpeng.com,www2.ryanpeng.com 看nginx与php-fpm是否连接成功
三.安装配置mariadb主机: 172.16.40.88
安装启动:
# yum install mariadb-server
# systemctl start mariadb.service
创建数据库及授权用户:
MariaDB [(none)]> grant all on db.* to 'dbuser'@'172.16.%.%' identified by "dbpasswd";
MariaDB [(none)]> CREATE DATABASE db;
在php服务器(172.16.40.11)上建立php测试页,测试php主机是否可以正常连接数据库主机
# vim /data/vhost/www1/index.php
$conn = mysql_connect('172.16.40.88','dbuser','dbpasswd');
if ($conn)
echo "ok";
else
echo "NO";
phpinfo();
?>
测试连接是否成功,若显示ok则证明连接成功;
四.分别在虚拟主机1,2上部署WordPress和phpMyadmin
在php-fpm主机(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 分别移动到/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数据库用户名 */
define('DB_USER', 'wpuser');
/** MySQL数据库密码 */
define('DB_PASSWORD', 'wppasswd');
/** MySQL主机 */
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 (创建软链接,方便回滚)
# 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'; (数据库服务器地址)
$cfg['Servers'][$i]['user'] = 'dbuser';
$cfg['Servers'][$i]['password'] = 'dbpass';
# scp -r phpMyAdmin/ 172.16.40.99:/data/vhost/www2/
分别登录两个虚拟机,测试WordPress和phpMyadmin
五.在php-fpm(172.16.40.11)主机上安装xcache:
安装php-xache
# yum -y install php-xcache
# systemctl restart php-fpm.service
配置文件做简单的配置
# vim /etc/php.d/xcache.ini
xcache.size = 300M
在装载xcache前后进行压力测试
#ab -n 10000 -c 1000 http://www1.ryanpeng.com/wordpress | http://www2.ryanpeng.com/phpmyadmin
- 上一篇
MySQL连接超时相关的两个参数interactive_timeout和wait_timeout的区别及解释
本篇内容主要讲解"MySQL连接超时相关的两个参数interactive_timeout和wait_timeout的区别及解释",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让
- 下一篇
linux 在~/.bash_profile配置完oracle每次都要source 才能使用的问题
在root模式下修改.bash_profile或者oracle下修改.bashrc#cd ~#vi .bashrc增加以下环境配置内容:export ORACLE_BASE=/opt/oracle/a