linux系统架构-----LNMP

LNMP概述

  • LNMP为Linux平台,Nginx web服务软件,mysql数据库软件,PHP编辑语言
  • LNMP系统架构相对于LAMP的优点是LNMP比较节省内存,主要支持静态请求,但在访问量大的时候php-fpm容易僵死,容易发生502 bad gateway错误,LAMP适合处理动态请求

一安装nginx

//将安装包挂载mnt目录下
mount.cifs //192.168.10.138/LNMP-C7 /mnt

将安装包解压到opt目录下 安装环境包

tar zxvf nginx-1.12.2.tar.gz -C /opt
yum install gcc gcc-c++ pcre* zlib-devel make -y

创建nginx用户

useradd -M -s /sbin/nologin nginx

安装nginx

cd /opt/nginx-1.12.2/ 
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module

编译

make && make install

优化nginx

//为nginx创建软连接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
//创建service工具
vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: - 99 20
#description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
  start)
     $PROG
     ;;
  stop)
     kill -s QUIT $(cat $PIDF)
     ;;
  restart)
     $0 stop
     $0 start
     ;;
   reload)
      kill -s HUP $(cat $PIDF)
     ;;
   *)
     echo "Usage: $0 {start|stop|restart|reload}"
     exit 1
esac
exit 0
//添加权限
chmod +x /etc/init.d/nginx
//添加为系统服务
chkconfig --add /etc/init.d/nginx 

关闭防火墙 增强性功能 开启nginx服务

systemctl stop firewalld.service
setenforce 0
service nginx start

第二步安装MYSQL

解压安装包

tar -xzvf mysql-boost-5.7.20.tar.gz -C /opt

安装环境包

yum install ncurses ncurses-devel bison cmake autoconf -y

创建用户

useradd -s /sbin/nologin mysql

安装配置环境

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

编译

make && make install

调整MySQL数组

chown -R mysql:mysql /usr/local/mysql

调整配置文件参数

vim /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

设置环境变量

echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
//设置全局变量
echo 'export PATH' >> /etc/profile
//启动文件
source /etc/profile

初始数据库

cd /usr/local/mysql
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

优化mysql服务控制,使用systemctl工具控制mysql服务

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /lib/systemd/system

开启mysql服务

systemctl start mysqld.service

设置数据库密码

mysqladmin -u root -p password

安装php

将安装包解压到opt

tar xjvf php-7.1.10.tar.bz2 -C /opt

安装环境包

yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

配置服务,安装且编译

./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

编译

make && make install

拷贝核心配置文件

cp php.ini-development /usr/local/php/lib/php.ini

编辑核心配置文件

vim /usr/local/php/lib/php.ini
#指定路经
mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai

验证模块

/usr/local/php/bin/php -m

配置FPM模块

cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
#去掉注释
pid = run/php-fpm.pid

启动php

/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini

建立软链接
vim /usr/local/nginx/conf/nginx.conf

ln -s /usr/local/php/bin/* /usr/local/bin/

使得Nginx支持PHP

location ~ \.php$ {
#指定站点目录
            root           html;
#FPM模块的位置
            fastcgi_pass   127.0.0.1:9000;
#支持php的网页格式
            fastcgi_index  index.php;
#加载脚本类型和位置
            fastcgi_param  SCRIPT_FILENAME   /usr/local/nginx/html$fastcgi_script_name;
#把nginx中的变量转化为php中的变量
            include        fastcgi_params;
        }

创建PHP首页,且重启nginx服务

vim /usr/local/nginx/html/index.php
<?
phpphpinfo();
?>
systemctl restart nginx

你可能感兴趣的:(linux系统架构-----LNMP)