lnmp的mysql分离_LNMP分离部署

环境:

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 $1 instart)

[[ `netstat-anput | grep nginx | wc -l` -eq 0]]

$PRIF

([ `echo $?` -eq 0 ] && echo "This Start Secusses!") ||(echo "This Nginx Running,Please reload or restart")

;;

stop)

[[ `netstat-anput | grep nginx | wc -l` > 0]]

kill-s QUIT $(cat $PROG)

([ `echo $?` -eq 0 ] && echo "Nginx stop successfully!") || (echo "Failed stop nginx!")

;;

reload)if [[ `netstat -anput | grep nginx | wc -l` > 0]];then

kill-s HUP $(cat $PROG)else$PRIF

kill-s HUP $(cat $PROG)

([ `echo $?` -eq 0 ] && echo "This is Nginx reload Secussed!")|| (echo "This Nginx Reload failure!")

fi

;;

restart)if [[ `netstat -anput | grep nginx | wc -l` == 0]];then

echo"This Nginx Running..."$PRIF

([ `echo $?` -eq 0 ] && echo "Nginx start successfully!")elseecho Stopping Nginx...

kill-s QUIT $(cat $PROG)

$PRIF

([ `echo $?` -eq 0 ] && 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"exit1;;

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 1;

events {

worker_connections1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout65;

server {

listen80;

server_name localhost;

location/{

root/www/webapp/;

index index.php index.html index.htm;

}

location~\.php$ {

root/www/webapp;

fastcgi_pass192.168.2.144:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

error_page500 502 503 504 /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

phpinfo();

?>

a6839787a5ea751fbd33d76a097d4158.png

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;

a07a8c110db1d97138bfe0d616ef9e2f.png

cb06f1db8f8ac29e9220afe80510538a.png

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

错误1:预编译报错:

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

CMake Error: Internal CMake error, TryCompile configure of cmake failed

43afdb66b51a95825f10d4e4f58db5da.png

错误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

72bd9401738ca968db7e2168b2958cd6.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值