rpm实现LAMP

rpm实现LAMP部署

LAMP概述

LAMP指的Linux(操作系统)、ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web应用平台。常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

资源类型

静态资源:原始形式与响应给客户端的结果一致; 
动态资源:原始形式通常为程序文件(为某种编程语言开发),需要运行后将生成的结果展示给客户端;

CGI

Common Gateway Interface,是外部应用程序(CGI程序)与Web服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将Web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。

httpd+php

module:可基于模块 
    prefork:libphp 
    worker, event:libphp-zts 
FastCGI 
    php以fpm机制独立地监听在一个套接字上; 
    工作模式类似于httpd的prefork;

基于module安装LAMP

本次以CentOS 7为例进行安装,部署过程中会说明CentOS 6与CentOS 7的不同之处

安装httpd

[root@centos ~]# yum -y install httpd  #安装httpd
[root@centos ~]# systemctl start httpd.service   #CentOS 7启动服务
[root@centos ~]# service httpd start   #CentOS 6启动服务

HY8EOE9B9@QZHROX@I8G6_4.png

}_LC~SXSF7JZOF0NE()NBRD.png

安装php

[root@centos7 ~]# yum -y install php php-mysql

php配置文件:/etc/php.ini/etc/php.d/*.ini 
php:生成libphp5.so模块 支持动态解析 
php-mysql:php驱动mysql

}TMBMO)4T5L85~HDH11~0HW.png

安装mysql

[root@centos ~]# yum -y install mariadb-server  #CentOS 7
[root@centos ~]# systemctl start mariadb.service  #CentOS 7
[root@centos ~]# yum -y install mysql-server   #CentOS 6
[root@centos ~]# service mysqld start #CentOS 6

RN}%FLF7ZF{DRPUP6MG~)1S.png

M)_9FH124NC[}H@)X3ALO0T.png

初始化数据库

[root@centos7 ~]# mysql_secure_installation    #初始化配置数据库命令
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

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] y   #是否删除匿名用户
... Success!

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] y   #删除test库
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

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@centos ~]# systemctl restart httpd.service  #重启httpd服务并验证

U{PDC)P~H[HP(KK(DKCPSMF.png

WCMDIPDJ9F_}C`G{EB(8XFI.png

基于php-fpm搭建LAMP

前面已经讲解过httpd和mysql安装,此处不再做介绍

php-fpm安装

[root@centos ~]# yum -y install php-fpm   #CentOS 7
[root@CentOS ~]# yum -y install php-fpm mod_proxy_fcgi  #CentOS 6 需要安装mod_proxy_fcgi来提供fcgi模块,由EPEL源提供

V)NT_BTE33`4{O9J]4R`OBE.png

启动php-fpm服务

[root@centos ~]# systemctl start php-fpm.service #CentOS 7
[root@centos ~]# service php-fpm start  #CentOS 6

5WH`FOJUNO_E[33X2`IOOSI.png

php-fpm配置文件

ini:配置php解释器工作环境;
   /etc/php.ini, /etc/php.d/*.ini
conf:配置fpm守护进程的工作模式;
   /etc/php-fpm.conf, /etc/php-fpm.d/*.conf

配置项:
   /etc/php-fpm.conf
       [global]
       include=/etc/php-fpm.d/*.conf   # 包含/etc/php-fpm.d/*.conf的所有配置文件
       pid = /run/php-fpm/php-fpm.pid      # 进程的pid文件路径
       error_log = /var/log/php-fpm/error.log  # 错误日志文件路径
       log_level = notice      # 定义日志文件级别
       emergency_restart_threshold = 0     # 紧急情况重启进程的条件,一般禁用
       emergency_restart_interval = 0      # 紧急情况重启进程的时间间隔,一般为禁用
       process_control_timeout = 0     # 控制进程的超时时长
       daemonize = no      # 是否运行为守护进程,在CentOS 7上可以可配置为no,因为所有进程都由systemd管理

   /etc/php-fpm.d/*.conf
       [pool-id]
       listen = 127.0.0.1:9000     # 进程所监听的端口
       listen.backlog = -1     # 超出请求时的队列长度,-1表示没有上线
       listen.allowed_clients = 127.0.0.1  # 所允许的客户端列表
       user = apache   # 运行子进程的用户
       group = apache  # 运行子进程的组
       pm = dynamic
           定义process管理机制:static, dynamic
               static:服务启动时创建出所有子进程;
               dynamic:根据用户请求量的变化来维护子进程数量;
       pm.max_children = 50    # 最大子进程数
       pm.start_servers = 5    # 服务开启时所启动的子进程数
       pm.min_spare_servers = 5    # 最少空闲子进程数
       pm.max_spare_servers = 35   # 最大空闲子进程数
       pm.max_requests = 500   # 每个子进程所响应的最大请求数

       pm.status_path = /fpm-status    # php-fpm的状态页
       ping.path = /ping   # 向服务器发送ping
       ping.response = pong # 如果服务器正常,则回复pong
       request_terminate_timeout = 0 # 定义请求超时时长,0表示无限制
       request_slowlog_timeout = 0 # 定义满请求的时间,如果达到时长,则输出至慢请求日志当中
       slowlog = /var/log/php-fpm/www-slow.log     # 慢日志文件路径
       rlimit_files = 1024     # 限制用户请求的文件数
       rlimit_core = 0     #

       php_admin_value[error_log] = /var/log/php-fpm/www-error.log # 连接池的错误日志
       php_admin_flag[log_errors] = on     # 管理功能的标志位是否打开
       php_value[session.save_handler] = files     # php基于什么方式保存session
       php_value[session.save_path] = /var/lib/php/session     # session文件的存放路径

fpm配置虚拟主机反代配置

SB}8G_1BXD%X4A9_4__(S7Y.png

4HCRKKA[VC4LKBTO(_R{B$M.png

[root@centos ~]# systemctl restart httpd.service  ##重启httpd服务

测试

]6]1W3RN@@EO$UX(P[8LHCV.png

测试状态页以及ping页面

2YQQ3{X9BFB}414X}$XJUDQ.png

状态页参数讲解

http://WEB_SERVER:PORT/pm-status
   pool:                 www    # 连接池名称
   process manager:      dynamic    # 进程管理器类型
   start time:           26/Sep/2016:15:10:26 +0800    # 启动时间
   start since:          7437    # 运行时长
   accepted conn:        6    # 连接池已经处理过的总请求数
   listen queue:         0    # 队列的长度
   max listen queue:     0     #  请求队列的最大长度
   listen queue len:     128     # socket等待队列的最大长度;
   idle processes:       4    # 空闲的进程数;
   active processes:     1    # 活跃的进程数量;
   total processes:      5     # 总进程数;
   max active processes: 1     # 连接池当中过去最大活跃进程度;
   max children reached: 0     # 进程数量达到连接池上限的次数;
   slow requests:        0 # 慢请求的数量;

其它格式的输出:
   /pm-status?json
   /pm-status?xml
   /pm-status?html
   /pm-status?full

full格式的输出:
   pid:                  33095
   state:                Idle    # 当前进程的状态,idle, running, ...
   start time:           26/Sep/2016:15:10:26 +0800    # 进程启动的日期时间
   start since:          7968  # 运行时长
   requests:             2    # 处理过的请求数量
   request duration:     112     # 请求处理过程的时长
   request method:       GET    # 请求方法
   request URI:          /pm-status?html     # 请求的URL
   content length:       0    # 请求内容的长度,POST方法才有意义
   user:                 -     # 用户
   script:               -     # php脚本;
   last request cpu:     0.00    # 最近一次请求消耗CPU
   last request memory:  262144    # 最近一次请求消耗的内存量

测试ping页面

}WZ8G32C32INO7N}V~%[`UL.png

部署应用

部署phpMyadmin

[root@centos ~]# yum -y install php-mbstring php-mcrypt php-gd  #安装php相关包
[root@centos ~]# unzip phpMyAdmin-4.0.5-all-languages.zip  #解压phpMyadmin
[root@centos ~]# mv phpMyAdmin-4.0.5-all-languages/* /var/www/html/  #将文件移动至站点根目录

测试

~D}N`{M7PYZ148V]PF@C%DL.png

Y~}Y4OTOYV59C)PT6MG1E85.png

部署wordpress

配置数据库

[root@centos7 ~]# mysql -uroot -pmageedu   #以root身份登录数据库
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;    #显示所有数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> CREATE DATABASE wordpress;   #创建wordpress数据库
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%' IDENTIFIED BY 'mageedu';   #wordpress用户对wordpress数据库所有权
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;   #刷新授权
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> quit   #退出
Bye
[root@centos7 ~]#

部署

[root@centos7 ~]# unzip wordpress-4.5.3-zh_CN.zip   #解压wordpress
[root@centos7 ~]# mv wordpress/* /var/www/html/   #mv文件至网站访问根目录
[root@centos7 ~]# cd /var/www/html/  
[root@centos7 html]# cp wp-config-sample.php wp-config.php  #生成配置文件
[root@centos7 html]# vim wp-config.php  #编辑配置文件

K6P7))_BCXAISKNTY_G8NLF.png

GTKA)P59]_@)1]H@0BVLXD1.png

部署Discuz论坛

配置数据库

[root@centos7 ~]# mysql -uroot -pmageedu
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE bbs;  #创建bbs数据库
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON bbs.* TO 'bbs'@'%' IDENTIFIED BY 'mageedu';   #授权bbs用户对bbs数据库所有权
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;   #刷新授权
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> quit
Bye
[root@centos7 ~]#

部署

[root@centos7 ~]# unzip Discuz_X3.2_SC_UTF8.zip  #解压
[root@centos7 ~]# mv upload/* /var/www/html/  #移至网站根目录
[root@centos7 ~]# cd /var/www/html/
[root@centos7 html]# chmod -R a+w data/ config/ uc_client/ uc_server/   #对于指定目录赋予写入权限

HHQ6LWA~M5P_2UX{U[P_VCA.png

~E`~G02J(}BMFHXKSU_F)_9.png

EG(7Y)5`8P@P%VCXTGDLB$E.png

L4A_ZPEOKHOUM9Q@@E{]V[X.png

[JDKSG$3BV]JSLJ93XJCP)7.png

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

(0)
zhai796898zhai796898
上一篇 2016-11-02 23:02
下一篇 2016-11-02 23:27

相关推荐

  • 简单的shell脚本结合awk实现防止对web服务的dos攻击

    一 实验环境         鄙人使用的是centos 6.8操作系统   需要安装iptables(常见的linux系统貌似都会自动安装iptables)这条可以忽略   awk也需要安装没有的话就用yum装下吧       &…

    2017-04-24
  • nfs 共享实验

    nfs全称为:network file system    网络文件系统 在Linux里可以理解为将一个文件夹变成共享文件夹,让其他用户都可以访问。而访问的主机其本地磁盘是没有存储文件的 创建方法如下 :     准备两台机器,一台当 client  另一台当server    &nbsp…

    Linux干货 2017-06-07
  • shell脚本小练习..

    刚刚接触vim和shell脚本,用几个小脚本练练手。 1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 2、编写脚本/root/bin/backup.sh,可实现每日将/etc/目录备份到/root/etcYYYY-mm-dd中。 3、编写脚本…

    2017-04-13
  • LAMP基于RPM包实现(httpd与php以fastcgi方式结合) 2

    概述:     承接上篇,本篇为介绍下利用rpm包,实现LAMP组合,其中httpd和php的结合方式为fastcgi,也就是php运行为独立的服务,监听的某个套接字上,接受请求,提供服务     包括LAMP安装过程(http、php-fpm、mysql-server、php-…

    Linux干货 2016-10-15
  • 计算机的组成

        计算机组成(computer composition)指的是系统结构的逻辑实现,包括机器机内的数据流和控制流的组成及逻辑设计等。 计算机组成的任务是在指令集系统结构确定分配给硬件系统的功能和概念结构之后,研究各组成部分的内部构造和相互联系,以实现机器指令集的各种功能和特性。这种联系包括各功能部件的内部和相   &nbsp…

    2017-03-26
  • LVM逻辑卷管理

    一、lvm介绍     1.lvm概念                        &n…

    Linux干货 2016-09-02