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

相关推荐

  • LInux系统启动与内核管理(下)

    从上一篇介绍了系统启动流程可以得知,在BIOS读取相关信息之后,接下来就是去找第一个可以启动的设备当中的MBR中读取Boot Loader信息,Boot Loader提供具有惨淡功能,直接加载内核信息,以及相关的控制权转交功能。启动系统必须有Boot Loader,然后才能去加载内核,Boot Loader存储于MBR当中,MBR只有512字节,其中前446…

    Linux干货 2016-09-19
  • 配额、RAID、软RAID以及LVM管理

    磁盘配额允许控制用户或者组织对磁盘的使用,它能防止个人或者组织使用文件系统中超过自己使用的部分,或者造成系统完全拥堵。配额必须由root用户或者具有root权限的用户启用和管理。 硬RAID以及软RAID :RAID是Redundant Array of Independent Disks的简写,即独立硬盘冗余阵列,简称磁盘阵列。通过实现的方式不同…

    Linux干货 2016-11-23
  • N28-第二周作业

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 命令:cp、mv、rm 1.1 cp命令 用法: cp [OPTIONS]…[-T] SOURCE DEST cp SRC DEST而言,SRC是文件时 如果目标不存在: 新建DEST,并将SRC中内容填充至DEST中 如果目标存在: 如果DEST是文件:将SRC中的内容覆盖至DE…

    Linux干货 2017-12-15
  • mysql慢查询日志进行按库切割重写文件然后分析

    需求: 把每天的慢查询日志进行按库切割 对每个库的慢查询日志进行分析 思路: 工具/功能 一般统计信息 高级统计信息 脚本 优势 mysqldumpslow 支持 不支持 perl mysql官方自带 mysqlsla 支持 支持 perl 功能强大,数据报表齐全,定制化能力强. mysql-explain-slow-log 支持 不支持 perl 无 my…

    Linux干货 2015-04-03
  • 网卡别名与bonding

    网络接口配置-bonding Bonding简介 Bonding 就是将多块网卡绑定同一IP地址对外提供服务,可以实现高 可用或者负载均衡。然,直接给两块网卡设置同一IP地址 是不可能的。通过bonding,虚拟一块网卡对外提供连接, 物理网卡的被修改为相同的MAC地址。 Bonding模式 Mode 0 (balance-rr) 轮转(Round-robi…

    Linux干货 2016-09-05
  • iptables的DNAT、SNAT配置

    DNAT:目的地址转换。当外网主机访问内网的某台服务器的时候,如果直接暴露服务器的IP于公网,可能会遭受各种各样的攻击,而DNAT的主要作用就是在服务器前面添加一台防火墙。将防火墙的地址公布出去,让外网客户端通过访问防火墙的地址就可以访问到本地服务器。这样就起到了保护服务器的目的; SNAT:源地址转换。内网主机在访问互联网的时候所有源地址都转换为防火墙的外…

    2017-06-12