环境:

Nginx+PHP:192.168.2.144

Mysql:192.168.2.151

【Nginx】

yum install -y pcre-devel openssl-deve popt-devel

tar zxvf nginx-1.11.2.tar.gz -C /usr/src/
cd /usr/src/
d /usr/src/nginx-1.11.2/
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
 make
 make install
 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
nginx -t

[root@www ~]# cat /etc/init.d/nginx
#!/bin/bash
PRIF="/usr/local/nginx/sbin/nginx"
PROG="/usr/local/nginx/logs/nginx.pid"
case $ in
start)
[[ `netstat -anput | grep nginx | wc -l` -eq ]]
$PRIF
([ `echo $?` -eq ] && echo "This Start Secusses!") ||(echo "This Nginx Running,Please reload or restart")
;;
stop)
[[ `netstat -anput | grep nginx | wc -l` > ]]
kill -s QUIT $(cat $PROG)
([ `echo $?` -eq ] && echo "Nginx stop successfully!") || (echo "Failed stop nginx!")
;;
reload)
if [[ `netstat -anput | grep nginx | wc -l` > ]];then
kill -s HUP $(cat $PROG)
else
$PRIF
kill -s HUP $(cat $PROG)
([ `echo $?` -eq ] && echo "This is Nginx reload Secussed!")|| (echo "This Nginx Reload failure!")
fi
;;
restart)
if [[ `netstat -anput | grep nginx | wc -l` == ]];then
echo "This Nginx Running..."
$PRIF
([ `echo $?` -eq ] && echo "Nginx start successfully!")
else
echo Stopping Nginx...
kill -s QUIT $(cat $PROG)
$PRIF
([ `echo $?` -eq ] && echo "This is Nginx Restart Secussed!") || (echo "This Nginx Restart Faulure!")
fi
;;
*)
echo -e "\033[41;36m Unages: $0 [start|stop|reload|restart]\033[0m"
exit
;;
esac

【Mysql】

[root@DBserver ~]# yum install -y cmake ncurses-devel

[root@DBserver ~]# tar zxvf mysql-5.5.38.tar.gz -C /usr/src/

[root@DBserver ~]# cd /usr/src/mysql-5.5.38/
[root@DBserver mysql-5.5.38]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utff8_general_ci -DWITH_EXTRA_CHARSETS=all

[root@DBserver mysql-5.5.38]# make

[root@DBserver mysql-5.5.38]# make install

[root@DBserver mysql-5.5.38]# useradd -M -s /sbin/nologin mysql
[root@DBserver mysql-5.5.38]# chown -R mysql.mysql /usr/local/mysql/
[root@DBserver mysql-5.5.38]# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cf
[root@DBserver mysql-5.5.38]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/

[root@DBserver mysql-5.5.38]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@DBserver mysql-5.5.38]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
[root@DBserver mysql-5.5.38]# source /etc/profile

[root@DBserver mysql-5.5.38]# chkconfig --add mysqld

[root@DBserver mysql-5.5.38]# systemctl  mysqld start

[php]

[root@www ~]# yum install -y libxml2-devel bzip2-devel libcurl-devel libmcrypt-devel

[root@www ~]# tar -jxvf php-5.6.8.tar.bz2 -C /usr/src/

[root@www php-5.6.8]# ./configure --prefix=/usr/local/php --with-mysql --with-pdo-mysql --with-mysqli --with-openssl --enable-fpm --enable-sockts --enable-mbstring --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr/ --with-config-file-path=/etc/ --with-config-file-scan-dir=/etc/php.d --with-curl

[root@www php-5.6.8]# make

[root@www php-5.6.8]# make install

[root@www php-5.6.8]# cp php.ini-production /etc/php.ini
[root@www php-5.6.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@www php-5.6.8]# chmod +x /etc/init.d/php-fpm
[root@www php-5.6.8]# chkconfig --add php-fpm
[root@www php-5.6.8]# chkconfig php-fpm on
[root@www php-5.6.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@www etc]# sed -i '235s#pm.max_children = 5#pm.max_children = 150#;s#pm.start_servers = 2#pm.start_servers = 8#;s#pm.min_spare_servers = 1#pm.min_spare_servers = 8#;s#pm.max_spare_servers = 3#pm.max_spare_servers = 10#g' /usr/local/php/etc/php-fpm.conf

配置php-fpm的 Pid文件路径

[root@www etc]# sed -i 's#;pid = run/php-fpm.pid#pid = /usr/local/php/var/run/php-fpm.pid#g' /usr/local/php/etc/php-fpm.conf

在php-fpm配置文件配置用户名为nginx,用nginx用户来启用php-fpm程序,而监听地址为本地IP用来调用

[root@www etc]# sed -i 's#user = nobody#user = nginx#;s#group = nobody#group = nginx#;s#listen = 127.0.0.1:9000#listen = 192.168.2.144:9000#g' /usr/local/php/etc/php-fpm.conf

【整合Nginx与PHP】

worker_processes  ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
server {
listen ;
server_name localhost;
location / {
root /www/webapp/;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /www/webapp;
fastcgi_pass 192.168.2.144:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}
}

[root@www etc]# mkdir /www/webapp -p

[root@www etc]# useradd -M -s /sbin/nologin  nginx

[root@www etc]# systemctl start php-fpm

netstat -anput | grep php-fpm
tcp 0 0 192.168.2.144:9000 0.0.0.0:* LISTEN 126357/php-fpm: mas

[root@www ~]# cat /www/webapp/index.php
<?php
phpinfo();
?>

Ps:如果PHP单独在一个服务独立运行的话。可以用nfs共享,指定php-fpm的本地IP进行挂载

1 mkdir /www
2 chown -R nginx:nginx /www
3 vim /etc/exports
4 ---------------------------------------------
5 /www 192.168.2.0/24(rw,no_root_squash)
6 ---------------------------------------------
7 service nfs start 8 mount -t nfs 192.168.2.144:/www /www
【Discuz论坛】

[root@www ~]# unzip Discuz_X3.1_SC_UTF8.zip -d /www/webapp

[root@www ~]# cd /www/webapp
[root@www webapp]# mv upload/* .

[root@www webapp]# chmod 777 -R data/ config/ uc_client/ uc_server/

【数据库授权】

[root@DBserver mysql-5.5.38]# mysql -u root -p123.com

mysql> create database Discuzdb default charset=utf8;

mysql> grant all on Discuzdb.* to root@'mysql> grant all on Discuzdb.* to root@'192.168.2.144' identified by '123456';

mysql> flush privileges;

【Mysql数据库错误问题汇总】

错误1:预编译报错:

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed

错误2:解决方法:

make clean    #清楚上次编译生成的object文件以及二进制文件
rm -rf CMakeCache.txt  
rm -rf /etc/my.cnf

make[2]: *** [sql/CMakeFiles/sql.dir/mysqld.cc.o] 错误 1
make[1]: *** [sql/CMakeFiles/sql.dir/all] 错误 2

LNMP分离部署的更多相关文章

  1. LNMP下动静分离部署phpmyadmin软件包

    LNMP环境肯定是先要配置好的.可以参考我之前的博客.那我们直接进行配置,我这里使用了三台机器进行动静分离部署,第一台负责nginx反向代理,第二台负责php-fpm应用程序以及mariadb的服务器 ...

  2. 【转】Nginx+php-fpm+MySQL分离部署详解

    转:http://www.linuxidc.com/Linux/2015-07/120580.htm Nginx+php-fpm+MySQL分离部署详解 [日期:2015-07-26] 来源:Linu ...

  3. LNMP分离式部署

    #### LNMP组合工作流程 在LNMP组合工作时,首先是用户通过浏览器输入域名请求Nginx Web服务,如果请求是静态资源,则由Nginx解析返回给用户:如果是动态请求(.php结尾),那么Ng ...

  4. LNMP分离式部署实例[转]

    很多人在练习部署LNMP环境的时候,大都数是部署在同一个虚拟机上面的.但是实际工作中,我们一般都是分离部署的. 今天我就用3台虚拟机,部署下LNMP环境.以供参考! 网络拓扑图: 首先准备3台虚拟机: ...

  5. linux运维、架构之路-Lnmp架构部署

    一.Lnmp架构原理 二. Lnmp架构软件安装 1.Nginx安装脚本 #!/bin/bash useradd -s /sbin/nologin -M www mkdir -p /server/to ...

  6. LNMP架构部署

    第1章 部署LNMP架构步骤 1.1 ①部署Linux系统(OK) 基本优化完成(ip地址设置 yum源更新 字符集设置) 安全优化完成(iptables关闭 selinux关闭 /tmp/ 1777 ...

  7. 001.Amoeba读写分离部署

    一 Amoeba简介 Amoeba(变形虫)项目,该开源框架于2008年 开始发布一款 Amoeba forMysql软件.这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQ ...

  8. Puppet基于Master/Agent模式实现LNMP平台部署

    前言 随着IT行业的迅猛发展,传统的运维方式靠大量人力比较吃力,运维人员面对日益增长的服务器和运维工作,不得不把很多重复的.繁琐的工作利用自动化处理.前期我们介绍了运维自动化工具ansible的简单应 ...

  9. windows下Redis 主从读写分离部署

    原文:windows下Redis 主从读写分离部署 1.可直接下载window下的运行文件(下面这个链接) 也可以浏览github 查看相应的版本说明文档 https://github.com/Ser ...

随机推荐

  1. 获取日期Date

    获取特定时间戳: new Date("2018-06-12").getTime()   processDate(){ return { disabledDate(time){ re ...

  2. 010_mac常用docker维护命令

    一. ➜ ~ docker search rabbitmq #搜索 NAME DESCRIPTION STARS OFFICIAL AUTOMATED rabbitmq RabbitMQ is an ...

  3. python bytes/str

    http://eli.thegreenplace.net/2012/01/30/the-bytesstr-dichotomy-in-python-3/

  4. bootstrap排列顺序

    写在 typora 的笔记 复制过来排版很丑,所以截图算了..

  5. 5)协程二(yeild from)

     一:yield from说明 python从3.3版本开始使用yield from 替代yield  yield from 结构会在内部自动捕获 StopIteration 异常. 这种处理方式与 ...

  6. PHP中使用Redis长连接笔记

    pconnect函数声明 其中time_out表示客户端闲置多少秒后,就断开连接.函数连接成功返回true,失败返回false: pconnect(host, port, time_out, pers ...

  7. 锤子科技"临死前"被"接盘" ,内部人士爆料已改签今日头条母公司

    就在昨天,据据锤子科技内部人士透露,部分锤子科技员工在昨天已经接到了相关的临时通知,要求改签劳动合同至今日头条的母公司——字节跳动.至于这是锤子科技真正再度复活还是借尸还魂都不重要,重要的是,作为忠实 ...

  8. sticky footer 模板

    http://www.w3cplus.com/blog/tags/136.html http://www.w3cplus.com/css/css-sticky-foot-at-bottom-of-th ...

  9. linux cp命令使用

    功能: 复制文件或目录说明: cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中.若同时指定多个文件或目录, ...

  10. 【mysql】删除字段的最后一个字符

    场景:在存入16进制id时,由于转换失误,得到的结果是0x1001L的格式,我希望转换为0x1001,去掉最后的L 指令: update tb_test set hexid=left(hexid, l ...