RHEL5搭建apache服务器全过程(二)DNS服务器及LAMP平台

1、在三台服务器上安装RHEL5操作系统(图形模式),分区规划如下:

/boot                200M
/swap                 4G(根据实际物理内存而定)
/home                 8G
/                    120G(根据实际物理硬盘而定)
 
禁用selinux,只在DNS服务器上启用iptables

分别修改各服务器主机名:

DNS服务器:dns.eyo.com

WebServer1:web1.eyo.com

WebServer2:web2.eyo.com

 

2、 在dns.eyo.com 上搭建DNS 服务器

www.eyo.com对内解析到192.168.0.225,对外解析到公司实际公网IP(依赖DNAT),需要安装的rpm包如下:

Ø bind-9.3.6

Ø bind-chroot-9.3.6

Ø caching-nameserver-9.3.6

Ø bind –utils-9.3.6
 
详细步骤如下:
[root@dns ~]# mount /dev/cdrom /mnt/
[root@dns ~]# cd /mnt/Server/
[root@dns Server]# rpm -ivh bind-9.3.6-4.P1.el5.i386.rpm 
[root@dns Server]# rpm -ivh bind-chroot-9.3.6-4.P1.el5.i386.rpm 
[root@dns Server]# rpm -ivh bind-utils-9.3.6-4.P1.el5.i386.rpm 
[root@dns Server]# rpm -ivh caching-nameserver-9.3.6-4.P1.el5.i386.rpm 

[root@dns Server]# cd /var/named/chroot/etc/
[root@dns etc]# cp -p named.caching-nameserver.conf named.conf
[root@dns etc]# vim named.conf 

options {
        listen-on port 53 { 192.168.0.227; 173.16.16.1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";

        // Those options should be used carefully because they disable port
        // randomization
        // query-source    port 53;    
        // query-source-v6 port 53;

        allow-query     { any; };
        allow-query-cache { localhost; };
};
 

view "LAN" {
        match-clients      { 192.168.0.0/24; };
        zone "eyo.com" IN {
                type master;
                file "eyo.com.zone.lan";
        };
};

view "WAN" {
        match-clients      { any; };
        zone "eyo.com" IN {
                type master;
                file "eyo.com.zone.wan";
        };
};


[root@dns named]# named-checkconf /var/named/chroot/etc/named.conf

[root@dns etc]# cd ../var/named/
[root@dns named]# cp -p named.local eyo.com.zone.lan
[root@dns named]# cp -p named.local eyo.com.zone.wan


[root@dns named]# vim eyo.com.zone.lan

$TTL    86400
@       IN      SOA     ns1.eyo.com. root.eyo.com.  (
                                      2011070801; Serial
                                      4H  ; Refresh
                                      30M ; Retry
                                      12H ; Expire
                                      1D ); Minimum
        IN      NS      ns1.eyo.com.
ns1     IN      A       192.168.0.227
www     IN      A       192.168.0.225
web1    IN      A       192.168.0.223
web2    IN      A       192.168.0.224
 

[root@dns named]# vim eyo.com.zone.wan

$TTL    86400
@       IN      SOA     ns1.eyo.com. root.eyo.com.  (
                                      2011070801; Serial
                                      4H       ; Refresh
                                      30M      ; Retry
                                      12H      ; Expire
                                      1D )     ; Minimum
        IN      NS     ns1.eyo.com.
ns1     IN      A       173.16.16.1
www     IN      A       173.16.16.1
 

[root@dns named]# named-checkzone eyo.com eyo.com.zone.lan
zone eyo.com/IN: loaded serial 2011070801
OK
[root@dns named]# named-checkzone eyo.com eyo.com.zone.wan
zone eyo.com/IN: loaded serial 2011070801
OK
[root@dns named]# service named start
启动 named:                                               [确定]
[root@dns named]# chkconfig named on

 

 

3、 在web1 、web2 服务器上搭建LAMP 平台(暂时不安装awstats和phpMyAdmin

编译安装Apache:

[root@web1 Desktop]# tar zxvf httpd-2.2.9.tar.gz -C /usr/src/

[root@web1 Desktop]# cd /usr/src/httpd-2.2.9/
[root@web1 httpd-2.2.9]# ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/lib --enable-auth-digest --enable-cgi --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache2/htdocs
[root@web1 httpd-2.2.9]# make && make install
[root@web1 httpd-2.2.9]# vim /usr/local/apache2/conf/httpd.conf 
                       97 ServerName web1.eyo.com(修改97行)
[root@web1 httpd-2.2.9]# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.local

Apache服务器不需做太多配置,暂时告一段落

 

编译安装MySQL:

[root@web1 Desktop]# useradd  -M -s /sbin/nologin mysql
[root@web1 Desktop]# tar zxvf mysql-5.0.56.tar.gz -C /usr/src/
[root@web1 Desktop]# cd /usr/src/mysql-5.0.56/
[root@web1 mysql-5.0.56]# ./configure --prefix=/usr/local/mysql
[root@web1 mysql-5.0.56]# make && make install
[root@web1 mysql-5.0.56]# cp support-files/my-medium.cnf /etc/my.cnf
[root@web1 mysql-5.0.56]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@web1 mysql-5.0.56]# chown -R root:mysql /usr/local/mysql/
[root@web1 mysql-5.0.56]# chown -R mysql /usr/local/mysql/var/
[root@web1 mysql-5.0.56]# echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
[root@web1 mysql-5.0.56]# ldconfig
[root@web1 mysql-5.0.56]# /usr/local/mysql/bin/mysqld_safe --user=mysql &

[1] 14639
   Starting mysqld daemon with databases from /usr/local/mysql/var

[root@web1 mysql-5.0.56]# netstat -tunpl | grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      14665/mysqld   

[root@web1 mysql-5.0.56]# cp support-files/mysql.server /etc/init.d/mysqld
[root@web1 mysql-5.0.56]# chmod +x /etc/init.d/mysqld
[root@web1 mysql-5.0.56]# chkconfig --add mysqld
[root@web1 mysql-5.0.56]# chkconfig mysqld on
 

[root@web1 mysql-5.0.56]# export PATH=$PATH:/usr/local/mysql/bin
[root@web1 mysql-5.0.56]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@web1 ~]# mysqladmin -u root password "redhat"

 

构建PHP环境:

[root@web1 Desktop]# tar zxvf php-5.2.6.tar.gz -C /usr/src/
[root@web1 Desktop]# cd /usr/src/php-5.2.6/
[root@web1 php-5.2.6]# ./configure --prefix=/usr/local/php5 --enable-mbstring --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5
[root@web1 php-5.2.6]# make && make install
[root@web1 php-5.2.6]# cp php.ini-dist /usr/local/php5/php.ini


[root@web1 php-5.2.6]# vim /usr/local/apache2/conf/httpd.conf

 53      LoadModule php5_module        modules/libphp5.so
166    <IfModule dir_module>
167        DirectoryIndex index.php index.html
168     </IfModule>
308     AddType application/x-compress .Z
309     AddType application/x-gzip .gz .tgz
310     AddType application/x-httpd-php .php
 

[root@web1 php-5.2.6]# /usr/local/apache2/bin/apachectl restart

 

测试PHP运行环境:
[root@web1 ~]# vim /usr/local/apache2/htdocs/test.php
<?php
phpinfo( );
?>
 

在浏览器中访问http://192.168.0.223/test.php进行测试,将出现如下界面:

 

[root@web1 ~]# vim /usr/local/apache2/htdocs/testdb.php
?php
$link=mysql_connect('localhost','test','');
if (! $link) echo "Fail";
else echo "Success";
mysql_close();
?>


在浏览器中访问http://192.168.0.223/testdb.php进行测试,将出现Success,如图:

 注意:以上LAMP平台的步骤必须在web2上也进行一次!

 

 

你可能感兴趣的:(apache,linux,lamp,heartbeat,rhel5)