CentOS 7 部署LAMP架构(独立服务模式)

细节要求:(1) 三者分离于三台主机,Httpd与PHP以FastCGI模式通讯;

(2) 一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;

(3) 部署PHP加速器:xcache;

一、准备CentOS 7主机环境以及Repo仓库提供基于rpm安装包方式的程序包安装源

安装主机程序包规划:

主机1:web-server(192.168.1.132)  –安装httpd(2.4.6)

主机2:php-server(192.168.1.200)  –安装php-fpm(5.4.16),php-mysql,xcache,第三方软件wordpress.phpMyAdmin

主机3:db-server(192.168.1.201)    –安装mariadb-server(5.5.52)

3台主机均关闭selinux进程

二、web-server主机服务包与程序安装过程

#yum install httpd  -y                                                        –安装httpd服务

#systemctl enable httpd.service                                        –设置httpd服务开机自动运行

#systemctl start httpd.service                                            –启动httpd服务进程

#systemctl status httpd.serice                                            –查看httpd服务进程状态

#firewall-cmd –permanent –add-service=http               –设置防火墙允许http服务策略

#firewall-cmd –reload                                                      –加载防火墙策略

#ss -tnl | grep 80                                                               –查看httpd服务监听状态

#httpd -M | grep fcgi                                                        –查看httpd服务是否运行fastCGI调用模块

image.png

三、php-server主机安装过程

#yum install php-fpm php-mysql php-xcache  -y          –安装php-fpm服务

#yum install wordpress phpMyAdmin -y                        –安装第三方软件

#vim /etc/php-fpm.d/www/conf                                     –配置php-fpm服务参数

listen = 192.168.1.200:9000                                             –设置本机的socket监听服务

listen.allowed_clients = 192.168.1.132                             –设置允许访问php-fpm服务的客户端地址

#systemctl enable php-fpm.service                                 –启用php-fpm开机自动运行

#systemctl start php-fpm.service                                    –启动php-fpm服务进程

#systemctl status php-fpm.service                                  –查看服务进程状态

#firewall-cmd –permanent –add-port=9000/tcp          –设置防火墙允许php-fpm端口策略

#firewall-cmd –reload                                                     –加载防火墙策略

#ss -tnl | grep 9000                                                          –查看php-fpm服务的9000端口是否已启动并监听

#mkdir -pv /var/www/http/www                                     –创建测试web-server与php-server代理转发

#vim /var/www/http/www/index.php                              –创建测试页面

This is php-server

<?php

     phpinfo();

?>

测试结果

image.pngCentOS 7 部署LAMP架构(独立服务模式)

针对wordpress第三方软件的配置

#vim /etc/httpd/conf.d/wordpress.conf

<Directory /usr/share/wordpress>

  AllowOverride Options

  <IfModule mod_authz_core.c>

    # Apache 2.4

   Require all granted                                                   ##允许远程网络浏览访问资源

  </IfModule>

  <IfModule !mod_authz_core.c>

    # Apache 2.2

    Order Deny,Allow

    Deny from All

    Allow from 127.0.0.1

    Allow from ::1

</IfModule>

</Directory>

#vim /etc/wordpress/wp-config.php                                                  –定义访问远程mariadb数据的信息

// ** MySQL settings – You can get this info from your web host ** //

/** The name of the database for WordPress */

define('DB_NAME', 'test');

/** MySQL database username */

define('DB_USER', 'wordpress');

/** MySQL database password */

define('DB_PASSWORD', 'redhat');

/** MySQL hostname */

define('DB_HOST', '192.168.1.201');

/** Database Charset to use in creating database tables. */

define('DB_CHARSET', 'utf8');

针对phpMyAdmin第三方软件的配置

#vim /etc/httpd/conf.d/phpMyAdmin.conf

<Directory /usr/share/phpMyAdmin/>

   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>

     # Apache 2.4

     <RequireAny>

       Require all granted                                                         ##允许远程网络浏览访问资源

       Require ip ::1

     </RequireAny>

   </IfModule>

   <IfModule !mod_authz_core.c>

     # Apache 2.2

     Order Deny,Allow

     Deny from All

     Allow from 127.0.0.1

     Allow from ::1

   </IfModule>

</Directory>

#vim /etc/phpMyAdmin/config.inc.php                              –仅指定远程mariadb数据库IP地址即可,其他保留默认

// The $cfg['Servers'] array starts with $cfg['Servers'][1].  Do not use

// $cfg['Servers'][0]. You can disable a server config entry by setting host

// to ''. If you want more than one server, just copy following section

// (including $i incrementation) serveral times. There is no need to define

// full server array, just define values you need to change.

$i++;

$cfg['Servers'][$i]['host']          = '192.168.1.201'; // MySQL hostname or IP address

$cfg['Servers'][$i]['port']          = '';          // MySQL port – leave blank for default port

$cfg['Servers'][$i]['socket']        = '';          // Path to the socket – leave blank for default socket

$cfg['Servers'][$i]['connect_type']  = 'tcp';       // How to connect to MySQL server ('tcp' or 'socket')

$cfg['Servers'][$i]['extension']     = 'mysqli';    // The php MySQL extension to use ('mysql' or 'mysqli')

$cfg['Servers'][$i]['compress']      = FALSE;       // Use compressed protocol for the MySQL connection

                                                    // (requires PHP >= 4.3.0)

$cfg['Servers'][$i]['controluser']   = '';          // MySQL control user settings

                                                    // (this user must have read-only

$cfg['Servers'][$i]['controlpass']   = '';          // access to the "mysql/user"

                                                    // and "mysql/db" tables).

                                                    // The controluser is also

四、db-server主机安装过程

#yum install mariadb-server -y                                        –安装mariadb数据库服务

#firewall-cmd –permanent –add-service=mysql           –设置防火墙允许mysql服务端口3306

#firewall-cmd –reload                                                     –加载防火墙策略

#vim /etc/my.cnf                                                              –修改mariadb配置文件

skip_name_resolve = ON                                                  –禁用数据库主机名解析

#systemctl enable mariadb.service                                  –启用mariadb服务开机自动运行

#systemctl start mariadb.service                                      –启动mariadb服务

#systemctl status mariadb.service                                    –查看服务进程状态

#ss -tnl | grep 3306                                                           –查看mysql端口监听状态

#/usr/bin/mysql_secure_install                                         –进行数据库初始化安装,设置root密码,是否允许远程访问管理等

#mysql -uroot -hlocalhost -p                                           –设置第三方程序访问数据库的账户权限

Mariadb[(none)]>grant all privileges on test.* to 'wordpress'@'192.168.1.%' identified by 'redhat';       –授予wordpress远程访问test数据库的权限

Mariadb[(none)]>grant all privileges on *.* to 'pmauser'@'192.168.1.%' identified by 'redhat';              –授予pmauser远程管理mariadb所有数据库的权限

五、web-server主机上创建虚拟主机,并设置php转发过程

#mkdir -pv /var/www/http/{www,wordpress,pma}                    –创建不同虚拟主机的主目录

#touch /var/www/http/{www,wordpress,pma}/index.php         –创建空的.php文件,提供FastCGI转发

#vim /etc/httpd/conf.d/virtualhost.conf                                    –创建并编辑针对虚拟主机的配置文件

<VirtualHost *:80>                                                                      ##测试FastCGI连通性

   ServerName www.test.com

   DocumentRoot /var/www/http/www

   DirectoryIndex index.php

   ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/var/www/html/$1"

</VirtualHost>

<VirtualHost *:80>                                                                       ##测试phpMyAdmin

   ServerName pma.test.com

   DocumentRoot /var/www/http/pma

   DirectoryIndex index.php

   ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/usr/share/phpMyAdmin/$1"

</VirtualHost>

<VirtualHost *:80>                                                                        ##测试wordpress

   ServerName wordpress.test.com

   DocumentRoot /var/www/http/wordpress

   DirectoryIndex index.php

   ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/usr/share/wordpress/$1"

</VirtualHost>

六、验证虚拟主机访问

访问http://pma.test.com/phpmyadmin  虚拟主机

image.png

输入运行数据库远程访问的账户信息,打开图形化管理数据库的页面

image.png

访问http://wordpress.test.com 虚拟主机

image.png

原创文章,作者:N24_shishen,如若转载,请注明出处:http://www.178linux.com/69017

(0)
N24_shishenN24_shishen
上一篇 2017-02-17 08:48
下一篇 2017-02-17 16:42

相关推荐

  • shell脚本编写-2

    1、条件判断if语句       1)、 单分支 if  判断条件;then     条件为真的分支代码     fi 2)、双分支     if  判断条件; then    &…

    Linux干货 2016-08-15
  • 在马哥学习linux第一天的感受

         来马哥教育好几天了,昨天算是正式开始,在昨天早上,举行了开班典礼,各位老师助教为我们介绍了在马哥教育进行培训的相关注意事项,下午进行了两场测试,首先有一个摸底测试,不得不说我真的是太菜了,除了一些比较简单的题目我还有些把握,相当一部分我都是似曾相识,但是也不是很确定,还有很大一部分我根本听都没听说过,看到别人都写的满满…

    Linux干货 2017-07-11
  • CentOS上配置rsyslog客户端用以远程记录日志

    rsyslog是一个开源工具,被广泛用于Linux系统以通过TCP/UDP协议转发或接收日志消息。rsyslog守护进程可以被配置成两种环境,一种是配置成日志收集服务器,rsyslog进程可以从网络中收集其它主机上的日志数据,这些主机会将日志配置为发送到另外的远程服务器。rsyslog的另外一个用法,就是可以配置为客户端,用来过滤和发送内部日志消息到本地文件…

    Linux干货 2015-02-14
  • 马哥教育网络班21期+第12周课程练习 ​

    1、请描述一次完整的http请求处理过程;   1)客户端和服务器端建立连接。服务器接收或者拒绝请求。   2)服务器端接收客户端请求。接收来自于网络的请求报文中对某资源的一次请求。对请求的处理响应,可分为单进程(启动一个进程处理请求,一次只处理一个)和多进程(并行启动多个进程,每个进程处理一个请求)。  &…

    Linux干货 2016-10-09
  • 设计模式(十)享元模式Flyweight(结构型)

    相对于其它模式,Flyweight模式在PHP实现似乎没有太大的意义,因为PHP的生命周期就在一个请求,请求执行完了,php占用的资源都被释放。我们只是为了学习而简单做了介绍。 1. 概述 面向对象技术可以很好地解决系统一些灵活性或可扩展性或抽象性的问题,但在很多情况下需要在系统中增加类和对象的个数。当对象数量太多时,将导致运行代价过高,带来性能下降等问题。…

    Linux干货 2015-07-08
  • 系统之锹sysdig:Linux服务器监控和排障利器

    当你需要追踪某个进程产生和接收的系统调用时,首先浮现在你脑海中的是什么?你可能会想到strace,那么你是对的。你会使用什么样的命令行工具来监控原始网络通信呢?如果你想到了tcpdump,你又作出了一个极佳的选择。而如果你碰到必须追踪打开的文件(在Unix意义上:一切皆文件)的需求,可能你会使用lsof。 strace、tcpdump以及lsof,确实是些伟…

    Linux干货 2015-02-09

评论列表(2条)

  • luoweiro
    luoweiro 2017-02-23 07:31

    对于分开部署,后期学到nginx的时候,也可以多采用这种方式,但是要注意如果是多台机器如何做负载均衡,负载均衡的策略是怎样的?

    • N24_shishen
      N24_shishen 2017-02-24 10:58

      @luoweiro
      好的。有待后期继续学习新的知识点以后,在来更新。