PowerBSD(三轮车夫)
前言:
本文着重描述CNFUG服务器具体的配置过程,其中包括了Apache,MySQL,Php,Qmail,Qmailadmin,vpopmail等……
这算是一个完整的服务器的配置过程了!希望大家看了这篇文档能够有所启发,能够更加灵活的运用FreeBSD构建
更强大的服务!
系统环境:
FreeBSD 4.8 Stable(具体如何将系统升级到Stable我就不多说了,请参考FreeBSD的Handbook)
Qmail安装路径/usr/local/qmail/
Vpopmail安装路径/home/vpopmail/
Apache安装路径/server/httpd/
Forum路径/www/cnfug/forum/htdocs/
Mail主页路径/www/cnfug/mail/htdocs/
Mail-cgi-bin路径/www/cnfug/mail/cgi-bin/
MySQL安装路径/server/mysql/
php安装路径/server/php/
源码存放路径/source/src/
源码编译路径/source/build/
安装MySQL
添加MySQL相应的用户和组
#pw groupadd mysql -g 3306
#pw useradd mysql -u 3306 -c "MySQL Daemon" -d /server/mysql -g 3306 -s /nonexitent
#tar zxvf mysql-4.0.13.tar.gz -C /server/build
#cd /server/build/mysql-4.0.13/
#./configure --prefix=/server/mysql --with-mysqld-ldflag=all-static --with--charset=gbk --with-low-memory --enable-assembler --disable-shared --without-docs
#make
#make install
#scripts/mysql_install_db (安装数据库)
#cp support-files/my-medium.cnf /etc/my.cnf
#vi /etc/my.cnf 添加user=mysql
如果你想让你的数据库独立出来,可以指定数据库的路径
在/etc/my.cnf中添加 datadir=/www/MySQL/data
cp /server/mysql/lib/mysql/libmysqlclient* /usr/lib/
//这一步非常重要,不然在后面使用vpopmail添加domain时候会报错
//安全设置:修改权限
#chown -R mysql:mysql /server/mysql
#chmod -R go-xwr /server/mysql
#/server/mysql/bin/mysqld_safe &
#/server/mysql/bin/mysqladmin -u root password 'newpassword' //修改MySQL的root密码!重要!
#/server/mysql/bin/mysql -u root -p 输入你的密码!你现在就应该可以用MySQL了!
添加MySQL用户:
mysql>use mysql;
//建立vpopmail和ezmlm需要的用户和相应的数据库
mysql>grant select,insert,update,delete,create,drop on vpopmail.* to vpopmail@localhost identified by '12345678';
mysql>grant select,insert,update,delete,create,drop on ezmlm.* to ezmlm@localhost identified by '12345678';
mysql>create database vpopmail;
mysql>create database ezmlm;
mysql>show status;
mysql>status;
mysql>show databases;
安装Apache
添加Apache相关的用户和组(默认FreeBSD已经建立了该用户,如果没有请添加)
#pw groupadd www -g 80
#pw useradd www -u 80 -c "World Wide Web Owner" -d /server/httpd -g 80 -s /nonexitent
如果有,请做如下修改
#pw usermod www -d /server/httpd -s /nonexitent
#tar zxvf httpd-2.0.47.tar.gz -C /source/build
#cd /source/build/httpd-2.0.47/
#./configure --prefix=/server/httpd --enable-mods-shared=all --enable-module=so --enable-ssl=shared --disable-status --disable-userdir --enable-suexec=shared
#make
#make install
#chown -R www:www /server/httpd
#/server/httpd/bin/apachectl start
安装PHP
#tar jxvf php-4.3.2.tar.bz2 -C /source/build/
#cd /source/build/php-4.3.2/
#./configure --prefix=/server/php --enable-track-vars --with-mysql=/server/mysql --with-apxs2=/server/httpd/bin/apxs --with-gd=/usr/server/gd(可选)
#make
#make install
#cp php.ini-recommended /server/php/lib/php.ini
在/server/httpd/conf/httpd.conf中添加如下脚本
LoadModule php4_module modules/libphp4.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps(这一行可以不添加)
安装Qmail
//建立安装目录
mkdir -p /usr/local/qmail/alias
//建立相关的用户和组
#pw groupadd nofiles
#pw useradd alias -g nofiles -m -d /usr/local/qmail/alias -s /nonexistent
#pw useradd qmaild -g nofiles -d /usr/local/qmail -s /nonexistent
#pw useradd qmaill -g nofiles -d /usr/local/qmail -s /nonexistent
#pw useradd qmailp -g nofiles -d /usr/local/qmail -s /nonexistent
#pw groupadd qmail
#pw useradd qmailq -g qmail -d /usr/local/qmail -s /nonexistent
#pw useradd qmailr -g qmail -d /usr/local/qmail -s /nonexistent
#pw useradd qmails -g qmail -d /usr/local/qmail -s /nonexistent
查看建好的用户和组
#pw user show -a
#pw group show -a
安装Qmail
#tar zxvf qmail-1.03.tar.gz
//对Qmail打补丁
#patch -p0 < qmail-103.patch
#tar zxvf qmail-smtpd-auth-0.30.tar.gz
#cd qmail-smtpd-auth-0.30
#cp base* README.auth ../qmail-1.03
#patch -d ../qmail-1.03 < auth.patch
编辑conf-qmail修改其中的路径为/usr/local/qmail这样qmail就安装到/usr/local/qmail目录下!默认是在/var/qmail目录下!
//执行make检查
#make setup check
./config-fast cnfug.org
//修正SMTP认证信息人员输入和任意更改电子邮件发信人地址的补丁
#cp qmail-smtpd.c qmail-1.03/
#patch < qmail-smtpd.patch.txt
#make qmail-smtpd
#cp qmail-smtpd /usr/local/qmail/bin/qmail-smtpd
//建立邮件帐号的别名
#cd /usr/local/qmail/alias
#touch .qmail-postmaster .qmail-mailer-daemon .qmail-root
#chmod 644 /usr/local/qmail/alias/.qmail*
//建立Qmail启动文件
#cp /usr/local/qmail/boot/home /usr/local/qmail/rc
#perl -i -pe 's/Mailbox/Maildir/' /usr/local/qmail/rc
#perl -i -pe 's/sendmail_enable="YES"/sendmail_enable="NONE"/' /etc/rc.conf
#perl -i -pe 's/sendmail_submit_enable="YES"/sendmail_submit_enable="NO"/' /etc/defaults/rc.conf
#perl -i -pe 's/sendmail_outbound_enable="YES"/sendmail_outbound_enable="NO"/' /etc/defaults/rc.conf
#perl -i -pe 's/sendmail_msp_queue_enable="YES"/sendmail_msp_queue_enable="NO"/' /etc/defaults/rc.conf
#mv /usr/lib/sendmail /usr/lib/sendmail.bak(在FreeBSD下该命令不需要)
#mv /usr/sbin/sendmail /usr/sbin/sendmail.bak
#chmod u+x /usr/local/qmail/bin/sendmail
#ln -s /usr/local/qmail/bin/sendmail /usr/lib/sendmail(在FreeBSD下该命令不需要)
#ln -s /usr/local/qmail/bin/sendmail /usr/sbin/sendmail
#mkdir -p /etc/qmail
#echo "csh -cf '/usr/local/qmail/rc &'">>/etc/qmail/start
#echo "/etc/qmail/smtp.sh">>/etc/qmail/start
安装ucspi-tcp
tar zxvf ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
修改conf-home为/usr/local/qmail(安装到路径/usr/local/qmail/bin/目录下)
#vi conf-home
make
make setup check
//生成tcp.smtp.cdb
echo "127.0.0.1:allow,RELAYCLIENT="\"\" > /etc/qmail/tcp.smtp
/usr/local/qmail/bin/tcprules /etc/qmail/tcp.smtp.cdb /etc/qmail/tcp.smtp.tmp < /etc/qmail/tcp.smtp
检查qmaild的uid和gid
pw user show qmaild
qmaild:*:3308:3307::0:0:User &:/usr/local/qmail:/nonexistent
它的uid是3308,gid是3307
#echo "/usr/local/qmail/bin/tcpserver -H -R -l cnfug.org -t 1 -c 100 -v -p -x /etc/qmail/tcp.smtp.cdb -u 3308 -g 3307 0 smtp /usr/local/qmail/bin/qmail-smtpd /home/vpopmail/bin/vchkpw /usr/bin/true /usr/local/qmail/bin/cmd5checkpw /usr/bin/true 2>&1 | /usr/local/qmail/bin/splogger &">/etc/qmail/smtp.sh
#chmod 755 /etc/qmail/smtp.sh
cmd5checkpw的安装
make
cp cmd5checkpw /usr/local/qmail/bin/
vpopmail的安装
在MySQL中添加vpopmail的用户!
/server/mysql/bin/mysql -u root -p
mysql> grant select,insert,update,delete,create,drop on vpopmail.* to vpopmail@localhost identified by '12345678';
#mkdir -p /home/vpopmail/etc
#pw groupadd vchkpw -g 89
#pw useradd vpopmail -u 89 -g 89 -d /home/vpopmail -s /nonexistent
#echo "/etc/qmail/start">>/etc/rc.conf
vi vmysql.h 修改一下内容
#define MYSQL_UPDATE_SERVER "localhost" (mysql服务器名)
#define MYSQL_UPDATE_USER "vpopmail" (用户名)
#define MYSQL_UPDATE_PASSWD "12345678" (改成你设置的密码)
#define MYSQL_READ_SERVER "localhost" (mysql服务器名)
#define MYSQL_READ_USER "vpopmail" (用户名)
#define MYSQL_READ_PASSWD "12345678" (改成你设置的密码)
#./configure --prefix=/home/vpopmail --enable-mysql=y --enable-incdir=/server/mysql/include/mysql --enable-libdir=/server/mysql/lib/mysql --enable-libs=/server/mysql/lib/mysql --enable-default-domain=cnfug.org --enable-passwd=n --enable-defaultquota=52428800s --enable-tcprules-prog=/usr/local/qmail/bin/tcprules --enable-tcpserver-file=/etc/qmail/tcp.smtp --enable-vpopuser=vpopmail --enable-vpopgroup=vchkpw --enable-ip-alias-domains=n --enable-roaming-users=y --enable-sqwebmail-pass=y --enable-qmaildir=/usr/local/qmail
#make
#make install-strip
#chmod +s /home/vpopmail/bin/vchkpw
#cd /home/vpopmai/bin/
#./vadddomain cnfug.org(添加一个cnfug.org的域,按提示输入postmaster的密码!)
#./vdeldomain cnfug.org(将cnfug.org域删除!目的是为了修改vpopmail的数据表的结构)
mysql>use vpopmail;
mysql>drop tables vpopmail;
在mysql中建立数据库vpopmail在数据库中建立如下表:
mysql>
create table vpopmail (
pw_id int(5) unsigned NOT NULL auto_increment,
pw_name varchar(32) NOT NULL default '',
pw_domain varchar(64) NOT NULL default '',
pw_passwd varchar(40) NOT NULL default '',
pw_uid int(11) default NULL,
pw_gid int(11) default NULL,
pw_gecos varchar(64) default NULL,
pw_dir varchar(160) default NULL,
pw_shell varchar(20) default NULL,
pw_clear_passwd varchar(16) default NULL,
PRIMARY KEY (pw_id),
KEY pw_name (pw_name,pw_domain)
) TYPE=MyISAM;
再次通过/home/vpopmail/bin/vadddomain cnfug.org建立cnfug.org的域
#echo "/usr/local/qmail/bin/tcpserver -c 100 -v -l cnfug.org -U -H -R 0 pop3 /usr/local/qmail/bin/qmail-popup cnfug.org /home/vpopmail/bin/vchkpw /usr/local/qmail/bin/qmail-pop3d Maildir 2>&1 | /usr/local/qmail/bin/splogger &">/etc/qmail/pop.sh
#chmod 755 /etc/qmail/pop.sh
安装ezmlm-0.53
在MySQL建立相关的用户和表
mysql> use mysql
Database changed
mysql> create database ezmlm;
mysql> grant select,insert,update,delete,create,drop on ezmlm.* to ezmlm@localhost identified by '12345678';
解压ezmlm
#tar zxvf ezmlm-0.53.tar.gz
#tar zxvf ezmlm-idx.0.40.tar.gz
#cp -Rp ezmlm-idx.0.40/* ezmlm-0.53/
#cd ezmlm-0.53
#patch < idx.patch
修改conf-bin文件中的路径为/usr/local/qmail/bin/ezmlm
修改conf-man文件中的路径为/usr/share/man
修改conf-qmail文件中的路径为/usr/local/qmail
#cd sub_mysql
编辑sub_sqlcc修改mysql的路径为/server/mysql/include/mysql
编辑sub_sqlld修改为-L/server/mysql/lib/mysql -lmysqlclient -lm -lz
开始编译
#make mysql #MySQL的支持
#make clean
#make
#make man
#make ch_GB #中文支持
#make setup
修改/usr/local/qmail/bin/ezmlm/ezmlmrc将"To:##L@##H"修改为"To:<#L#>@<#H#>"
对邮件列表字符集的修改,在/home/vpopmail/domains/xxx/questions/下建立一个charset的文件!~
#touch charset
#chown vpopmail:vchkpw charset
#chmod go-r charset
#vi charset 添加一行gb2312
这样你发一份邮件到questions-help@xxx.xxx 你收到的信息将可以正确的显示中文了!
在你建立一个基于MySQL的maillist之前,你必须保证ezmlm库中已存在一个对应的表:
Ex:你想建一个基于MySQL的maillist:questions
/usr/local/qmail/bin/ezmlm/ezmlm-mktab -d questions | /server/mysql/bin/mysql -uezmlm -p12345678 -f ezmlm
这样就在ezmlm库中为questions建立了一系列相关表格:
mysql> use ezmlm
Database changed
mysql> show tables;
+-------------------------+
| Tables_in_ezmlm |
+-------------------------+
| questions |
| questions_allow |
| questions_allow_slog |
| questions_cookie |
| questions_deny |
| questions_deny_slog |
| questions_digest |
| questions_digest_cookie |
| questions_digest_mlog |
| questions_digest_slog |
| questions_mlog |
| questions_mod |
| questions_mod_slog |
| questions_slog |
+-------------------------+
在后面将通过QmailAdmin进行邮件列表的管理
安装autorespond
2.11安装autorespond
(对于qmailadmin-0.74版以上,必须使用2.0以上的版本)
# tar zxvf autorespond-2.0.0.tar.gz
# cd autorespond-2.0.0
# make
# make install
# cp autorespond /usr/local/bin
#gcc -Wall -o autorespond autorespond.c
#cp autorepond /usr/local/qmail/bin/autorespond
安装Qmailadmin
./configure --enable-vpopmaildir=/home/vpopmail --enable-htmldir=/www/cnfug/mail/htdocs --enable-cgibindir=/www/cnfug/mail/cgi-bin --enable-imagedir=/www/cnfug/mail/htdocs/images/qmailadmin --enable-imageurl=/images/qmailadmin --with-htmllibdir=/www/cnfug/mail/htdocs --enable-qmaildir=/usr/local/qmail --enable-cgipath=/cgi-bin/qmailadmin --enable-autoresponder-bin=/usr/local/qmail/bin --enable-ezmlmdir=/usr/local/qmail/bin/ezmlm --enable-modify-quota=yes
make
make install-strip
chgrp qmail /usr/local/qmail
在/home/vpopmail/domains/xxx.com下面建立一个.qmailadmin-limits文件(这个文件本身没有)
在里面写
maxpopaccounts 100
default_quota 10485760
这样用qmailadmin添加账号的最大数目就是100,每个邮箱的配额就是10485760,10M。。
变量: 数值型. maxaliases,maxforwards,maxautoresponder,maxmailinglists
变量:bool型
disable_pop,disable_imap,disable_dialup,disable_password_changing,disable_webmail,disable_external_relay
以上的变量只要在文件中存在就起作用,不用设值。
../configure --prefix=/home/vpopmail --enable-default-domain=powerbsd.org --enable-passwd=n --enable-ip-alias-dmains=n --enable-defaultquota=52428800s --enable-sqwebmail-pass=y --enable-mysql=y --enable-incdir=/usr/server/mysql/include/mysql --enable-libdir=/usr/server/mysql/lib/mysql --enable-libs=/usr/server/mysql/lib/mysql --enable-tcprules-prog=/usr/server/qmail/bin/tcprules --enable-vpopuser=vpopmail --enable-vpopgroup=vchkpw --enable-qmaildir=/usr/server/qmail
make configure-check
make
make check
make install-strip
make install-configure
make
make install-strip
chmod 6755 /home/vpopmail/bin/vchkpw
安装sqwebmail
./configure --prefix=/usr/local/qmail/webmail --with-unicode=gb2312 --with-authvchkpw --enable-webpass=vpopmail --enable-cgibindir=/www/cnfug/mail/cgi-bin/ --enable-imagedir=/www/cnfug/mail/htdocs/webmail --enable-mimetypes=/www/cnfug/mail/htdocs/ --disable-utf7-folder-encoding --enable-mimecharset=gb2312 --enable-default-domain=cnfug.org
./configure --prefix=/usr/local/qmail/webmail --enable-unicode=gb2312 --with-authvchkpw --enable-cgibindir=/www/cnfug/mail/cgi-bin/ --enable-imagedir=/www/cnfug/mail/images/webmail --with-cachedir=/var/cache/webmail --enable-imageurl=/images/webmail --enable-mimetypes=/server/httpd/conf/ --disable-utf7-folder-encoding --enable-mimecharset=gb2312 --enable-default-domain=cnfug.org
#make configure-check
#make
#make install-strip
#make install-configure
/usr/local/qmail/webmail/libexec/authlib/authdaemond start
#cp /usr/local/qmail/webmail/authdaemonrc.dist /usr/local/qmail/webmail/authdaemonrc
/usr/local/qmail/webmail/libexec/authlib/authdaemond start