您的位置:首页 > 运维架构 > Linux

centos 下虚拟主机的配置

2010-11-03 22:42 302 查看
Centos5.5下virtual host 的配置

一、系统环境:Centos5.5
二、Lamp架构的搭建
所需软件:freetype-2.4.2.tar.gz libpng-1.4.4.tar.gz php-5.2.14.tar.gz pure-ftpd-1.0.29.tar.gz zlib-1.2.3.tar.gz
gd-2.0.35.tar.gz httpd-2.2.17.tar.gz libxml2-2.7.7.tar.gz phpMyAdmin-3.3.8-all-languages.tar.bz2 ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz gettext-0.18.1.1.tar.gz jpegsrc.v6b.tar.gz mysql-5.0.75.tar.gz pure-ftpd-1.0.26.tar.gz ZendOptimizer-linux-glibc23-i386.tar.gz
1、apache的编译
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar zxvf httpd-2.2.17.tar.gz
[root@localhost src]# cd httpd-2.2.17
[root@localhost httpd-2.2.17]# ./configure --prefix=/usr/local/apache2 --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support --disable-userdir --enable-auth-digest --enable-cgi --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache2/htdocs --enable-ssl --enable-http --enable-rewrite
[root@localhost httpd-2.2.17]#make && make install
[root@localhost httpd-2.2.17]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
2、mysql的编译
[root@localhost src]# tar zxvf mysql-5.0.75.tar.gz
[root@localhost src]# cd mysql-5.0.75
[root@localhost mysql-5.0.75]# ./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --without-debug --with-big-tables --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-slient --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-assembler --without-innodb --without-isam --without-ndb-debug --with-charset=utf8 --with-charset=gbk
[root@localhost mysql-5.0.75]#make && make install
[root@localhost mysql-5.0.75]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.0.75]# vi /etc/my.cnf
[mysqld]
27 port = 3306
28 socket = /tmp/mysql.sock
29 skip-locking
30 key_buffer = 16M
31 max_allowed_packet = 1M
32 table_cache = 64
33 sort_buffer_size = 512K
34 net_buffer_length = 8K
35 read_buffer_size = 256K
36 read_rnd_buffer_size = 512K
37 myisam_sort_buffer_size = 8M
38 user = mysql //38行加入user = mysql
[root@localhost mysql-5.0.75]# cd /usr/local/mysql/bin/
[root@localhost bin]# useradd mysql
[root@localhost bin]# ./mysql_install_db --user=mysql
[root@localhost bin]# ./mysqld_safe --user=mysql &
[root@localhost bin]# cp /usr/local/src/mysql-5.0.75/support-files/mysql.server /etc/init.d/mysqld
[root@localhost bin]# chmod 755 /etc/init.d/mysqld
[root@localhost bin]# /etc/init.d/mysqld restart
[root@localhost bin]# ln -s /usr/local/mysql/bin/* /usr/bin/
[root@localhost bin]# mysqladmin -uroot password 'edwin'
3、php的编译
A、库支持
1.Jpeg6b的编译
[root@localhost bin]# cd /usr/local/src/
[root@localhost src]# tar zxvf jpegsrc.v6b.tar.gz
[root@localhost src]# cd jpeg-6b/
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/lib
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/man
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/include
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/bin
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/man/man1
[root@localhost jpeg-6b]#./configure --prefix=/usr/local/jpeg6 --enable-static --enable-shared
[root@localhost jpeg-6b]# make && make install
2、freetype的编译
[root@localhost freetype-2.4.2]# ./configure --prefix=/usr/local/freetype-2.4.2 --enable-static --enable-shared --with-pic --with-ats
[root@localhost freetype-2.4.2]# make && make install
3、zlib的编译
[root@localhost src]# cd zlib
[root@localhost zlib]# ./configure --prefix=/usr/local/zlib –shared
[root@localhost zlib]# make && make install
[root@localhost zlib]# cd ..
4、libpng的编译
[root@localhost libpng-1.4.4]# ./configure --prefix=/usr/local/libpng-1.4.4 --enable-static --enable-shared --with-pic
[root@localhost libpng-1.4.4]# make && make install
5、libxml的编译
[root@localhost libxml2-2.7.7]# ./configure --prefix=/usr/local/libxml2 --with-zlib=/usr/local/zlib/ --with-modules --with-tree --with-threads --with-ftp --with-history --with-html --with-pic --enable-shared --enable-static
[root@localhost libxml2-2.7.7]# make && make install
6、gettext的编译
[root@localhost src]# cd gettext-0.18.1.1
[root@localhost gettext-0.18.1.1]# ./configure --prefix=/usr/local/gettext --enable-csharp --enable-static --with-pic -enable-shared --with-libxml2-prefix=/usr/local/libxml2/ --with-included-gettext
[root@localhost gettext-0.18.1.1]#make && make install
7、gd库的编译
[root@localhost src]# cd gd-2.0.35
[root@localhost gd-2.0.35]# ./configure --prefix=/usr/local/gd2 --enable-shared --enable-static --with-pic --with-png=/usr/local/libpng-1.4.4/ --with-freetype=/usr/local/freetype2.4.2/ --with-jpeg=/usr/local/jpeg6/ --with-fontconfig --with-xpm
[root@localhost gd-2.0.35]# make && make install
说明:configure.ac:64: error: possibly undefined macro: AM_ICONV
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
make: *** [configure] 错误 1
解决方法:yum install gettext* -y
接着编译 出现错误
make[2]: *** [gd_png.lo] Error 1
make[2]: Leaving directory `/usr/local/file/gd-2.0.26gif'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/file/gd-2.0.26gif'
make: *** [all] Error 2
(如里这里有错误,请vi gd_png.c,找到“png.h”改成“/usr/local/libpng-1.4.4/include/png.h”)
8、php的编译
[root@localhost php-5.2.14]# ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --enable-mod-charset --enable--fastcgi --enable-safe-mode --enable-libgcc --with-libxml-dir=/usr/local/libxml2/ --with-zlib=/usr/local/zlib/ --with-curl --enable-ftp --with-gd=/usr/local/gd2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng-1.4.4/ --with-freetype-dir=/usr/local/freetype-2.4.2/ --enable-mbstring --with-mysql=/usr/local/mysql/ --with-mysql-sock=/tmp/mysql.sock --enable-sockets --enable-static --enable-shared --with-pic --enable-zend-multibyte
[root@localhost php-5.2.14]#make && make install
错误:/bin/sed: can't read /usr/local/jpeg-6b/lib/libjpeg.la: No such file or directory
libtool: link: `/usr/local/jpeg-6b/lib/libjpeg.la' is not a valid libtool archive
make: *** [libphp5.la] 错误 1
最终解决方案 ln –s /usr/local/jpeg6 /usr/local/jpeg-6b
[root@localhost php-5.2.14]# cp php.ini-dist /usr/local/php5/lib/php.ini
[root@localhost php-5.2.14]# vi /usr/local/apache2/conf/httpd.conf
57 LoadModule php5_module modules/libphp5.so
313 AddType application/x-httpd-php .php
169 <IfModule dir_module>
170 DirectoryIndex index.php index.htm index.html
171 </IfModule>
[root@localhost php-5.2.14]#cd /usr/local/apache2/htdosc
[root@localhost php-5.2.14]#vi index.php
<?php
Phpinfo();
?>
[root@localhost php-5.2.14]#vi datalink.php
<?php
$link=mysql_connect(‘localhost’,’test’,’’);
If (!$link) echo ‘faild’;
Else echo ‘success’;
Mysql_close();
?>
现在可以进行访问测试啦
准备工作,默认的httpd是不支持开机自启动的,现在是httpd支持开机自启动
[root@localhost php-5.2.14]#vi /etc/init.d/httpd
#!/bin/sh
#顶部加上以下两句话
# chkconfig: 2345 13 34
# description: lamp httpd server
[root@localhost php-5.2.14]#service httpd restart ;chkconfig –add httpd ; chkconfig httpd on
[root@localhost php-5.2.14]#service mysqld restart ; chkconfig mysqld on
9、ZendOptimizer加速器的安装
[root@localhost src]# cd ZendOptimizer-3.3.3-linux-glibc23-i386
[root@localhost ZendOptimizer-3.3.3-linux-glibc23-i386]# ./install.sh
[root@localhost ZendOptimizer-3.3.3-linux-glibc23-i386]# /etc/init.d/httpd restart
10、下来我们来配置pureftp 及资源限制
[root@localhost src]# cd pure-ftpd-1.0.26
[root@localhost pure-ftpd-1.0.26]#./configure --prefix=/usr/local/pureftpd --with-cookie --with-throttling --with-ratios --with-quotas --with-sysquotas --with-largefile --with-welcomemsg --with-uploadscript --with-virtualhosts --with-virtualroot --with-virtualchroot --with-diraliases --with-peruserlimits --with-language=simplified-chinese --with-mysql=/usr/local/mysql --with-paranoidmsg --with-altlog --with-puredb
第一次的错误:[root@localhost pure-ftpd-1.0.26]# ./configure --prefix=/usr/local/pureftpd --with-mysql=/usr/local/mysql/ --with-cookie --with-quotas --with-virtualhosts --with-virtualchroot --with-uploadscript --with-language=simplified-chinese --with-puredb --with-pam --with-sysquotas --with-extauth --with-tls --with-diraliases --with-throttling --with-ratios --with-nonroot --with-welcomemsg --with-altlog --with-paranoidmsg --with-minimal
注意 :错误configure: error: Your MySQL client libraries aren't properly installed
解决方案:将mysql目录下的 include/mysql下的mysql.h文件以及lib/mysql下的全部文件,连接(直接复制到 /usr/lib 目录下.)
[root@localhost pure-ftpd-1.0.26]#make &&make install
建立配置文件
[root@server pure-ftpd-1.0.21]# mkdir -m 755 /usr/local/pureftpd/etc
[root@server pure-ftpd-1.0.21]# cp pureftpd-mysql.conf /usr/local/pureftpd/etc/
[root@server pure-ftpd-1.0.21]# cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/etc/
[root@server pure-ftpd-1.0.21]# cp configuration-file/pure-config.pl /usr/local/pureftpd/bin/
[root@server pure-ftpd-1.0.21]# chmod u+x /usr/local/pureftpd/bin/pure-config.pl
建立mysql认证数据库表
mysql> create database pureftpd;
Query OK, 1 row affected (0.07 sec)
mysql> grant all on pureftpd.* to pureftpd@localhost identified by 'pureftpd';
Query OK, 0 rows affected (0.01 sec)
mysql> use pureftpd;
Database changed
mysql> CREATE TABLE users (
-> id int(32) unsigned NOT NULL auto_increment,
-> User varchar(16) NOT NULL default '*',
-> Password varchar(64) NOT NULL default '*',
-> Uid varchar(11) NOT NULL default '-1',
-> Gid varchar(11) NOT NULL default '-1',
-> Dir varchar(128) NOT NULL default '-1',
-> QuotaSize smallint(5) NOT NULL default 0,
-> QuotaFiles int(11) NOT NULL default 0,
-> ULBandwidth smallint(5) NOT NULL default 0,
-> DLBandwidth smallint(5) NOT NULL default 0,
-> ULRatio smallint(6) NOT NULL default 0,
-> DLRatio smallint(6) NOT NULL default 0,
comment tinytext NOT NULL,
ipaccess varchar(15) NOT NULL default '*',
status enum('0','1') NOT NULL default '0',
DLRatio smallint(6) NOT NULL default 0,
-> comment tinytext NOT NULL,
-> ipaccess varchar(15) NOT NULL default '*',
-> status enum('0','1') NOT NULL default '0',
-> create_date datetime NOT NULL default '0000-00-00 00:00:00',
-> modify_date datetime NOT NULL default '0000-00-00 00:00:00',
-> PRIMARY KEY (id,User),
-> UNIQUE KEY User (User)
-> ) TYPE=MyISAM AUTO_INCREMENT=5;
Query OK, 0 rows affected, 1 warning (0.07 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
建立用户
INSERT INTO users VALUES (1,'tom', 'qqqqqq', '2000', '2000', ' /usr/local/apache2/htdocs/tom.com/', 0, 0, 0, 0, 0, 0, '*', '*', '1', '2010-9-09 09:20:33', '2011-9-09 09:20:33');
INSERT INTO users VALUES (2,'jack', 'qqqqqq', '2000', '2000', ' /usr/local/apache2/htdocs/jack.com/', 0, 0, 0, 0, 0, 0, '*', '*', '1', '2010-9-09 09:20:33', '2011-9-09 09:20:33');
INSERT INTO users VALUES (3,'leo', 'qqqqqq', '2000', '2000', ' /usr/local/apache2/htdocs/leo.com/', 0, 0, 0, 0, 0, 0, '*', '*', '1', '2010-9-09 09:20:33', '2011-9-09 09:20:33');
[root@localhost ~]# groupadd -g 2000 pureftpd
[root@localhost ~]# useradd -u 2000 -g pureftpd -d /var/pureftp -s /sbin/nologin pureftpd
[root@localhost ~]# mkdir /var/ftp ;chown ftp:ftp /var/ftp
[root@localhost ~]# vi /usr/local/pureftpd/etc/pure-ftpd.conf
MySQLConfigFile /usr/local/pureftpd/etc/pureftpd-mysql.conf
NoChmod yes
IPV4Only yes
DisplayDotFiles no //不显示隐藏文件
CreateHomeDir yes //自动建立家目录
[root@localhost ~]# vi /usr/local/pureftpd/etc/pureftpd-mysql.conf
MYSQLSocket /tmp /mysql.sock
MYSQLUser pureftpd
MYSQLPassword pureftpd
MySQLGetQTAFS SELECT QuotaFiles FROM users WHERE User="/L"
MySQLGetQTASZ SELECT QuotaSize FROM users WHERE User="/L"
启动pureftpd
[root@localhost ~]# /usr/local/pureftpd/bin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
[root@localhost ~]# vi /etc/init.d/pureftpd //创建启动脚本
#!/bin/bash
#
# Startup script for the pure-ftpd FTP Server $Revision: 1.3 $
#
# chkconfig: 2345 85 15
# description: Pure-FTPd is an FTP server daemon based upon Troll-FTPd
# processname: pure-ftpd
# pidfile: /var/run/pure-ftpd.pid
# config: /etc/pure-ftpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
# Path to the pure-ftp binaries.
prog=pure-config.pl
fullpath=/usr/local/pureftpd/bin/$prog
pureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho
start() {
echo -n $"Starting $prog: "
$fullpath /usr/local/pureftpd/etc/pure-ftpd.conf --daemonize
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
echo
}
stop() {
echo -n $"Stopping $prog: "
kill $(cat /var/run/pure-ftpd.pid)
RETVAL=$?
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ] ; then
stop
# avoid race
sleep 3
start
fi
;;
status)
status $prog
RETVAL=$?
if [ -f $pureftpwho ] && [ $RETVAL -eq 0 ] ; then
$pureftpwho
fi
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
[root@localhost ~]# chmod 755 /etc/init.d/pureftpd
11、虚拟主机的配置
[root@localhost htdocs]# vi /usr/local/apache2/conf/httpd.conf
# Virtual hosts
NameVirtualHost 192.168.1.161

#main
<VirtualHost 192.168.1.161>
ServerAdmin admin@admin.com
ServerName server.linux.com
DocumentRoot /usr/local/apache2/htdocs
</VirtualHost>

#tom.com
<VirtualHost 192.168.1.161>
ServerAdmin admin@tom.com
ServerName host.tom.com
DocumentRoot /usr/local/apache2/htdocs/tom.com/htdocs
</VirtualHost>

# leo.com
<VirtualHost 192.168.1.161>
ServerAdmin admin@leo.com
ServerName host.leo.com
DocumentRoot /usr/local/apache2/htdocs/leo.com/htdocs
</VirtualHost>

# jack.com
<VirtualHost 192.168.1.161>
ServerAdmin admin@jack.com
ServerName host.jack.com
DocumentRoot /usr/local/apache2/htdocs/jack.com/htdocs
</VirtualHost>

#test module
<VirtualHost 192.168.1.161>
ServerName host.admin.com
DocumentRoot /usr/local/apache2/htdocs/admin.com/htdocs
ServerAlias admin.com host.admin.com www.admin.com
DirectoryIndex default.htm default.html default.php index.htm index.html index.php
<IfModule bw_mod.c>
BandWidthModule On
BandWidth all 819200
MaxConnection all 800
</IfModule>
<Directory /usr/local/apache2/htdocs/admin.com/htdocs>
AllowOverride Options FileInfo
</Directory>
</VirtualHost>
至此一个完整的虚拟主机环境就搭建成功了,欢迎l大家和我一起测试讨论……
                                                edwin
                                                2010年11.1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: