ubuntu hardy下简易的proftpd+mysql配置

Posted on 七月 9th, 2008 in Linux | No Comments »

1. 安装

sudo aptitude install proftpd proftpd-mysql

2. 配置
/etc/proftpd/proftpd.conf

Include /etc/proftpd/sql.conf

前面的注释去掉
然后修改/etc/proftpd/sql.conf,我的相关配置如下:

SQLBackend mysql
SQLEngine on
SQLAuthenticate on
SQLAuthTypes Plaintext Crypt
SQLConnectInfo ftp@localhost proftp abcde
SQLUserInfo ftpuser userid passwd uid gid homedir shell
SQLGroupInfo ftpgroup groupname gid members

3. 创建mysql库
此处请参照Virtual Hosting With Proftpd And MySQL (Incl. Quota) On Ubuntu 8.04 LTS

4. restart proftpd

sudo /etc/init.d/proftpd restart

设置proftpd+mysql的虚拟FTP服务

Posted on 十二月 15th, 2007 in Linux | No Comments »

具体设置参考:http://www.howtoforge.com/proftpd_mysql_virtual_hosting

按照上面的设置完成后,还需要的操作:
1、允许恢复上传
在proftpd.conf里添加一行:

AllowStoreRestart on

2、权限控制
比如,控制只读,可以在文件权限上设置,把写权限去掉,也可以在FTP权限里进行控制。
在FTP里进行权限控制,在相应目录下创建一个.ftpaccess文件,里面内容为:

<limit STOR>DENYALL</limit>

而专门供上传的目录,需要控制为不可删除:

<limit DELE>DENYALL</limit>

mysql又出问题了

Posted on 十二月 1st, 2007 in Linux | 1 Comment »

已经被MYSQL的问题烦恼了很长的时间了,而且一直没有搞清楚问题的原因。
原来已经调整了参数,并且设置了MYSQL每天自动重新启动一次,没想到还是有问题。
最近又出现了too many connections的问题,干脆再次调整参数,从500直接调整到1500了,

2.4 Too many connections错误
如果在你试土连接MySQL时,你得到错误Too many connections,这意味着已经有max_connections个客户连接了mysqld服务器。

如果你需要比缺省(100)更多的连接,那么你应该重启mysqld,用更大的 max_connections 变量值。

注意,mysqld实际上允许(max_connections+1)个客户连接。最后一个连接是为一个用Process权限的用户保留的。通过不把这个权限给一般用户(他们不应该需要它),有这个权限一个管理员可以登录并且使用SHOW PROCESSLIST找出什么可能出错。见7.21 SHOW句法(得到表,列的信息)。

几个相关命令:
mysqladmin version
mysqladmin variable
show processlist
完整信息可以参考:http://phpchina.com/bbs/archiver/tid-3817.html

wordpress mu 1.3中的编码问题

Posted on 十一月 3rd, 2007 in Blog | No Comments »

发现wordpress mu 升级到1.3版本了,对应到wordpress 2.3系列。其中,显著的功能就是默认的TAG支持了。但是升级后发现中文乱码,这时因为我的mysql数据库目前默认的编码还是latin1,而wordpress mu目前默认的编码是采用utf8了,因此需要进行修改。

有两种办法处理:
1、修改wordpress mu的代码
找到wp-inlcudes/wp-db.php文件,注释掉这两行:

// if ( !empty($this->charset) && version_compare(mysql_get_server_info(), '4.1.0', '>=') )
// $this->query("SET NAMES '$this->charset'");

2、修改数据库编码,使其和你的wordpress编码相对应
比如,可以修改数据库的编码为utf8。
首先导出:

mysqldump --default-character-set=latin1 -uroot yourdb > yourdb.sql

然后修改此文件,替换所有的latin1为utf8,并在文件头添加:

SET NAMES utf8;
SET CHARACTER_SET_CLIENT=utf8;
SET CHARACTER_SET_RESULTS=utf8;

然后保存为yourdb-utf.sql,在进行数据库的导入工作:

mysql -uroot
mysql>drop database yourdb
mysql >create database yourdb
mysql -uroot yourdb<yourdb-utf.sql

此处的转换方法参考:转换论坛:webwiz 7.9 -> phpBB3

我为了以后升级的方便,选择了第二种方法进行处理。

检测mysql进程并重启服务

Posted on 九月 22nd, 2007 in Linux | No Comments »

服务器上的mysql老是拖累apache,导致WWW服务不正常,前面修改过对应的mysql参数,但还是不行,因此,就决定设定让系统CRON下面这个脚本,注意脚本来自傅翮鹤 ,我仅仅修改了ubuntu下对应的参数而已。

#!/bin/bash
#check apache,mysql thread and auto reboot service
#Powered by 傅翮鹤 [www.fuhehe.com]
#Date 2007-06-15

#config
MaxApacheThread=100
MaxMysqlThread=50
HttpService=`ls /etc/init.d|grep apache2`
MysqlService=`ls /etc/init.d|grep mysql`

ApacheThread=`ps -A|grep apache2|wc -l`
MysqlThread=`ps -A|grep mysql|wc -l`

NeedReboot=0

if [ $ApacheThread -gt $MaxApacheThread ]
then
NeedReboot=1
fi
if [ $ApacheThread -eq 0 ]
then
NeedReboot=2
fi

if [ $MysqlThread -gt $MaxMysqlThread ]
then
NeedReboot=3
fi
if [ $MysqlThread -eq 0 ]
then
NeedReboot=4
fi

if [ $NeedReboot -eq 1 ]
then
echo "-----------------------------"
echo $(date +"%y-%m-%d %H:%M:%S")
echo "-----------------------------"
echo "Apache:$ApacheThread;Mysql:$MysqlThread."
echo "Apache is busy,reboot"
/etc/init.d/$HttpService stop
/etc/init.d/$HttpService start
elif [ $NeedReboot -eq 2 ]
then
echo "-----------------------------"
echo $(date +"%y-%m-%d %H:%M:%S")
echo "-----------------------------"
echo "Apache:$ApacheThread;Mysql:$MysqlThread."
echo "Apache is down,reboot"
/etc/init.d/$HttpService start
elif [ $NeedReboot -eq 3 ]
then
echo "-----------------------------"
echo $(date +"%y-%m-%d %H:%M:%S")
echo "-----------------------------"
echo "Apache:$ApacheThread;Mysql:$MysqlThread."
echo "Mysql is busy,reboot"
/etc/init.d/$MysqlService stop
/etc/init.d/$MysqlService start
elif [ $NeedReboot -eq 4 ]
then
echo "-----------------------------"
echo $(date +"%y-%m-%d %H:%M:%S")
echo "-----------------------------"
echo "Apache:$ApacheThread;Mysql:$MysqlThread."
echo "Mysql is down,reboot"
/etc/init.d/$MysqlService start
else
echo "-----------------------------"
echo $(date +"%y-%m-%d %H:%M:%S")
echo "-----------------------------"
echo "Apache:$ApacheThread;Mysql:$MysqlThread."
echo "System is normal"
fi

整合phpbb3和svn服务

Posted on 九月 2nd, 2007 in Linux, phpbb, westdc | 1 Comment »

整合,题目有点大,呵呵。
其实就是把SVN的用户控制交给phpbb3来进行处理。
要求SVN必须采用apache2/mod_auth_mysql来进行控制的。
然后在phpbb3的后台创建一个新的用户组,用于控制可以访问SVN服务的用户。然后在mysql里创建一个视图,提取用户名称和密码。注意,PHPBB3采用的加密方式是直接MD5。假设创建的组名为svn:

create view svnauth (username,passwd,groups) as select users.username,users.user_password,groups.group_name from groups,user_group left join users on user_group.user_id=users.user_id where groups.group_name="svn" and user_group.group_id=groups.group_id ;

然后在apache2的site文件里设置为:

Auth_MySQL_Encryption_Types PHP_MD5

这样就可以了,具体的操作还需要参考之前的文章:安装subversion: ssl+auth_mysql+mod_svn

估计还需要mysql 5的支持,不知道mysql 4是否支持视图。

apache2下使用mysql进行身份认证

Posted on 八月 14th, 2007 in Linux | 1 Comment »

服务器平台为ubuntu feisty,首先确认apache2已经安装好。
然后安装auth-mysql支持并启用此模块:

sudo aptitude install libapache2-mod-auth-mysql
sudo a2enmod auth_mysql

要建立一个数据库用于认证,并建立一个用户表存贮用户信息。

mysql -uroot
create database svn;
grant all on svn.* to svn@localhost identified by 'mypwd';
flush privileges;
use svn;
create table auth(
`username` varchar(25) NOT NULL default '',
`passwd` varchar(25) NOT NULL default '',
`groups` varchar(25) NOT NULL default '',
PRIMARY KEY (`username`),
KEY `groups` (`groups`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

然后修改site文件:

Auth_MySQL_Info localhost <auth_user> <password>

<Directory "<web directory>">
Options +Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig Options FileInfo Limit
Order allow,deny
Allow from all
</Directory>

创建.htaccess文件:

AuthUserFile /dev/null
AuthBasicAuthoritative off
AuthMYSQL on
AuthMySQL_Authoritative on
AuthMySQL_DB svn
AuthMySQL_Password_Table auth
AuthMySQL_Group_Table auth
AuthMySQL_Empty_Passwords off
AuthMySQL_Encryption_Types Plaintext Crypt_DES
AuthName "<description>"
AuthType Basic

<Limit GET POST>
require valid-user
#or
require group group group1
</Limit>

注意问题:
注意这个部分AuthUserFile /dev/null
如果没有这行,apache的error_log中会出现这样的错误:

[error] [client ip] (9)Bad file descriptor: Could not open password file: (null)

如果没有AuthBasicAuthoritative off
会出现错误:

[error] [client ip] user yourusername not found:

参考:

http://www.howtoforge.com/mod_auth_mysql_apache2_debian

http://www.linuxmine.com/79991.html

mysql: Too many connections

Posted on 七月 29th, 2007 in Linux | 2 Comments »

最近,服务器上经常出现MYSQL占用CPU100%的情况,导致和mysql有关的应用都死翘翘,估计和论坛有关系。
首先,修改了/etc/mysql/my.cnf,增大了并发数,把max_connections从100增大到500。
然后限制了论坛上的搜索设定,设定词频为40%,原来为90%。
还希望能限制搜索引擎的拜访次数,不过没有在phpbb3的后台里找到。

参考:

http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html

转移邮件服务器:postfix

Posted on 七月 3rd, 2007 in Linux | 8 Comments »

原邮件服务器硬盘损害,已经无法工作,需要转移到新服务器上。
原来的服务器是debian etch,新服务器是ubuntu feisty。

首先安装:
sudo aptitude install postfix postfix-mysql courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl postfix-tls libsasl2 libsasl2-modules libsasl2-modules-sql sasl2-bin openssl libpam-mysql amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 unzoo libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzop pax razor pyzor dcc-client

首先创建mysql数据库,因为原来已经创建,直接导入就可以了。
把原来的mysql-virtual*文件拷贝到/etc/postfix/目录下,注意若mysql用户密码发生变化,要进行相应的修改。
然后修改文件权限:

chmod o= /etc/postfix/mysql-virtual_*.cf
chgrp postfix /etc/postfix/mysql-virtual_*.cf

创建vmail用户:

groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /home/vmail -m

对/etc/postfix/main.cf进行修改定制:

postconf -e 'myhostname = server1.example.com'
postconf -e 'mydestination = server1.example.com, localhost, localhost.localdomain'
postconf -e 'mynetworks = 127.0.0.0/8'
postconf -e 'virtual_alias_domains ='
postconf -e ' virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf'
postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'
postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'
postconf -e 'virtual_mailbox_base = /home/vmail'
postconf -e 'virtual_uid_maps = static:5000'
postconf -e 'virtual_gid_maps = static:5000'
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'
postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'
postconf -e 'content_filter = amavis:[127.0.0.1]:10024'
postconf -e 'receive_override_options = no_address_mappings'

这部分需要具体检查,我把myorigin这个给注释掉了,对于多域名的邮件列表有影响。

saslauthd相关设置,和DEBIAN不大一样,和UBUNTU EDGY也不尽相同:

sudo rm -fdr /var/spool/postfix/var/run/saslauthd
sudo mv /var/run/saslauthd /var/spool/postfix/var/run/saslauthd
sudo ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd
sudo adduser postfix sasl

修改/etc/default/saslauthd文件,把START修改为yes。
修改/etc/pam.d/smtp文件:

auth required pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1

account sufficient pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1

对应的用户名密码数据库要进行替换。

修改/etc/courier/authdaemonrc文件,把authmodulelist的值变为"authmysql"。

修改/etc/init.d/postfix文件,在FILES部分:

FILES=”etc/localtime etc/services etc/resolv.conf etc/hosts \
etc/nsswitch.conf etc/nss_mdns.config etc/postfix/sasl/smtpd.conf etc/sasldb2″

这个原来是有sasldb2文件的,但是在ubuntu feisty下没有这个文件,但执行起来没有问题,比较奇怪。

修改/etc/courier/authmysqlrc文件:

MYSQL_SERVER localhost

MYSQL_USERNAME mail_admin

MYSQL_PASSWORD mail_admin_password

MYSQL_PORT 0

MYSQL_DATABASE mail

MYSQL_USER_TABLE users

MYSQL_CRYPT_PWFIELD password

#MYSQL_CLEAR_PWFIELD password

MYSQL_UID_FIELD 5000

MYSQL_GID_FIELD 5000

MYSQL_LOGIN_FIELD email

MYSQL_HOME_FIELD "/home/vmail"

MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')

重新启动服务:

/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop restart
/etc/init.d/courier-pop-ssl restart
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart

修改/etc/aliases文件,可以根据自己的需要进行修改。

修改vi /etc/amavis/conf.d/15-content_filter_mode文件,去掉几个注释:

use strict;

# You can modify this file to re-enable SPAM checking through spamassassin

# and to re-enable antivirus checking.

#

# Default antivirus checking mode

# Uncomment the two lines below to enable it back

#

@bypass_virus_checks_maps = (

\%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);

#

# Default SPAM checking mode

# Uncomment the two lines below to enable it back

#

@bypass_spam_checks_maps = (

\%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);

1; # insure a defined return

修改 /etc/amavis/conf.d/50-user文件,添加:

$pax='pax';

修改/etc/postfix/master.cf文件,添加:

[...]

amavis unix - - - - 2 smtp

-o smtp_data_done_timeout=1200

-o smtp_send_xforward_command=yes

127.0.0.1:10025 inet n - - - - smtpd

-o content_filter=

-o local_recipient_maps=

-o relay_recipient_maps=

-o smtpd_restriction_classes=

-o smtpd_client_restrictions=

-o smtpd_helo_restrictions=

-o smtpd_sender_restrictions=

-o smtpd_recipient_restrictions=permit_mynetworks,reject

-o mynetworks=127.0.0.0/8

-o strict_rfc821_envelopes=yes

-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks

-o smtpd_bind_address=127.0.0.1

修改/etc/spamassassin/local.cf,添加:

[...]

# dcc

use_dcc 1

dcc_path /usr/bin/dccproc

dcc_add_header 1

dcc_dccifd_path /usr/sbin/dccifd

#pyzor

use_pyzor 1

pyzor_path /usr/bin/pyzor

pyzor_add_header 1

#razor

use_razor2 1

razor_config /etc/razor/razor-agent.conf

#bayes

use_bayes 1

use_bayes_rules 1

bayes_auto_learn 1

启动服务:

adduser clamav amavis
/etc/init.d/amavis restart
/etc/init.d/clamav-daemon restart
/etc/init.d/clamav-freshclam restart
/etc/init.d/postfix restart

参考:

http://www.howtoforge.com/virtual_postfix_mysql_quota_courier_ubuntu_edgy

http://wlx.westgis.ac.cn/322/

转换论坛:webwiz 7.9 -> phpBB3

Posted on 六月 3rd, 2007 in Linux | 25 Comments »

webwiz是一个基于ASP的论坛,由于此官方论坛已经停止维护,官方网站很长时间无法登录了,由于ASP的先天缺陷,而且正好PHPBB3也已经到RC1了,就决定把这个论坛进行转换。

1、实际情况
我们使用的WEBWIZ 7.9使用的是ACCESS数据库,并且在使用过程中有一定的修改,但我不清楚有哪些修改,因此,你的转换若有问题,也请反馈你的实际情况。
头像有三种,一种是系统提供的,在avatars目录下,另一种是用户上传的头像,放在uploads目录下,还有一种是HTTP连接,就是放在另外网站上的头像。
WEBWIZ的附件是直接存放在uploads目录下,但数据库里没有任何相关信息。
WEBWIZ的密码是采用了HASHEncode+Salt的加密算法,和SHA1类似,但不同。

2、转换程序
phpBB3只提供了从phpbb2的升级程序,在phpbb的官方论坛上搜索到了一个从webwiz到phpbb2的转换程序,但其转换的内容不完整,因此就决定自己写一个。而且PHPBB3现在已经采用了UTF8编码,要求数据库也要采用UTF8编码,MYSQL 4.1之后的程序也提供了UTF8编码。
首先需要转换ACCESS数据库到MYSQL,我前面有介绍过如何进行转换
我是使用了knoda进行数据转换的,在ubuntu系统下,注意,转换好后,数据库是默认为UTF8编码的。
转换完后,导出mysql数据。

mysqldump --default-character-set=latin1 -uroot yourdb > yourdb.sql

要修改此SQL文件,使之成为UTF8编码。替换所有的latin1为utf8,并在文件的开始添加:

SET NAMES utf8;
SET CHARACTER_SET_CLIENT=utf8;
SET CHARACTER_SET_RESULTS=utf8;

然后转移到测试服务器上,并进行相应的导入工作。

在http://www.phpbb.com下载最新的phpbb3,根据安装提示,安装一个默认的空白的PHPBB3系统,假如你的数据库是phpbb。
并把webwiz论坛的所有文件拷贝到同一个服务器上,二者目录可以在一个层次。
如:

/var/www/phpbb
/var/www/webwiz

然后把我提供的转换程序拷贝到phpbb/install/convertors目录下,即convert_webwiz.php和functions_webwiz.php文件。
同时修改phpbb/includes/auth/auth_db.php文件,若你想让你的用户重新申请密码的话,也可以不修改这个文件。

// Check password ...
// added for webwiz conversion
// HashEncode is webwiz function.
global $phpbb_root_path, $phpEx;
require($phpbb_root_path . 'includes/functions-webwiz-hash.' . $phpEx);
if (!$row['user_pass_convert'] && (md5($password) == $row['user_password']
or HashEncode($password.$row['salt'])==$row['user_password']))
{
if (md5($password)!=$row['user_password'])
{
// Unconverted password
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_password = "'.md5($password).'"
WHERE user_id = ' . $row['user_id'];
$db->sql_query($sql);
}

if ($row['user_login_attempts'] != 0)

这个前面的$sql语句中要添加一个字段:salt。

若修改了此文件,还要拷贝functions-webwiz-hash.php到phpbb/includes/目录下。
然后就可以在PHPBB的安装界面那儿进行系统的转换了。

下载:webwiz 7.9 converter