VHCS install @ CentOS 4.2

VHCS install @ CentOS 4.2 by oicq12659空闲的时间安装VHCS,这个是用来做虚拟主机管理的,和CPANEL相比,VHCS是开源的,阿建用得着。根据VHCS的安装文档重写如下,以方便安装1. 安装OSchoose "server" option during install
firewall: open ssh/http/https/ftp/smtp ports
selinux: disable (warn still generates errors in VHCS)
select minimum install安装类型选“自定义”
手动分区(4G虚拟硬盘)
/ ext3 2000M
swap 2*mem
/var ext3 剩余空间(用户数据在此分区上)
eth0 关闭DHCP,10.10.10.180/255.255.255.0
hostname: srv180.capno.com
gateway: 10.10.10.1
dns: 202.106.0.20/202.106.196.115
Enable firewall,默认的四个服务全允许(SSH/HTTP,HTTPS/FTP/SMTP)
SELinux: Disable
安装包选择:Minimal最小化安装(676M)2. 基本配置
# useradd admin;passwd admin(以下操作凡未说明的都以root身份执行)
使用ssh客户端连接server
# vi /etc/fstab
LABEL=/var              /var                    ext3    defaults,usrquota        1 2
# touch /var/aquota.user;
chmod 600 /var/aquota.user;
mount -o remount /var;
quotacheck -avugm
# server iptables stop;
mv /etc/rc.d/rc3.d/S08iptables /etc/rc.d/rc3.d/K08iptables
# vi /etc/grub.conf timeout=1删除以下无用的软件包(iiimf-server,iiimf-csconv,iiimf-docs,iiimf-libs,xorg-x11-xfs并未安装)
# yum remove apmd autofs bluez-utils cups irda-utils
isdn4k-utils pcmcia-cs sendmail
ypbind xinetd上传需要的软件包VHCS至/home/admin/
包含vhcs安装包,yum安装和升级包(节约yum升级时间),编译好的包(节约编译时间,第一次需要按官方文档自行编译)
# cd /home/admin/VHCS/;
cp -p yum_base/* /var/cache/yum/base/packages/;
cp -p yum_update/* /var/cache/yum/update/packages/# rpm –import http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
# vi /etc/yum.repos.d/CentOS-Base.repo的[base]和[update]项,设置为较快的镜象,如:baseurl=http://mirror.secuidc.com/centos/$releasever/os/$basearch/
baseurl=http://mirror.secuidc.com/centos/$releasever/update/$basearch/# cat <<EOF > /etc/yum.repos.d/dag.repo
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
exclude=proftpd*
EOF# yum install perl-libwww-perl perl-HTML-Parser perl-HTML-Tagset perl-URI
perl-Crypt-Blowfish perl-Crypt-CBC perl-Date-Calc perl-MIME-tools
perl-Convert-BinHex perl-IO-stringy perl-MailTools perl-TimeDate# yum install rpm-build bind# rpm -Uvh cpan2rpm-2.028-1.noarch.rpm# tar vxfz Crypt-PasswdMD5-1.3.tgz; cd Crypt-PasswdMD5-1.3;
perl Makefile.PL; make; make install; cd ..# tar vxfz Term-ReadPassword-0.07.tgz; cd Term-ReadPassword-0.07;
perl Makefile.PL; make; make install; cd ..# rpm –import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-4
# yum install
bison bzip2-devel cyrus-sasl cyrus-sasl-plain
expect fam-devel flex freetype-devel
gcc gcc-c++ gdbm-devel httpd httpd-devel
iptables libc-client-devel libjpeg-devel
libmcrypt libmcrypt-devel libpng-devel libtool
libxslt-devel make mod_ssl
mysql mysql-devel mysql-server
ncurses-devel net-snmp-devel
openssl openssl-devel openssl-perl
pam-devel php php-imap php-gd
php-mysql php-pgsql php-snmp
pkgconfig postgresql-devel zlib-devel
(删掉了mysql-admin这个包,不存在。)
# ln -s /usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE/libperl.so /lib/
# rpm -Uvh proftpd-1.2.10-8_mysql.dag.i386.rpm;
rpm -Uvh postfix-2.2.5-1.mysql.sasl2.vda.rhel4.i386.rpm;
rpm -Uvh courier-authlib-*.rpm;
rpm -Uvh courier-mysql-0*.rpm courier-0*.rpm courier-imapd-0*.rpm courier-pop3d-0*.rpm;
rpm -Uvh php-mcrypt-4.3.9-3.1.1.i386.rpm
# vi /etc/postfix/main.cf
myhostname = srv180.capno.com
# vi /etc/httpd/conf/httpd.conf
ServerName srv180.capno.com:80# chkconfig –add courier;
service courier start;
chkconfig proftpd on;
service proftpd start;
service mysqld start;
service httpd start;
service named start# mysql
mysql> create database vhcs2;use mysql;
mysql> update user set password=password(‘DB_PASSWORD’) where User=’root’;
mysql> flush privileges;# cd /home/admin/VHCS/;
tar -xjpvf vhcs2-2.4.7.1.tar.bz2;
cd vhcs2-2.4.7.1/configs/vhcs2.confSERVER_HOSTNAME = srv180
BASE_SERVER_IP = 10.10.10.180
MR_LOCK_FILE = /var/run/vhcs2.lock
DATABASE_NAME = vhcs2
DATABASE_PASSWORD = ****
BIND_CONF_FILE = /etc/named.conf
BIND_DB_DIR = /var/named/chroot/var/named
APACHE_CMD = /etc/init.d/httpd
APACHE_NAME = httpd
APACHE_LOG_DIR = /var/log/httpd
APACHE_USERS_LOG_DIR = /var/log/httpd/users
APACHE_BACKUP_LOG_DIR = /var/log/httpd/backup
APACHE_CONF_FILE = /etc/httpd/conf.d/vhcs2.conf
APACHE_USER = apache
APACHE_GROUP = apache
MTA_SASLDB_FILE = /etc/sasldb2
CMD_NAMED = /etc/init.d/named
CMD_HTTPD = /etc/init.d/httpd
CMD_AUTHD = /etc/init.d/courier-authlib
CMD_IMAP = /etc/init.d/courier
CMD_POP = /etc/init.d/courier
CMD_VHCS2D = /etc/init.d/vhcs2
MAIL_TRAFF_LOG = maillog# sed -i "s#/usr/lib/postfix#/usr/libexec/postfix#g" /home/admin/VHCS/vhcs2-2.4.7.1/configs/postfix/main.cf
# cd /home/admin/VHCS/vhcs2-2.4.7.1; make install# mkdir /var/named/chroot;
mkdir /var/named/chroot/var;
mkdir /var/named/chroot/var/named;
chown -R named:named /var/named/chroot# cp –reply=yes -R /tmp/vhcs-2.4.7.1/* /;
cp -pR /tmp/vhcs-2.4.7.1/var/mail/* /var/mail/;
cp -pR /tmp/vhcs-2.4.7.1/etc/init.d/vhcs2_* /etc/init.d/;
rmdir /etc/courier/userdb;
touch /etc/courier/userdb;chmod 600 /etc/courier/userdb;
cp -p /etc/courier/userdb /etc/authlib/userdb
makeuserdb# cd /var/www/vhcs2/engine/setup/
# ./vhcs2-setup
hostname: srv180
system network address: 10.10.10.180
SQL server host: localhost
SQL database: vhcs2
SQL user: root
SQL password: *******
VHCS ftp SQL user: vftp
admin name: admin
admin password: *******
admin e-mail: # sed -i "s/nogroup/nobody/" /etc/proftpd.conf
# chmod u+w -R /var/www/vhcs2/gui/tools/webmail/
# cd /etc/vhcs2/bind/parts/
# cp -p cfg_entry.tpl cfg_entry.tpl.bak
# vi cfg_entry.tpl
original line: file "{DB_DIR}/{DMN_NAME}.db";
replacement line: file "{DMN_NAME}.db";
# sed -i "s/0700/0755/" /var/www/vhcs2/engine/vhcs2-*
# touch /etc/sasldb2
(test with /usr/sbin/sasldblistusers2)# vi /etc/init.d/vhcs2 #!/bin/sh
#
# vhcs2           Start or stop the vhcs2 daemon
#
# chkconfig: – 95 5
# processname: vhcs2
# description: Start or stop the vhcs2 daemon
#name=’vhcs2′
lockfile=/var/lock/subsys/vhcs2
confFile=/etc/vhcs2/vhcs2.conf
pidFile=/var/log/vhcs2/vhcs2.pid
daemon=/var/www/vhcs2/daemon/vhcs2_daemon
name=vhcs2_daemoncase "$1" in
    ‘start’)
    $daemon >/dev/null 2>&1 </dev/null
    RETVAL=$?
    if [ "$RETVAL" = "0" ]; then
        touch $lockfile >/dev/null 2>&1
    fi
;;
‘stop’)
pidfile=`grep "^pidfile=" $confFile | sed -e ‘s/pidfile=//g’`
kill `cat $pidfile`
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
    rm -f $lockfile
fi
;;
‘status’)
pidfile=`grep "^pidfile=" $confFile | sed -e ‘s/pidfile=//g’`
if [ "$pidfile" = "" ]; then
    pidfile=$pidFile
fi
if [ -s $pidfile ]; then
    pid=`cat $pidfile`
    kill -0 $pid >/dev/null 2>&1
    if [ "$?" = "0" ]; then
        echo "$name (pid $pid) is running"
        RETVAL=0
    else
        echo "$name is stopped"
        RETVAL=1
    fi
else
    echo "$name is stopped"
    RETVAL=1
fi
;;
‘restart’)
$stop && $start
RETVAL=$?
;;
*)
echo "Usage: $0 { start | stop | restart }"
RETVAL=1
;;
esac
exit $RETVAL# chmod +x /etc/init.d/vhcs2
# chkconfig –add vhcs2# cd /etc/rc.d/rc3.d
# mv S35courier K35courier;
mv S13portmap K13portmap;
mv S14nfslock K14nfslock;
mv S18rpcidmapd K18rpcidmapd;
mv S19rpcgssd K19rpcgssd;
mv S25netfs K25netfs;
mv S40smartd K40smartd;
mv S44acpid K44acpid;
mv S80proftpd K80proftpd;
mv S85gpm K85gpm;
mv S95anacron K95anacron;
mv S95atd K95atd;
mv S97messagebus K97messagebus;
mv S98haldaemon K98haldaemon# service httpd stop;
service mysqld stop;
service proftpd stop;
service courier stop;
service named stop; # service named start;
service courier start;
service proftpd start;
service mysqld start;
service httpd start;
service vhcs2 start访问http://10.10.10.180/vhcs2 admin登录后修改默认语言
Genaral -> Muiltlanguage -> Chinese, Save
修改/etc/php.ini, defaultcharset = "gb2312", 重启httpd

Installing VHCS on CentOS 4.4

I found an installation guide of VHCS on CentOS 4.x in its wiki. It looks a bit complicate but not too bad for me. So I suggested my friend to give it a try. He installed CentOS 4.4 as usual and then I have to install further packages to meet the requirements of VHCS. This is a long, long story. In fact, VHCS doesn’t support CentOS exactly. The only distributions supported by VHCS are just Debian-based and SUSE. That’s why I have to make it work myself.

In order to install VHCS on CentOS 4.4, you have to follow above document until you have all requirements installed but VHCS itself and then follow below procedures.

  1. Edit Makefile by changing HOST_OS to centos

    HOST_OS=centos

  2. Edit configs/Makefile to know about centos

    diff -ruN vhcs2-2.4.7.1.orig/configs/Makefile vhcs2-2.4.7.1/configs/Makefile
    --- vhcs2-2.4.7.1.orig/configs/Makefile 2005-12-31 18:13:02.000000000 +0700
    +++ vhcs2-2.4.7.1/configs/Makefile 2006-09-26 21:40:21.000000000 +0700
    @@ -16,6 +16,8 @@
    cd ./logrotate && $(MAKE) install ; cd .. ;
    elif <a href="http://en.wikipedia.org/wiki/$(HOST_OS)_==_suse" title="reference on $(HOST_OS) == suse" target="_blank">$(HOST_OS) == suse</a> ; then
    cd ./dists/suse && $(MAKE) install ;
    + elif <a href="http://en.wikipedia.org/wiki/$(HOST_OS)_==_centos" title="reference on $(HOST_OS) == centos" target="_blank">$(HOST_OS) == centos</a> ; then
    + cd ./dists/centos && $(MAKE) install ;
    fi

    # elif <a href="http://en.wikipedia.org/wiki/$(HOST_OS)_==_redhat" title="reference on $(HOST_OS) == redhat" target="_blank">$(HOST_OS) == redhat</a> ; then
    @@ -37,6 +39,8 @@
    cd ./logrotate && $(MAKE) uninstall ; cd .. ;
    elif <a href="http://en.wikipedia.org/wiki/$(HOST_OS)_==_suse" title="reference on $(HOST_OS) == suse" target="_blank">$(HOST_OS) == suse</a> ; then
    cd ./dists/suse && $(MAKE) uninstall ;
    + elif <a href="http://en.wikipedia.org/wiki/$(HOST_OS)_==_centos" title="reference on $(HOST_OS) == centos" target="_blank">$(HOST_OS) == centos</a> ; then
    + cd ./dists/centos && $(MAKE) uninstall ;
    fi

    # elif <a href="http://en.wikipedia.org/wiki/$(HOST_OS)_==_redhat" title="reference on $(HOST_OS) == redhat" target="_blank">$(HOST_OS) == redhat</a> ; then

  3. Then copy file from suse to centos as a template.

    cd configs/dists
    cp -Rp suse centos

  4. Edit Makefile and vhcs2.conf in configs/dists/centos

  5. Edit Makefile, httpd.conf, parts/vhcs2_base.tpl and working/vhcs2.conf in configs/dists/centos/apache

  6. Edit main.cf in configs/dists/centos/postfix/main.cf to make sure setgid_group is postdrop

    setgid_group = postdrop

  7. Make sure that all paths in configs are correctly set

  8. Edit vhcs2_daemon in configs/dists/centos/init.d as follow.

    #! /bin/sh
    #
    # skeleton example file to build /etc/init.d/ scripts.
    # This file should be used to construct scripts for /etc/init.d.
    #
    # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
    # Modified for Debian GNU/Linux
    # by Ian Murdock <imurdock@gnu.ai.mit.edu>.
    # Modified for SuSE
    # by Carsten Schoene <cs@linux-administrator.com>
    #
    # Version: @(#)skeleton 1.8 03-Mar-1998 miquels@cistron.nl
    #
    # This file was automatically customized by dh-make on Mon, 22 Apr 2002 16:15:28 +0300
    ### BEGIN INIT INFO
    # Provides: vhcs2_daemon
    # Required-Start: $network $remote_fs
    # Required-Stop: $network $remote_fs
    # Default-Start: 3 5
    # Default-Stop: 0 1 2 6
    # Description: Start the vhcs2_daemon
    ### END INIT INFO

    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/var/www/vhcs2/daemon/vhcs2_daemon
    PID=/var/run/vhcs2-daemon.pid
    NAME=vhcs2_daemon
    DESC=vhcs2_daemon

    test -x $DAEMON || exit 5

    #. /etc/rc.status
    . /etc/rc.d/init.d/functions

    # Shell functions sourced from /etc/rc.status:
    # rc_check check and set local and overall rc status
    # rc_status check and set local and overall rc status
    # rc_status -v ditto but be verbose in local rc status
    # rc_status -v -r ditto and clear the local rc status
    # rc_failed set local and overall rc status to failed
    # rc_reset clear local rc status (overall remains)
    # rc_exit exit appropriate to overall rc status

    # First reset status of this service
    #rc_reset

    case "$1" in
    start)
    echo -n "Starting $DESC: "
    daemon --check $NAME $DAEMON
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
    success
    else
    failure
    fi;
    echo
    /etc/init.d/vhcs2_network
    ;;
    stop)
    echo -n "Stopping $DESC: "
    killproc $NAME
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
    success
    else
    failure
    fi;
    echo
    ;;
    restart|force-reload)
    echo "Restarting $DESC: "
    $0 stop
    $0 start
    ;;
    status)
    echo "Checking for service $DESC: "
    status $DAEMON
    echo
    ;;
    *)
    echo "Usage: $0 {start|stop|restart|force-reload|status}"
    exit 1
    ;;
    esac

    #rc_exit

  9. Then run make install and vhcs2-setup as usual

Then you have to restart all services again.

for i in httpd named courier postfix proftpd vhcs2_daemon; do
chkconfig $i on;
service $i restart;
done

All done.