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

相关推荐

  • 无插件Vim编程技巧

    相信大家看过《简明Vim教程》也玩了《Vim大冒险》的游戏了,相信大家对Vim都有一个好的入门了。我在这里把我日常用Vim编程的一些技巧列出来给大家看看,希望对大家有用,另外,也是一个抛砖引玉的过程,也希望大家把你们的技巧跟贴一下,我会更新到这篇文章中。另外,这篇文章里的这些技巧全都是vim原生态的,不需要你安装什么插件。我的Vim的版本是7.2。 浏览代码…

    Linux干货 2015-04-01
  • Ubuntu之apt-get光盘源配置小结

    Ubuntu配置本地apt源的方法:    1. 命令自动配置:        mount    /dev/cdrom   /mnt/cdrom        apt-cdrom   ident   &nbsp…

    Linux干货 2016-03-09
  • N26-博客作业-week11

    1、详细描述一次加密通讯的过程,结合图示最佳。 加密过程 1、先用单向加密算法计算出数据的特征码 2、私钥加密特征码,并将结果附加在数据之后 3、生成一个临时的对称密钥,并使用对称密钥加密整段数据 4、获取对方的公钥,使用该公钥加密之前生成的临时对称密钥,并附加在数据之后 5、将所有数据发送给对方解密过程 1、先使用私钥解密加密的对称密钥 2、用对称密钥解密…

    2017-04-18
  • 网络管理之网络配置

    一:博客 1 centos6网卡别名 在Linux系统中,我们可以在一块物理网卡上配置多个IP地址,以此来实现类似子接口的功能,我们称之为网卡别名。 设置网卡别名,先在/etc/sysconfig/network-scripts目录下将eth0文件复制名为eth0:1的文件,复制文件中的1可随意设置,但为方便管理建议按顺序排列 注意要修改ifcfg-eth0…

    Linux干货 2016-09-05
  • 马哥教育21期网络班—第9周课程+练习—-成长进行时–不退步

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash  declare -i other=0 declare -i nologin=0   &nbs…

    Linux干货 2016-09-05
  • 第六周作业

    第六周作业 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; cp /etc/rc.d/rc.sysinit /tmp vim /tmp/rc.sysinit :进入末行模式 % s/^[[:space:]]/#&…

    Linux干货 2016-10-09