Nginx与LAMP架构的动静分离实操(yum方式搭建LAMP架构、实现网页的动静分离)

一 、yum方式搭建LAMP架构

这里的LAMP架构,我们不采用之前用的手工编译安装,使用yum安装,搭建LAMP架构的服务器IP为14.0.0.27

[root@localhost ~]# yum install httpd httpd-devel -y  ##安装apache服务
[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y   ##安装轻量化数据库包
[root@localhost ~]# systemctl start mariadb.service 
[root@localhost ~]# netstat -ntap | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      15604/mysqld        
[root@localhost ~]# mysql_secure_installation     ##数据库初始化设置
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y        ##设置数据库root密码
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n        ##是否移除匿名用户
 ... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n    ##是否不允许root远程登录
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n   ##是否删除测试数据库
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y     ##是否重新加载数据库
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@localhost ~]# yum install php -y   ##安装php服务

[root@localhost ~]# yum install php-mysql -y   ##安装php数据库

[root@localhost ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath    ##安装php功能依赖包

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vim index.php
<?php
  phpinfo();
?>
[root@localhost html]# systemctl restart httpd

在这里插入图片描述
在这里插入图片描述

[root@localhost html]# vim index.php   ##修改php的网页首页,方便观察
<?php
  echo "this is apache web"
?>
[root@localhost html]# systemctl restart httpd

在这里插入图片描述

二、 手工编译安装nginx

[root@localhost ~]# hostname nginx
[root@nginx ~]# cd /opt
讲软件包拷贝进来
[root@nginx opt]# ls
[root@nginx opt]# tar zvxf nginx-1.12.2.tar.gz 
[root@nginx opt]# cd nginx-1.12.2/
[root@nginx nginx-1.12.2]# useradd -M -s /sbin/nologin nginx
[root@nginx nginx-1.12.2]#  yum install pcre pcre-devel zlib-devel gcc gcc-c++ -y
[root@nginx nginx-1.12.2]# ./configure    
--prefix=/usr/local/nginx    
--user=nginx    
--group=nginx    
--with-http_stub_status_module 
[root@nginx nginx-1.12.2]# make && make install
[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin
[root@nginx nginx-1.12.2]# vim /etc/init.d/nginx   ##制作service管理脚本
#!/bin/bash
#chkconfig:-  99 20
#description:Nginx Service 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

[root@nginx nginx-1.12.2]# chmod +x /etc/init.d/nginx 
[root@nginx nginx-1.12.2]# chkconfig --add /etc/init.d/nginx 
[root@nginx nginx-1.12.2]# yum install elinks -y
[root@nginx nginx-1.12.2]# service nginx start 
[root@nginx nginx-1.12.2]# systemctl stop firewalld
[root@nginx nginx-1.12.2]# setenforce 0
[root@nginx nginx-1.12.2]# elinks 14.0.0.14

在这里插入图片描述

[root@nginx nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf
 location ~ \.php$ {
            proxy_pass   http://14.0.0.27;
        }

[root@nginx nginx-1.12.2]# service nginx stop
[root@nginx nginx-1.12.2]# service nginx start

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/kimowinter/article/details/107957980