Administrator
发布于 2021-05-19 / 15 阅读
0
0

ECS 搭建LNMP环境(CentOS 7)

  1. 配置防火墙

    1. 查询防火墙状态

 systemctl status firewalld

返回下列结果(inactive为关闭状态)

● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
  • 如果防火墙状态打开,输入下列代码关闭

 systemctl stop firewalld
  • 设置开机启动防火墙

 systemctl enable firewalld
  • 设置开机关闭防火墙

 systemctl disable firewalld
  1. 安装Nginx(这里安装1.8.1版本Nginx)

    1. 进入/usr/local/src/文件夹目录,手动下载压缩包

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.8.1.tar.gz
  • 安装相关依赖

yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
  • 手动解压压缩包,删除压缩包并进入nginx-1.8.1目录

tar -xvf nginx-1.8.1.tar.gz
rm -f nginx-1.8.1.tar.gz
cd nginx

  • 依次运行以下命令,编译源码

./configure \
 --user=nobody \
 --group=nobody \
 --prefix=/usr/local/nginx \
 --with-http_stub_status_module \
 --with-http_gzip_static_module \
 --with-http_realip_module \
 --with-http_sub_module \
 --with-http_ssl_module

make && make install
  • 运行以下命令,进入Nginx的sbin目录,然后启动Nginx

cd /usr/local/nginx/sbin/
./nginx
  • 在本地主机中,使用浏览器访问,ECS实例公网IP出现如下图所示的页面,表示Nginx已成功安装并启动。

  1. 安装Mariadb(Mariadb 和 MySQL功能操作差不多,这里因为MySQL登陆密码太麻烦选择Mariadb数据库)

    1. 测试与外网连接是否正常,按Ctrl+c退出测试

 ping www.baidu.com

  • 安装mariadb数据库,如果安装失败清空已安装文件

yum  install mariadb-server
yum  clean   all
  • 确认下载

  • 已安装完毕

  • 数据库启用

	1.   启动命令     systemctl  start  mariadb
	2.   重启命令     systemctl  restart  mariadb
	3.   关闭命令     systemctl  stop  mariadb
	4.   设定开机自起 systemctl  enable mariadb 
	5.   关闭开机自起 systemctl  disable mariadb 
  1. 配置Nginx

    1. 进入 /usr/local/nginx/conf

  • 复制一份原版nginx.conf文件为nginx.conf.bak

 cp nginx.conf ginx.conf.bak
  • 修改nginx.conf文件

 vim nginx.conf

  • 找到之前启动的nginx服务进程号,并结束进程(也可执行reload操作,但本文没有找到相关指令)

ps -ef | grep nginx

从容停止Nginx:kill -QUIT 主进程号  例如:kill -QUIT 16391

快速停止Nginx:kill -TERM 主进程号  
强制停止Nginx:kill -9 主进程号 
  • 重新执行回到 /usr/llocal/nginx/sbin 目录中执行启动操作 ./nginx

  • 配置mariadb

    1. 数据库初始化操作

 mysql_secure_installation

  • 测试数据库用户名和密码是否有效

  1. 安装php

    1. 更新yum源

      1. 添加epel源

yum install \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  • 添加webtatic源

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  • 安装php

yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  php70w-pdo.x86_64   php70w-mysqlnd  php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb
  • 检查php版本

 php -v

返回结果表示成功

PHP 7.0.33 (cli) (built: Dec  6 2018 22:30:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33, Copyright (c) 1999-2017, by Zend Technologies
  1. 配置php

    1. aaa

    2. a

    3. a

    4. a

    5. a

    6. a

    7. a


评论