建立httpd服务器,要求:
1)提供两个基于名称的虚拟主机:
(a)www1.magedu.com,页面文件目录为/var/www/html/www1;错误日志为/var/log/httpd/www1.err,访问日志为/var/log/httpd/www1.access;为此虚拟主机提供php+mysql的服务,要求:
 (1)通过在原有主页中添加phpinfo()测试页表明启用php成功;
 (2)将mysql的root用户密码设置为"123456"(引号中的内容);
 (3)通过http://www1.magedu.com/pma提供本机mysql服务的web管理接口;
(b)www2.magedu.com,页面文件目录为/var/www/html/www2;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/www2.access;
(c)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名;
2)www1主机仅允许172.16.0.0/16网络中的客户机访问;www2主机可以被所有主机访问;为此虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点;
 (1)要求使用证书认证,证书中要求使用的国家(CN)、州(Henan)、城市(Zhengzhou)和组织(linux);
 (2)设置部门为TECH,主机名为www2.magedu.com,邮件为[email protected]
 (3)此服务禁止来自于192.168.0.0/24网络中的主机访问;

编译安装httpd
# yum groupinstall -y "Development Libraries" "Development Tools" "X Software Development"
 
# yum install -y pcre pcre-devel 
 
# rpm -Uvh apr-1.4.6-1.i386.rpm
 
# rpm -Uvh apr-devel-1.4.6-1.i386.rpm
 
# rpm -Uvh apr-util-1.4.1-1.i386.rpm
 
# rpm -Uvh apr-util-devel-1.4.1-1.i386.rpm
 
# yum install -y pcre pcre-devel

# tar xf httpd-2.4.1.tar.bz2
 
# cd httpd-2.4.1
 
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib
 
# make
 
# make install
 配置web服务
#  mkdir -pv /var/www/html/www1
#  mkdir -pv /var/www/html/www2
# echo "

www1.magedu.com

" >          /var/www/html/www1/index.html
# echo "

www2.magedu.com

" > /var/www/html/www2/index.html
 

# vim /etc/httpd/httpd.conf
把Include /etc/httpd/extra/httpd-vhosts.conf 前面的#号去掉
# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf
 
# vi /etc/httpd/extra/httpd-vhosts.conf

 ServerAdmin [email protected]
 DocumentRoot "/var/www/html/www1"
 ServerName www1.magedu.com
 ErrorLog "/var/log/httpd/www1.err"
 CustomLog "/var/log/httpd/www1.access" common
 
 Order allow,deny
 Allow from 172.16.0.0/16
 Deny from all
 



 ServerAdmin [email protected]
 DocumentRoot "/var/www/html/www2"
 ServerName www2.magedu.com
 ErrorLog "/var/log/httpd/www2.err"
 CustomLog "/var/log/httpd/www2.access" common
 

安装mysql-5.5.19
1、准备数据存放的文件系统
 
新建一个逻辑卷,并将其挂载至特定目录即可,过程:
fdisk /dev/sda 建一个分区,大概2G 即可,类型要是8e的。如 /dev/sda5
     # pvcreate /dev/sda5先创建物理卷
     # vgcreate myvg /dev/sda5再创建物理卷组
     # lvcreate -L 1G -n lv1 /dev/myvg   创建逻辑卷并指定大小为1G,名字为lv1
     # mke2fs -j /dev/myvg/lv1格式化
其逻辑卷的挂载目录为/mydata,则# mkdir /mydata
                                       # mount /dev/myvg/lv1 /mydata 如果想开机自启动,则可在/etc/fstab内添加内容。
而后需要创建/mydata/data目录做为mysql数据的存放目录。
    # mkdir /mydata/data
 
 
这里假设其逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为mysql数据的存放目录。
 
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.19
 
首先下载平台对应的mysql版本至本地,这里是32位平台,因此,选择的为mysql-5.5.19-linux2.6-i686.tar.gz,
 
# tar xf mysql-5.5.19-linux2.6-i686.tar.gz -C /usr/local
# cd /usr/local/
# ln -sv mysql-5.5.19-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
vim /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
并查看是否有执行权限,若无 则加上执行权限
service mysqld start
 
添加至服务列表:
# chkconfig --add mysqld
# chkconfig mysqld on
 
而后就可以启动服务测试使用了(service mysql start)。
 
为了使用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
若无mysql库文件则:
vim /etc/ld.so.conf.d/mysql.conf
添加/usr/local/mysql/bin
则再次重新载入系统库即可
 
9、修改PATH环境变量,让系统可以直接使用mysql的相关命令。
步骤如下
Vim /etc/profile
增加:PATH=$PATP:/usr/local/mysql/bin
至此mysql源码编译安装完成
mysql
>use mysql
> update user set password=password('123456') where user='root' and host='127.0.0.1';
 
 
编译安装php
 tar xf php-5.3.10.tar.bz2
# cd php-5.3.10
# ./configure --prefix=/usr/local/php4httpd --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  --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt
 
说明:如果前面第1步解决依赖关系时安装mcrypt相关的两个rpm包,此./configure命令还可以带上--with-mcrypt选项以让php支持mycrpt扩展。
 
# make
# make test
# make intall
 
为php提供配置文件:
# cp php.ini-production /usr/local/php/lib/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
 cd /var/www/html/www1
   mv index.html index.php
   vim index.php
        phpinfo();
   ?>
   而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。
 
下载phpMyAdmin-2.11.10-all-languages.tar.gz
tar xvf phpMyAdmin-2.11.10-all-languages.tar.gz
cd phpMyAdmin-2.11.10
mv * ../pma
cd ../pma
cp config.sample.inc.php config.inc.php
vim config.inc.php  在$cfg['blowfish_secret'] = 'huewfeondhzn'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
然后重新启动服务: service httpd restart
在浏览器输入网址: http://www1.magedu.com/pma

提供https

vim /etc/pki/tls/openssl.cnf
 修改  dir    =  /etc/pki/CA
cd /etc/pki/CA
#(umask 077; openssl genrsa 2048 > private/cakey.pem)  此处存放CA的密钥

#openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650   自己作为CA服务器 申请发证并签证

#mkdir cdrts crl newcerts
#touch index.txt serial
#echo 01 > serial
#echo 01 > crlnumber

#cd /etc/httpd/
#mkdir ssl
#cd ssl
#(umask 077; openssl genrsa 1024 > httpd.key)    生成私钥文件
#openssl req -new -key httpd.key -out httpd.csr   提起公钥www2.magedu.com
#openssl ca -in httpd.csr -out httpd.crt 请求CA颁发证书

vim /etc/httpd/conf
把Include /etc/httpd/extra/httpd-ssl.conf前的#去掉
 
加载ssl所需要的模块,打开第88行和第128行的注释
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so

vim /etc/httpd/extra/httpd-ssl.conf

 
# General setup for the the virtual host
DocumentRoot "/var/www/html/www2
ServerName www2.magedu.com:443
ServerAdmin [email protected]
ErrorLog "/var/log/httpd/error_log"
TransferLog "/var/log/httpd/access_log"

    Order deny,allow
    Deny from 192.168.0.0/24

 
打开以下注释:
SSLCertificateFile "/etc/httpd/ssl/httpd.crt"
SSLCertificateKeyFile "/etc/httpd/ssl/httpd.key"

yum install mod_ssl
vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/var/www/html/www1"
ServerName www2.magedu.com
SSLCertificateFile /etc/httpd/conf/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl/httpd.key