Tag: Debian

VsFTPD自动安装脚本

Posted by – 2010-07-20

虽然平时配置一个ftp要不了5分钟,但写完脚本才发现,浪费的时间实现太多了,脚本一般半分钟就装好了。
本脚本在CentOS 和 Redhat Enterprise环境中测试通过。有空再测其它发行版。
脚本中用到了以下几个东西:
shell检查linux发行版;
shell向文本写东西;
shell生成随机密码;
sed输出匹配行的下一行;
……
本文采用的是虚拟用户方式
具体内容如下:

#----------------------------引用文字-开始----------------------------
#!/bin/bash
# VsFTPD Virtual User Configuration
# Author: 楚霏
# Company: chengyongxu.com
# Create Date: 2010-07-20
# Last Update Date: 2010-07-20 17:36
#################################################
#
# 在这一部分定义相关变量
#
#################################################
YUM_INSTALL_LIST="vsftpd db4 db4-tcl db4-utils"
APT_INSTALL_LIST="vsftpd db4.6-util"

# 通常只需要编辑以下两个变量
FTP_USER=www
FTP_HOME=/www

VSFTPD_BASE_DIR=/etc/vsftpd

#################################################
#
# 检查系统环境,并安装所需软件包
#
#################################################
# 检查是否以ROOT用户执行本脚本
[ `id -u` -ne '0' ] && echo 'Must be root!' && exit

# 检查发行版是否为本脚本所支持
[ `uname -i` = 'x86_64' ] && PLATFORM='x86_64' || PLATFORM='i386'
if cat /etc/issue|grep '4.' ;then
        OS=4
elif cat /etc/issue|grep '5.';then
        OS=5
else
        echo 'Do not support this system ' && exit
fi

DISTRIBUTION=`lsb_release -i | awk '{print $3}'`
case "$DISTRIBUTION" in
*CentOS*|*"Red Hat"*|*Fedora*)
    yum -y install $YUM_INSTALL_LIST
    ;;
*Debian*|*Ubuntu*)
    apt-get -y install $APT_INSTALL_LIST
    ;;
*)
    echo 'Do not support this distribution !' && exit 0
    ;;
esac

#################################################
#
# 创建FTP用的系统用户
#
#################################################
# 检查ftp要使用的用户是否存在
EXISTS_USER=`grep -E "^\<$FTP_USER\>" /etc/passwd |awk -F: '{print $1}'`
if [ "$EXISTS_USER" != "$FTP_USER" ]
then
        useradd -u 78 $FTP_USER -d $FTP_HOME -s /sbin/nologin
fi 

# 检查ftp用户的家目录是否正确
if [ "$EXISTS_USER" = "$FTP_USER" ]
then
       usermod -d $FTP_HOME $FTP_USER
fi

#################################################
#
# 创建FTP的目录和文件
#
#################################################
# 创建安装目录
if [ ! -d $VSFTPD_BASE_DIR ]
then
        mkdir -p $VSFTPD_BASE_DIR
fi

# 把FTP的系统用户写入
echo "$FTP_USER" >> $VSFTPD_BASE_DIR/vsftpd.chroot_list

# 创建日志文件
touch /var/log/vsftpd.log

# 创建虚拟用户的配置文件路径目录
mkdir -p $VSFTPD_BASE_DIR/user_config

# 创建密码文件, 单行为用户名, 双行为密码
touch $VSFTPD_BASE_DIR/passwd.txt

#################################################
#
# 修改配置文件
#
#################################################
# 写入测试用户和密码
echo ftpuser1 >> $VSFTPD_BASE_DIR/passwd.txt
echo `< /dev/urandom tr -dc A-Za-z0-9 | head -c 20` >> $VSFTPD_BASE_DIR/passwd.txt

# 修改PAM认证文件
echo "    auth       required     pam_userdb.so db=$VSFTPD_BASE_DIR/user_passwd" > /etc/pam.d/vsftpd
echo "    account       required     pam_userdb.so db=$VSFTPD_BASE_DIR/user_passwd" >> /etc/pam.d/vsftpd

# 编辑vsftpd的配置文件
> $VSFTPD_BASE_DIR/vsftpd.conf && echo "已删除默认配置"
echo "\
listen=YES
background=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
chown_uploads=NO
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
async_abor_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to Ismole FTP servers
pam_service_name=vsftpd
chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/vsftpd.chroot_list
guest_enable=YES
guest_username=$FTP_USER
user_config_dir=$VSFTPD_BASE_DIR/user_config\
" >> $VSFTPD_BASE_DIR/vsftpd.conf

# 为虚拟用户创建家目录和配置文件
if [ ! -d $FTP_HOME/wwwroot/ftpuser1 ]
then
        mkdir -p $FTP_HOME/wwwroot/ftpuser1
        chown -R $FTP_USER $FTP_HOME
fi

echo "\
local_root=$FTP_HOME/wwwroot/ftpuser1
write_enable=YES
anon_umask=022
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES\
" >> $VSFTPD_BASE_DIR/user_config/ftpuser1

#################################################
#
# 创建虚拟用户密码认证数据库文件,并写成脚本
#
#################################################
case "$DISTRIBUTION" in
*CentOS*|*"Red Hat"*|*Fedora*)
    echo "\
if [ -e $VSFTPD_BASE_DIR/user_passwd.db ]
then
        rm -f $VSFTPD_BASE_DIR/user_passwd.db
fi
db_load -T -t hash -f $VSFTPD_BASE_DIR/passwd.txt $VSFTPD_BASE_DIR/user_passwd.db\
" >> $VSFTPD_BASE_DIR/db_load.sh
    ;;
*Debian*|*Ubuntu*)
    echo "\
if [ -e $VSFTPD_BASE_DIR/user_passwd.db ]
then
        rm -f $VSFTPD_BASE_DIR/user_passwd.db
fi
db4.6_load -T -t hash -f $VSFTPD_BASE_DIR/passwd.txt $VSFTPD_BASE_DIR/user_passwd.db\
" >> $VSFTPD_BASE_DIR/db_load.sh
    ;;
*)
    echo 'Do not support this distribution !!' && exit
    ;;
esac

chmod 500 $VSFTPD_BASE_DIR/db_load.sh
$VSFTPD_BASE_DIR/db_load.sh

#################################################
#
# 启动并测试
#
#################################################
/etc/init.d/vsftpd start

# 验证登录
echo "测试用户名是: ftpuser1"
# 显示出匹配行的下一行,也就是密码
echo "测试用户密码是: `sed -n '/ftpuser1/{n;p;}' $VSFTPD_BASE_DIR/passwd.txt`"
echo "测试无误的话别忘了删除测试用户,Good luck ! "
#----------------------------引用文字-结束----------------------------

Debian+nginx+mediawiki的rewrite问题

Posted by – 2009-09-08

环境是Debian+nginx0.7.61+php5.3.0+mysql5.1.37
一、保证mediawiki目录下的LocalSettings.php文件中没有对做url重写的相关没配置,也就是注释或删除下边这个参数

#----------------------------引用文字-开始----------------------------
#$wgArticlePath      = "/$1";
#----------------------------引用文字-结束----------------------------

二、在nginx的vhost.conf进行rewrite的配置

#----------------------------引用文字-开始----------------------------
    location / {
        index           index.html index.htm index.php;
        root            /www/wwwroot/chengyongxu.cn;
        rewrite ^/wiki/index.php/([^?]*)(?:\?(.*))? /wiki/index.php?title=$1&$2;
    }
#----------------------------引用文字-结束----------------------------

#上边只加了一条规则,这样就可以通过访问

http://chengyongxu.cn/wiki/index.php/阿贾克斯

来访问到

http://chengyongxu.cn/wiki/index.php?title=阿贾克斯

三、如果要做rewrite,一定要保证同类的链接的一致性
不能阿贾克斯的链接是:

http://chengyongxu.cn/wiki/index.php/阿贾克斯

而类似的巴塞罗那的链接是:

http://chengyongxu.cn/index.php/巴塞罗那

Debian和ubuntu寻找最快源

Posted by – 2009-05-11

Debian和ubuntu寻找最快源
适用于debian,同样也适用基于debian的发行版,如ubuntu,kubuntu,dreamlinux等

apt-spy 方式:
apt-spy会根据站点回应时间和带宽自动创建`sources.list'。

apt-get install apt-spy
mv sources.list sources.list.bak /*备份源列表*/
apt-spy --help /*获取详细的使用方法/
apt-spy update /*更新您的镜像列表文件*/
apt-spy -d testing -a Asia /*在亚洲区寻找速度最快的testing版镜像,并生成 sources.list文件,也可使用 -o 参数指定写入文件*/

一个漫长的等待,以后就不用麻烦了
apt-get update

后记:
发现ubuntu9.04的默认源中没有apt-spy这个软件了,下面是ubuntu9.04的163源
把下边的源列表增到/etc/apt/sources.list
#----------------------------引用文字-开始----------------------------
deb http://mirrors.163.com/ubuntu/ intrepid main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ intrepid-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ intrepid-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ intrepid-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ intrepid-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid-backports main restricted universe multiverse
#----------------------------引用文字-结束----------------------------
如果你还想找更快的源,就可以装apt-spy按上边的步骤使用一下了