LNMP架构搭建

LNMP架构

版本

mysql-5.7.31-linux-glibc2.12-x86_64.tar

nginx-1.14.2.tar

php-7.2.12.tar

新建服务器

我们一般对外提供服务的服务器地址通常采用公网ip

克隆模板机,生成web01服务器

更改主机名字web01

hostnamectl set-hostname web01
su

改IP地址

vim /etc/sysconfig/network-scripts/ifcfg-ens33

绑定主机名称重启网络

vim /etc/hosts
#在文件里追加一行
192.168.17.102 web01

关闭防火墙,selinux,networkmanager

# systemctl stop firewalld
# systemctl disable firewalld
# setenforce 0
# sed -i '/SELINUX=enforcing/cSELINUX=disabled' /etc/selinux/config

配置yum源

时间同步

ntpdate 182.92.12.11

lnmp = linux nginx(port80) mysql(3306) php(独立软件 port80)

mysql安装

数据库安装位置:/usr/local/mysql

数据库的数据目录:/usr/local/mysql/data

套接字文件:/tmp/mysql.sock

端口设置:3306

如果套接字没在/tmp目录下:

mysql客户端无法直接连接到mysqld服务器端,必须手工指定-S选项,指定套接字的位置,或者可以在my.cnf文件中加一个选项

vim /etc/my.cnf
[mysqld]

[mysql]
socket=/usr/local/mysql/mysql.sock
# vim mysql.sh
#!/bin/bash
tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
useradd -r -s /sbin/nologin mysql
rm -rf /etc/my.cnf
cd /usr/local/mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
rm -rf /etc/my.cnf
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql
#根据需求
bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
#添加环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
cp support-files/mysql.server /etc/init.d/mysqld
service mysqld start

# source mysql.sh
mysql -p
mysql> set password='123';
mysql> flush privileges;

mysql_secure_installation

#配置mysqld服务器随开机自动启动
chkconfig --list
chkconfig -add mysqld
chkconfig mysqld on

nginx安装

安装方式:

yum:

需要epel源或者nginx官方源

源码:

配置,编译,安装

http://nginx.org/选择community stable version

先安装低版本 以后平滑升级

上传软件包

联网安装依赖库

yum -y install pcre-devel zlib-devel openssl-devel

解压软件包

cd /root/
tar xvf nginx-1.14.2.tar.gz

新建用户,配置要用

useradd -r -s /sbin/nologin www

配置

cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module 

编译,安装

make && make install

脚本

vim nginx.shell
#!/bin/bash
#安装依赖
yum -y install pcre-devel zlib-devel openssl-devel
#编译安装
cd /root/soft
tar xvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
make && make install

sh nginx.sh

配置nginx环境变量

vim /etc/profile
在文件末尾添加如下内容:
export NGINX_HOME=/usr/local/nginx
 
export PATH=$PATH:$NGINX_HOME/sbin

source /etc/profile

启动

nginx

关闭

nginx -s stop

重启

nginx -s restart

热重载

nginx -s reload

服务配置

先关闭nginx

编写脚本,将nginx加入系统服务

vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx service
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

启动

systemctl start/stop/reload/enable/disable nginx

php安装

安装依赖

yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel opensll-devel

解压

配置编译安装

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

make && make install

复制配置文件

shell > cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
shell > cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
shell > cp /root/php-7.2.12/php.ini-development /usr/local/php/etc/php.ini

添加启动服务

shell > cp /root/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
shell > chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
shell > service php-fpm start
ps -ef |grep php-fpm
netstat -tnlp |grep 9000

添加环境变量

shell > echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
shell > source /etc/profile

关联配置

让nginx可以转发php代码php-fpm

在修改配置文件前备份

cd /usr/local/nginx
cp conf/nginx.conf conf/nginx.conf.bak

使用grep过滤井号空行

grep -Ev '#|^$' conf/nginx.conf
#vim普通模式下 删除所有内容
ggdG

修改nginx.conf

在nginx.conf文件进行配置,让所有后缀名为.php的文件转发到当前计算机的9000端口

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        root html;
        location / {
            index  index.html index.htm;
        }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }
    }
}

编写测试文件

vim /usr/local/nginx/html/demo.php
<?php
        phpinfo();
?>

访问phpinfo()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值