httpd-2.4.4(apr-1.4.6 apr-util-1.5.1 pcre-8.32)
mysql-5.6.10
php-5.4.13
phpMyAdmin-3.5.7
wordpress-3.5.1
dhcp-4.2.5
如果读者有看不到的图片请点击该图片
首先我们把项目所要求的服务的源码安装包准备好,并传到服务器上,如图:图1-1:
图1-1
[root@localhost ~]# tar -jxvf apr-1.4.6.tar.bz2 -C /usr/local/src/
[root@localhost ~]# tar -jxvf apr-util-1.5.1.tar.bz2 -C /usr/local/src/
[root@localhost ~]# tar -jxvf pcre-8.32.tar.bz2 -C /usr/local/src/
[root@localhost ~]# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/ //解压安装apache源码包所需要的包apr,apr-util,pcre,httpd
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ll
total 16
drwxr-sr-x 25 5000 10001 4096 Feb 8 2012 apr-1.4.6
drwxr-xr-x 19 500 1000 4096 Sep 8 2012 apr-util-1.5.1
drwxr-xr-x 11 501 games 4096 Feb 19 04:28 httpd-2.4.4
drwxr-xr-x 7 1169 1169 4096 Nov 30 18:50 pcre-8.32
Apr安装
[root@localhost src]# cd apr-1.4.6/
[root@localhost apr-1.4.6]# ./configure --help
[root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.4.6]# make && make install
Apr-util安装
[root@localhost apr-1.4.6]# cd ../apr-util-1.5.1/
[root@localhost apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@localhost apr-util-1.5.1]# make && make install
Pcre安装
[root@localhost apr-util-1.5.1]# cd ../pcre-8.32/
[root@localhost pcre-8.32]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.32]# make && make install
Apache安装
[root@localhost pcre-8.32]# cd ../httpd-2.4.4/
[root@localhost httpd-2.4.4]# mkdir /etc/httpd //创建配置文件存放目录
[root@localhost httpd-2.4.4]# vim INSTALL //查看安装信息
10 $ ./configure --prefix=PREFIX
11 $ make
12 $ make install
13 $ PREFIX/bin/apachectl start //apache服务给出的安装步骤
[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd/ --enable-sed --enable-ssl --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config --with-pcre=/usr/local/pcre/ --enable-mpms-shared=all --with-z --enable-so
[root@localhost httpd-2.4.4]# make && make install
切换到apache目录下,查看形成的文件。由于安装的路径并不是系统默认的路径,而每执行一次命令都要指明路径很麻烦,所以我们就把安装文件所形成的头文件目录include、库文件目录lib、可执行的二进制文件目录bin和配置文件xxx.conf/cnf与系统关联起来,下面其他源码的安装也是一样的。(如图:图1-1-1-1)
[root@localhost ~]# cd /usr/local/apache/
图1-1-1-1
//关联头文件目录(利用软链接,如图:图1-1-1-2):
图1-1-1-2
//关联库文件目录(创建并编辑库连接文件,编写路径和语句如下,如图:图1-1-3):
图1-1-1-3
//重新加载lib库的缓存(如图:图1-1-1-4)
图1-1-1-4
//关联bin目录(如图:图1-1-1-5)
图1-1-1-5
[root@localhost ~]# . /etc/profile //重新读取文件
[root@localhost apache]# cd /etc/init.d/
[root@localhost init.d]# vim httpd
1 #!/bin/bash
2 #chkconfig: 2345 90 70 //接受chkconfig管理的关键两行2,3行
3 #description: httpd server
4 . /etc/init.d/functions
5 #dinf path
6 HTTPD='/usr/local/apache/bin/httpd'
7 CONF='/etc/httpd/httpd.conf'
8 #dinf function
9 start () {
10 echo -n "httpd is starting...."
11 sleep 1
12 $HTTPD -f $CONF
13 [ $? -eq 0 ] &&touch /var/lock/subsys/http && echo -e "\033[31m OK \033[0m " || echo -e "It is \033[31m FAIL \033[0m"
14 }
15
16 stop () {
17 echo -n "httpd is stoping...."
18 sleep 1
19 killproc $HTTPD && echo -e && rm -rf /var/lock/subsys/http || echo -e "It is \033[31m FAIL \033[0m "
20 }
21
22 restart (){
23 [ -f /var/lock/subsys/http ] && stop && start || echo -e "\033[31m httpd is stopd\033[0m"
24 }
25
26 case $1 in
27 start)
28 start
29 ;;
30 stop)
31 stop
32 ;;
33 restart)
34 restart
35 ;;
36
37 *)
38 echo "Usage: {start|stop|restart}"
39 ;;
40 esac
[root@localhost init.d]# chmod a+x httpd //是启动脚本可运行
[root@localhost init.d]# chkconfig --add httpd
[root@localhost init.d]# chkconfig httpd on //加入开机自动启动
[root@localhost init.d]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost init.d]# service httpd start
httpd is starting.... OK
[root@localhost init.d]# netstat -tupln |grep httpd
tcp 0 0 :::80 :::* LISTEN 29988/httpd
[root@rhel5 ~]#vim /etc/httpd/httpd.conf //不是源码安装,所以配置没在标准路径/etc/httpd/conf/ 目录下(如图:图1-1-1-6):
图1-1-1-6
这里要注意:版本较低的浏览器有可能无法正常访问
图1-1-1-7
[root@localhost ~]# tar -zxvf mysql-advanced-5.6.10-linux-glibc2.5-i686.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -s mysql-advanced-5.6.10-linux-glibc2.5-i686 mysql //为了方便,创建链接(如图:图1-1-2-1):
图1-1-2-1
[root@localhost local]# cd myaql
//查看解压后的mysql目录(如图:图1-1-2-2)
图1-1-2-2
//把mysql手册添加到系统搜索路径内(如图:图1-1-2-3)
图1-1-2-3
[root@localhost mysql]# vim /etc/profile
//关联bin目录(如图:图1-1-2-4)
图1-1-2-4
[root@localhost mysql]# . /etc/profile //系统重新读取/etc/profile文件
[root@localhost mysql]# ln -s include /usr/local/include/mysql //关联头文件存放目录include
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf //关联库文件存放目录lib,如图:图1-1-2-5
图1-1-2-5
[root@localhost mysql]# vim INSTALL-BINARY //查看mysql二进制文件后安装步骤(如图:图1-1-2-6)
图1-1-2-6
[root@localhost mysql]# groupadd mysql //创建组
[root@localhost mysql]# useradd -r -g mysql mysql //创建mysql系统用户属于mysql组
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql //以mysql用户的身份运行脚本
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# bin/mysqld_safe --user=mysql & //以mysql用户的身份后台运行程序
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# service mysqld start
Starting MySQL.. [ OK ]
[root@localhost mysql]# netstat -tupln |grep mysqld
tcp 0 0 :::3306 :::* LISTEN 31620/mysqld
[root@localhost mysql]# service mysqld stop
Shutting down MySQL.. [ OK ]
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on //加入开机自动开启服务管理
[root@localhost mysql]# chkconfig --list |grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost mysql]# mysqladmin -u root -p password '123456' //第一次创建用户和密码只能是创建root用户
[root@localhost mysql]# mysql -u root -p //以后访问的方式为 mysql -u root -p
Enter password:
[root@localhost ~]# tar -jxvf php-5.4.13.tar.bz2 -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/php-5.4.13/
[root@localhost php-5.4.13]# vim INSTALL
[root@localhost php-5.4.13]# ./configure --help
[root@localhost php-5.4.13]# ./configure --prefix=/usr/local/php --sysconfdir=/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql
[root@localhost php-5.4.13]# make && make install
[root@localhost php-5.4.13]# cp php.ini-development /usr/local/lib/php.ini
[root@localhost php-5.4.13]# cd /usr/local/php/ //查看php安装目录(如图:图1-1-3-1)
图1-1-3-1
[root@localhost php]# vim /etc/profile
图1-1-3-2
[root@localhost php]# . /etc/profile
[root@localhost php]# ln -s include /usr/local/include/php
[root@localhost php]# vim /etc/ld.so.conf.d/php.conf
图1-1-3-3
[root@localhost php]# ldconfig
[root@localhost php-5.4.13]# vim INSTALL
[root@localhost ~]# vim /etc/httpd/httpd.conf //编辑apache配置文件(如图:图1-1-3-4至1-1-3-6)
图1-1-3-4
图1-1-3-5
图1-1-3-6
[root@localhost ~]# service httpd restart
httpd is stoping.... [ OK ]
httpd is starting.... OK
[root@localhost ~]# ll /usr/local/apache/modules/ |grep php // 查看apache模块库里是否形成了结合php的模块
-rwxr-xr-x 1 root root 18390015 May 12 00:00 libphp5.so
[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# mv index.html index.php
[root@localhost htdocs]# vim index.php
图1-1-4-1
//结果如图:图1-1-4-2
图1-1-4-2
//php与mysql的结合(如图:图1-1-4-3)
图1-1-4-3
//结果如图:图1-1-4-4
图1-1-4-4
//查看apache可选配置文件的存放目录(如图:图1-1-5-1)
图1-1-5-1
[root@localhost ~]# vim /etc/httpd/httpd.conf //编辑apache主配置文件(如图:图1-1-5-2 至 图1-1-5-4)
图1-1-5-2
图1-1-5-3
图1-1-5-4
[root@localhost ~]# mkdir -pv /www/www /www/tec /www/mkt /www/bbs //创建各个部门站点主目录
mkdir: created directory `/www'
mkdir: created directory `/www/www'
mkdir: created directory `/www/tec'
mkdir: created directory `/www/mkt'
mkdir: created directory `/www/bbs'
[root@localhost ~]# echo "www ok">/www/www/index.html //创建站点测试页
[root@localhost ~]# echo "tec ok">/www/tec/index.html
[root@localhost ~]# echo "mkt ok">/www/mkt/index.html
[root@localhost ~]# echo "bbs ok">/www/bbs/index.html
//测试,如图:图1-1-5-5
图1-1-5-5
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
[root@localhost ~]# cd /mnt/cdrom/Server/
[root@localhost Server]# rpm -ivh bind-9.3.6-4.P1.el5.i386.rpm bind-chroot-9.3.6-4.P1.el5.i386.rpm caching-nameserver-9.3.6-4.P1.el5.i386.rpm
//挂载光驱,安装DNS服务器所需要的三个rpm包
[root@localhost Server]# cd /var/named/chroot/
图1-2-1
[root@localhost chroot]# cd etc/
[root@localhost etc]# cp -p named.caching-nameserver.conf named.conf //拷贝配置文件
[root@localhost etc]# vim named.conf //编辑配置文件(如图:图1-2-2)
图1-2-2
[root@localhost etc]# vim named.rfc1912.zones //编辑区域文件(如图:图1-2-3)
图1-2-3
[root@localhost etc]# cd ../var/named/
[root@localhost named]# ll
total 36
drwxrwx--- 2 named named 4096 Aug 26 2004 data
-rw-r----- 1 root named 198 Jul 30 2009 localdomain.zone
-rw-r----- 1 root named 195 Jul 30 2009 localhost.zone
-rw-r----- 1 root named 427 Jul 30 2009 named.broadcast
-rw-r----- 1 root named 1892 Jul 30 2009 named.ca
-rw-r----- 1 root named 424 Jul 30 2009 named.ip6.local
-rw-r----- 1 root named 426 Jul 30 2009 named.local
-rw-r----- 1 root named 427 Jul 30 2009 named.zero
drwxrwx--- 2 named named 4096 Jul 27 2004 slaves
[root@localhost named]# cp -p localhost.zone cj.com.zone //生成并编辑区域文件配置(如图:图1-2-4)
[root@localhost named]# vim cj.com.zone
图1-2-4
[root@localhost named]# vim /etc/resolv.conf //更改服务器dns指向(如图:图1-2-5)
图1-2-5
[root@localhost named]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 //更改eth0 ip,网关应指为(GTWAY=192.168.20.9)如图:图1-2-6
图1-2-6
[root@localhost named]# service network restart
图1-2-7
[root@localhost ~]# tar -zxvf phpMyAdmin-3.5.7-all-languages.tar.gz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# mv phpMyAdmin-3.5.7-all-languages /www/tec/phpmyadmin //解压安装并转移到相应的站点目录下,访问如图:图1-3-1-1
图1-3-1-1
//用创建的mysal用户和密码登录phpmyadmin,如图:图1-3-1-2
图1-3-1-2
//新建数据库worepress 如图:图1-3-1-3
图1-3-1-3
[root@localhost ~]# tar -zxvf wordpress-3.5.1-zh_CN.tar.gz -C /usr/local/src/
[root@localhost ~]# mv /usr/local/src/wordpress /www/bbs/wordpress //解压安装并转移到相应的站点目录
[root@localhost ~]# cd /www/bbs/wordpress/
[root@localhost wordpress]# cp -p wp-config-sample.php wp-config.php //生成wordpress网页配置文件
[root@localhost wordpress]# vim wp-config.php //编辑动态网页配置文件
define('DB_NAME', 'worepress'); //定义数据库库名字
define('DB_USER', 'root'); //定义登录数据库的用户
define('DB_PASSWORD', '123456'); //指出登录数据库用户登录的对应的密码
define('DB_HOST', 'localhost'); //定义数据库所在主机为本机
define('DB_CHARSET', 'utf8'); //定义字符显示设置,以简体中文显示
//安装并注册论坛帐号 如图:图1-3-2-1至 图1-3-2-5
图1-3-2-1
图1-3-2-2
图1-3-2-3
图1-3-2-4
图1-3-2-5
[root@localhost ~]# vim /etc/httpd/httpd.conf //编辑apache主配置文件
Alias /tec "/www/tec"
<Directory "/www/tec"> //指明要实施安全性保护的目录
Options Indexes MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
[root@localhost ~]# vim /www/tec/.htaccess //在需要保护的目录下创建.htaccess文件(如图:图1-4-1-1)
图1-4-1-1
[root@localhost ~]# man htpasswd //在验证文件里导入用户帐号和密码(如图:图1-4-1-2)
图1-4-1-1
[root@localhost ~]# htpasswd -b /www/tec/.htpasswd user2 123456 //为.htpasswd文件正确创建帐号和密码的方法
Adding password for user user2
[root@localhost ~]# service httpd restart
httpd is stoping.... [ OK ]
httpd is starting.... OK
//重启服务,测试目录安全性(如图:图1-4-1-2 图1-4-1-3)
图1-4-1-2
图1-4-1-3
//安装openssl的rpm包
[root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo //编辑yum工具安装库(如图:图1-4-2-1)
图1-4-2-1
[root@localhost ~]# yum install openssl -y //安装openssl工具
[root@localhost ~]# rpm -ql openssl |less //查看安装后的路径(如图:图1-4-2-2)
图1-4-2-2
[root@localhost ~]# cd /etc/pki/
[root@localhost pki]# ll
total 32
drwx------ 7 root root 4096 Apr 4 19:55 CA
drwxr-xr-x 2 root root 4096 Mar 23 19:28 nssdb
drwxr-xr-x 2 root root 4096 Mar 23 19:29 rpm-gpg
drwxr-xr-x 5 root root 4096 Apr 4 20:22 tls
[root@localhost pki]# vim tls/openssl.cnf //编辑openssl配置文件,如图:图1-4-2-3
图1-4-2-3
[root@localhost pki]# cd CA
[root@localhost CA]# mkdir certs crl newcerts
[root@localhost CA]# touch index.txt serial //创建三个目录和两个文件
[root@localhost CA]# echo "01" > serial //为证书颁发机构CA创建初始证书值
[root@localhost CA]# openssl genrsa 1024 > private/cakey.pem //为CA产生私钥
[root@localhost CA]# chmod 600 private/cakey.pem //更改私钥权限
[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem //为CA产生证书
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Berkshire]:
Locality Name (eg, city) [BEIJING]:
Organization Name (eg, company) [BEIJING]:
Organizational Unit Name (eg, section) []:tec
Common Name (eg, your name or your server's hostname) []:bj.ca.net
Email Address []:
//CA证书产生完毕
[root@localhost CA]# mkdir /www/certs //为服务器创建证书存放目录
[root@localhost CA]# openssl genrsa 1024 >/www/certs/tec.key //产生服务器私钥
[root@localhost CA]# chmod 600 /www/certs/tec.key //更改私钥权限
Generating RSA private key, 1024 bit long modulus
.........++++++
.......++++++
e is 65537 (0x10001)
[root@localhost CA]# openssl req -new -key /www/certs/tec.key -out /www/certs/tec.crs //为服务器产生证书请求文件
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Berkshire]:
Locality Name (eg, city) [BEIJING]:
Organization Name (eg, company) [BEIJING]:
Organizational Unit Name (eg, section) []:tec
Common Name (eg, your name or your server's hostname) []:tec.cj.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@localhost CA]# ll /www/certs/
total 8
-rw-r--r-- 1 root root 651 May 12 16:53 tec.crs
-rw------- 1 root root 887 May 12 16:49 tec.key
[root@localhost CA]# openssl ca -in /www/certs/tec.crs -out /www/certs/tec.cert //向CA机构提交请求,为服务器产生证书
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: May 12 09:07:58 2013 GMT
Not After : May 12 09:07:58 2014 GMT
Subject:
countryName = CN
stateOrProvinceName = Berkshire
organizationName = BEIJING
organizationalUnitName = tec
commonName = tec.cj.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
3D:E8:E0:A3:5B:CD:04:27:E7:73:1E:76:92:E8:D2:66:24:12:C5:60
X509v3 Authority Key Identifier:
keyid:6B:68:25:1A:45:A8:2C:64:3C:EE:EC:71:FC:D0:C1:51:04:B4:4D:82
Certificate is to be certified until May 12 09:07:58 2014 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
//CA机构想服务器颁发证书完毕
[root@localhost CA]# vim /etc/httpd/httpd.conf //编辑apache主配置文件,使证书与技术部站点目录结合(如图:图1-4-2-4 至 1-4-2-7)
图1-4-2-4
图1-4-2-5
图1-4-2-6
图1-4-2-7
[root@localhost ~]# mkdir -pv /usr/local/apache/www/certs //创建服务器私钥存放目录
[root@localhost ~]# mv /www/certs/tec.key /usr/local/apache/www/certs
//服务器的证书存放在/www/certs目录下,私钥应存放在/usr/local/apache/www/certs目录下
[root@localhost ~]# touch /usr/local/apache/logs/ssl_scache //创建ssl的缓存文件
[root@localhost ~]# service httpd restart
//测试apache与openssl结合(只能通过https来进行访问)如图:图1-4-2-8 至 图1-4-2-10
图1-4-2-8
图1-4-2-9
图1-4-2-10
[root@localhost ~]# tar -zxvf dhcp-4.2.5-P1.tar.gz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/dhcp-4.2.5-P1/
[root@localhost dhcp-4.2.5-P1]# ./configure --help
[root@localhost dhcp-4.2.5-P1]# ./configure --prefix=/usr/local/dhcp --sysconfdir=/etc
[root@localhost dhcp-4.2.5-P1]# make && make insatll
//dhclp服务加入开机自动管理,如图:图1-5-1
图1-5-1
[root@localhost dhcp-4.2.5-P1]#cd
[root@localhost ~]# vim /etc/dhcpd.conf //编辑配置文件,如图:图1-5-2 图1-5-3
图1-5-2
图1-5-3
[root@localhost ~]#service dhcpd start //启动dhcp服务