LNMP部署

Posted lyqlyqlyq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LNMP部署相关的知识,希望对你有一定的参考价值。

部署企业LNMP架构

源码包:nginx-* ; mysql-* ; php-* ; boost-* ; zend-loader-php5.6-linux-* ;
yum软件: pcre-devel zlib-devel openssl-devel gcc gcc-c++ net--tools
ncurses-devel cmake
gd libxml2-devel libjpeg-devel libpng-devel

 

关闭防火墙:
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# iptables -F

安装nginx:
[root@localhost ~]# yum -y install vim gcc gcc-c++ pcre-devel zlib-devel openssl-devel psmisc
[root@localhost ~]# tar xf nginx-1.14.2.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.14.2/
[root@localhost nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module && make && make install
[root@localhost nginx-1.14.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
[root@localhost nginx-1.14.2]# cd
[root@localhost ~]# nginx -t
[root@localhost ~]# netstat -lnpt | grep nginx
[root@localhost ~]# nginx
[root@localhost ~]# netstat -lnpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23383/nginx: master

安装mysql数据库:
[root@localhost ~]# yum -y insatll ncurses-devel cmake
[root@localhost ~]# mkdir /usr/local/boost
[root@localhost ~]# tar xf boost_1_59_0.tar.gz -C /usr/local/boost
[root@localhost ~]# useradd -M -s /sbin/nologin mysql
[root@localhost ~]# tar xf mysql-5.7.24.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/mysql-5.7.24/
[root@localhost mysql-5.7.24]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc -DWITH_BOOST=/usr/local/boost && make && make install
[root@localhost mysql-5.7.24]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R mysql:mysql ./
[root@localhost mysql]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
[root@localhost mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2019-09-13T03 ...... root@localhost: OyhkXihef6#k ----> 记住生成的密码 OyhkXihef6#k
[root@localhost mysql-5.7.24]# cd /usr/src/mysql-5.7.24/
[root@localhost mysql-5.7.24]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@localhost mysql-5.7.24]# source /etc/profile
[root@localhost mysql-5.7.24]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.7.24]# chmod +x /etc/init.d/mysqld
[root@localhost mysql-5.7.24]# /etc/init.d/mysqld start
Starting MySQL.Logging to ‘/usr/local/mysql/data/mysql.log‘.
SUCCESS!
[root@localhost ~]# mysqladmin -uroot -p‘OyhkXihef6#k‘ password ‘111111‘
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

安装PHP:
[root@localhost ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
[root@localhost ~]# cd /usr/src/php-5.6.39/
[root@localhost php-5.6.39]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install
[root@localhost php-5.6.39]# cp php.ini-production /usr/local/php5/php.ini
[root@localhost php-5.6.39]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@localhost php-5.6.39]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
[root@nginx~]# tar xf zend-loader-php5.6-linux-x86_64_update1.tar.gz -C /usr/src/
[root@nginx~]# cd /usr/src/zend-loader-php5.6-linux-x86_64/
[root@nginx zend-loader-php5.6-linux-x86_64]# cp ZendGuardLoader.so /usr/local/php5/lib/php/
[root@nginx zend-loader-php5.6-linux-x86_64]#vim /usr/local/php5/php.ini
在末行追加:
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
[root@localhost php5]# cd /usr/local/php5/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# useradd -M -s /sbin/nologin php
[root@localhost etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid
149 user = php
150 group = php
246pm.start_servers = 20
251pm.min_spare_servers = 5
256pm.max_spare_servers = 35
241pm.max_children = 5
[root@localhost ~]# /usr/local/sbin/php-fpm
[root@nginxetc]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: 2345 99 20
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 (start|stop|restart|reload)"
exit 1
esac
exit 0
[root@nginxetc]# vim /usr/local/nginx/conf/nginx.conf
server {
…… //省略部分信息
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ { //访问php页面的配置段
root html; //PHP网页文档根目录
fastcgi_pass 127.0.0.1:9000; //php-fpm的监听地址
fastcgi_index index.php; //PHP首页文件
include fastcgi.conf; //包括fastcgi.conf样本配置
}
}
[root@localhost ~]# killall -9 nginx
[root@localhost ~]# nginx

在浏览器输入192.168.200.111/php.php即可查看

以上是关于LNMP部署的主要内容,如果未能解决你的问题,请参考以下文章

LNMP源码编译安装及一键部署LNMP架构

ansible--使用ansible进行lnmp环境部署

20200720记录:部署LNMP环境,构建LNMP平台,地址重写

lnmp部署

Docker 运维 - 部署LNMP

LNMP架构部署