构建LAMP服务平台

时间:2023-02-12 12:49:17

www服务器: 是基于http 协议来处理html编程出来的内容的。
那么http是什么呢? http: 超文本传输协议  80/tcp
https : 是基于 SSL/TLS的http协议, 443/tcp
HTML:超文本标记语言。
HTML的格式为:
<html>
<title></title>
<body></body>
</html>
2,Web服务器的架构是C/S模式的
   C : Client : browser浏览器   : IE Firefox chrome,safri, Opera,ab
   S:   Web Server :  Apache Nginx, Lighttpd
3,  客户端跟服务器端是怎么建立链接的:
    通过三次握手建立TCP链接,客户端然后发送 tcp 报文了,四次断开
4,请求报文、响应报文
 起始行:
 request
   <method><url><version>
  response
  <version><status code><reason_phrase>
  空白行
  <b ody>
  方法:
  GET : 就是浏览器直接向WWW服务器要求网址列上面的资源,这也是最常见的。
  POST HEAD PUT DELDET OPTIONS TRACE CONNECTION;

   web 服务器的工作模型:
   单进程/单线程
 多进程/多线程
 prefork worker
 maxcilents
 MPM: 多道处理模块。
 I/O多路复用模型。
 状态代码:
LAMP平台:  L:linux A:apache M:mysql P:php/perl/python
1xx: 纯信息
2xx: “成功”类的信息 (200, 201, 202)
3xx:重定向类的信息 (301, 302, 304)
4xx: 客户端错误类的信息 (404)
5xx:服务器端错误类的信息
  mysql:  
 
     mysql>show  databases;                                   查看所有数据库名称
    mysql>show  tables;                                      查看数据库中的表名
   mysql>use  数据库名;                                    更改数据库
   mysql>describe   表名;                                   查看表结构
   mysql>create  database  数据库名;                         创建数据库
   mysql>create  table  表名 (字段定义);                      创建表
   mysql>drop  table  表名;                                  删除表
   mysql>drop  database  数据库名;                           删除数据库
   mysql>insert  into表名(字段列表)  values(字段值列表);        向表插入数据
   mysql>select 字段名 from 表名 where 条件;                  在表中查找数据
   mysql>update 表名 set 字段名=值 where 条件;              更新表中的数据
   mysql>flush privileges;                                      刷新权限
   mysql>delete  from  表名  条件表达式                      从表中删除数据
   mysql>grant 权限 on 数据库.表名 to 用户名@主机IP  identifiedby 密码;      赋予权限
   mysql> revoke权限 on 数据库.表名 to 用户名@主机IP                       去除权限
   /usr/local/mysql/bin/mysqldump  -u 用户名 -p密码 数据库名  表名  >  备份文件名
   /usr/local/mysql/bin/mysqldump  -u 用户名 -p密码 –all-databases  >  备份文件名
   /usr/local/mysql/bin/mysql  -u 用户名 –p密码 数据库名 < 备份文件名
   /usr/local/mysql/bin/mysql  -u 用户名 –p密码  < 备份文件名
php
    常见的php加速器有:
  1、APC (Alternative PHP Cache)
  2、eAccelerator
  3、XCache
  4、Zend Optimizer和Zend Guard Loader
  5、NuSphere PhpExpress
   搭建LAMP
   httpd 2.4.3 + mysql-5.5.28 + php-5.4.8编译安装过程:

一、编译安装apache

1、解决依赖关系

httpd-2.4.3需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行,它们的下载路径为ftp://172.16.0.1/pub/Sources/new_lamp

(1) 编译安装apr

# tar xf apr-1.4.6.tar.bz2
# cd apr-1.4.6
# ./configure --prefix=/usr/local/apr
# make && make install

(2) 编译安装apr-util

# tar xf apr-util-1.4.1.tar.bz2
# cd apr-util-1.4.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
/etc/httpd                        服务器根目录
 /etc/httpd/conf/httpd.conf           主配置文件
   /var/www/html                   网站根目录
   /etc/init.d/httpd                   服务器控制脚本
   /usr/sbin/httpd                    服务器的主要执行程序
   /var/log/httpd/access_log           访问日志文件
/var/log/httpd/error_log             错误日志文件

附:apache官方对APR的介绍:

The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations. The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behaviour regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.

(3) httpd-2.4.2编译过程也要依赖于pcre-devel软件包,需要事先安装。此软件包系统光盘自带,因此,找到并安装即可。

2、编译安装httpd-2.4.3

首先下载httpd-2.4.3到本地,下载路径为ftp://172.16.0.1/pub/Sources/new_lamp。而后执行如下命令进行编译安装过程:

# tar xf httpd-2.4.3.tar.bz2
# cd httpd-2.4.3
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=event
# make && make install
   (--prefix指定安装位置,--enable-so启用动态模块加载功能,--enable-rewrite启用地址重写功能,
    --enable-ssl启用ssl支持,--with-ssl指定ssl库文件位置,--enable-auth-digest启用digest认证支持
    --enable-cgi启用cgi脚本支持,--enable-suexec启用suexec指令支持,--with-suexec-caller指定可以
    调用suexec指令的用户,--with-suexec-docroot指定可以使用suexec指令的根目录)
    编译安装产生的主要目录
 conf/           配置文件
 htdocs/         网站根目录
 bin/            可执行命令
 modules/        模块文件
 logs/           日志文件
 lib/            库文件
 apache配置文件及日志
配置文件的重要配置项
 ServerRoot      服务器根目录
 Listen          服务器监听的IP地址及端口号
 ServerName     服务器主机名
 DocumentRoot   网站根目录
 DirectoryIndex   默认主页文件名
apache日志类型
 访问日志:access_log,记录客户机IP,访问的时间,进行的操作
 错误日志:error_log,记录发生的错误信息
2、新建用户以安全方式运行进程:

# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data

3、安装并初始化mysql-5.5.28

首先下载平台对应的mysql版本至本地,这里是32位平台,因此,选择的为mysql-5.5.28-linux2.6-i686.tar.gz,其下载位置为ftp://172.16.0.1/pub/Sources/mysql-5.5

# tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local
# cd /usr/local/
# ln -sv mysql-5.5.28-linux2.6-i686  mysql
# cd mysql

# chown -R mysql:mysql  .
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
# chown -R root  .

4、为mysql提供主配置文件:

# cd /usr/local/mysql
# cp support-files/my-large.cnf  /etc/my.cnf

并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2

另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /mydata/data


5、为mysql提供sysv服务脚本:

# cd /usr/local/mysql
# cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld

添加至服务列表:
# chkconfig --add mysqld
# chkconfig mysqld on

而后就可以启动服务测试使用了。


为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
6、输出mysql的man手册至man命令的查找路径:

编辑/etc/man.config,添加如下行即可:
MANPATH  /usr/local/mysql/man

7、输出mysql的头文件至系统头文件路径/usr/include:

这可以通过简单的创建链接实现:
# ln -sv /usr/local/mysql/include  /usr/include/mysql

8、输出mysql的库文件给系统库查找路径:

# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf

而后让系统重新载入系统库:
# ldconfig

9、修改PATH环境变量,让系统可以直接使用mysql的相关命令。具体实现过程这里不再给出。


三、编译安装php-5.4.8

1、解决依赖关系:

请配置好yum源(可以是本地系统光盘)后执行如下命令:
# yum -y groupinstall "X Software Development"

如果想让编译的php支持mcrypt扩展,此处还需要下载ftp://172.16.0.1/pub/Sources/ngnix目录中的如下两个rpm包并安装之:
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm

2、编译安装php-5.4.8

首先下载源码包至本地目录,下载位置ftp://172.16.0.1/pub/Sources/new_lamp

# tar xf php-5.4.8.tar.bz2
# cd php-5.4.8
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts

说明:这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。

# make
# make test
# make intall

为php提供配置文件:
# cp php.ini-production /etc/php.ini

3、 编辑apache配置文件httpd.conf,以apache支持php
 
 # vim /etc/httpd/httpd.conf
 1、添加如下二行
   AddType application/x-httpd-php  .php
   AddType application/x-httpd-php-source  .phps

 2、定位至DirectoryIndex index.html
   修改为:
    DirectoryIndex  index.php  index.html

而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。

四、安装xcache,为php加速:

1、安装
# tar xf xcache-2.0.0.tar.gz
# cd xcache-2.0.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install

安装结束时,会出现类似如下行:
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

2、编辑php.ini,整合php和xcache:

首先将xcache提供的样例配置导入php.ini
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d

说明:xcache.ini文件在xcache的源码目录中。

接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。

虚拟主机
(1)虚拟主机类型:基于名称、基于IP、基于端口
(2)基于名称
 NameVirtualHost  主机IP
 <VirtualHost  主机IP>
  DocumentRoot    网页根目录
  ServerName      主机名称
   </VirtualHost>
(3)基于IP(同上)
(4)基于端口
     Listen    80
     Listen    端口号
     其它配置同上
3.用户个人主页
 UserDir  public_html
 <Directory  “/home/*/public_html”>
  AllowOverride  none
  Option  none
 Order  allow,deny 
  Allow  from all
   </Directory>
   创建对应目录,并给出权限。
1.测试服务器性能
使用AB进行压力测试
 /安装目录/bin/ab  [-q]  [-c  并发请求次数] [-n 总请求次数]  http://网站IP/文件名

本文出自 “self” 博客,请务必保留此出处http://leargood.blog.51cto.com/4457126/1040194