手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2013年03月9日的文章

aliyun 安装 ftp(proftpd)

有了服务器,怎么着都得装个Ftp吧,否则,必须得让人用ssh连接来上传文件 ?
于是我找了proftpd,因为比较简单vsftpd太麻烦了。proftpd的教程很简单

1、先apt-get update,apt-get upgrade
2、apt-get install proftpd-basic proftpd-mod-mysql
3、修改 /etc/proftpd/proftpd.conf
因为原内容都注释了,所以直接在文件的最后加上:

XML/HTML代码
  1. DefaultRoot ~  
  2. Include /etc/proftpd/sql.conf  
  3. RequireValidShell off  

4、添加一个组,和一个用户:

XML/HTML代码
  1. groupadd -g 2001 ftpgroup  
  2. useradd -u 2001 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser  

5、去mysql里增加一个用户,如proftpd/proftpdpass,建一个数据库,如:proftpd
6、插入表结构:

SQL代码
  1. CREATE TABLE ftpgroup (  
  2.  groupname varchar(16) NOT NULL default '',  
  3.  gid smallint(6) NOT NULL default '2001',  
  4.  members varchar(16) NOT NULL default '',  
  5.  KEY groupname (groupname)  
  6.  ) ENGINE=MyISAM COMMENT='ProFTP group table';  
  7.   
  8. CREATE TABLE ftpuser (  
  9.  id int(10) unsigned NOT NULL auto_increment,  
  10.  userid varchar(32) NOT NULL default '',  
  11.  passwd varchar(32) NOT NULL default '',  
  12.  uid smallint(6) NOT NULL default '2001',  
  13.  gid smallint(6) NOT NULL default '2001',  
  14.  homedir varchar(255) NOT NULL default '',  
  15.  shell varchar(16) NOT NULL default '/sbin/nologin',  
  16.  count int(11) NOT NULL default '0',  
  17.  accessed datetime NOT NULL default '0000-00-00 00:00:00',  
  18.  modified datetime NOT NULL default '0000-00-00 00:00:00',  
  19.  PRIMARY KEY (id),  
  20.  UNIQUE KEY userid (userid)  
  21.  ) ENGINE=MyISAM COMMENT='ProFTP user table';  

7、修改/etc/proftpd/modules.conf,去掉两行注释:

XML/HTML代码
  1. LoadModule mod_sql.c  
  2. LoadModule mod_sql_mysql.c  

8、修改/etc/proftpd/sql.conf

 

 

XML/HTML代码
  1. SQLBackend mysql  
  2. SQLAuthTypes Crypt  
  3. #下面一行就是用户名密码  
  4. SQLConnectInfo 数据库@localhost 用户名 密码   
  5. SQLUserInfo ftpuser userid passwd uid gid homedir shell  
  6. SQLGroupInfo ftpgroup groupname gid members  
  7. # Update count every time user logs in  
  8. SQLLog PASS updatecount  
  9. SQLNamedQuery updatecount UPDATE "countcount=count+1, accessed=now() WHERE userid='%u'" ftpuser  
  10. SQLLog STOR,DELE modified  
  11. SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser  

9、插入用户:

XML/HTML代码
  1. INSERT INTO `ftpgroup` (`groupname`, `gid`, `members`) VALUES ('ftpgroup', 2001, 'ftpuser');  
  2. INSERT INTO `ftpuser` ( `userid`, `passwd`, `uid`, `gid`, `homedir`, `shell`, `count`) VALUES ( 'username', ENCRYPT('password'), 2001, 2001, '/var/www/www.example.com/', '/sbin/nologin', 0);  

10、重启proftpd:/etc/init.d/proftpd restart
上面这段其实是来自:http://www.sysadminworld.com/2011/install-proftpd-with-mysql-backend-on-debian-ubuntu/

 

--------EOF---

至此,上面的内容基本上就能够登录成功了,如果还是失败,建议先停掉proftpd,然后运行proftpd -nd6,查看错误信息,比如我就看到了这个:

XML/HTML代码
  1. Mar 09 00:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): notice: unable to use '~/' [resolved to '/server/wwwroot/htdocs/']: Permission denied  
  2. Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): Preparing to chroot to directory '~/'  
  3. Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): chroot to '~/' failed for user 'xxxxxx': Operation not permitted  
  4. Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): error: unable to set default root directory  
  5. Mar 08 16:22:29 test proftpd[8850] test (0.0.0.0[0.0.0.0]): FTP session closed.  

我靠,这个怎么办?

 

这时候我又请vampire帮忙了。他就帮我检查了一下,做了几个处理:

1、vim /etc/groups ,在www-data:x:33后面加了:www-data:x:33:ftpgroup ,表示权限跟着www-data,因为我们的ftp目录里的文件都是基于www-data的

2、修改/etc/proftpd/proftpd.conf,改其中的:user / group ,都改成www-data

3、还是/etc/proftpd/proftpd.conf ,改 Umask ,原来是Umask 022 022,去掉一个022

4、因为我的www-data是gid是33,所以刚才在数据库里插的gid统统换成33,而不是原来的2001,这时候再登录其实还是不正常。

5、最重要的一个,在刚才的sql.conf里面,加入:SQLMinID 33,这个玩意要参考:http://www.proftpd.org/docs/directives/linked/config_ref_SQLMinID.html,我晶,这个东西,居然在默认的sql.conf里是没有这一行的。果然还是vampire有经验。因为www-data的gid是33,所以sqlminid就是33了。

这时候,终于一切正常了。折腾了好久。。。

 

 

 

 

 

 

 

Tags: aliyun, proftpd

aliyun二三事

最近在试用阿里云,但是遇到了一些问题。
我在安装数据库的时候,是通过apt-get install mysql-server进行安装的,然而我安装完后,想将数据存储到额外挂载的磁盘时,却发现数据不能写入。。。
因为我老是启动失败。。所以看了下LOG,LOG是说写入目录失败。
于是请vampire帮忙看了一下,他测试了mysql_install_db,但是。。。

XML/HTML代码
  1. # mysql_install_db --datadir=/server/software/mysql_data  
  2. Installing MySQL system tables...  
  3. 130308 16:14:25 [Warning] Can't create test file /server/software/mysql_data/AY130304113437124704.lower-test  
  4. 130308 16:14:25 [Warning] Can't create test file /server/software/mysql_data/AY130304113437124704.lower-test  
  5. ERROR: 1005  Can't create table 'db' (errno: 13)  
  6. 130308 16:14:25 [ERROR] Aborting  
  7.   
  8. 130308 16:14:25 [Note] /usr/sbin/mysqld: Shutdown complete  
  9.   
  10.   
  11. Installation of system tables failed!  Examine the logs in  
  12. /server/software/mysql_data for more information.  
  13.   
  14. You can try to start the mysqld daemon with:  
  15.   
  16.     shell> /usr/sbin/mysqld --skip-grant &  
  17.   
  18. and use the command line tool /usr/bin/mysql  
  19. to connect to the mysql database and look at the grant tables:  
  20.   
  21.     shell> /usr/bin/mysql -u root mysql  
  22.     mysql> show tables  
  23.   
  24. Try 'mysqld --help' if you have problems with paths.  Using --log  
  25. gives you a log in /server/software/mysql_data that may be helpful.  
  26.   
  27. Please consult the MySQL manual section  
  28. 'Problems running mysql_install_db', and the manual section that  
  29. describes problems on your OS.  Another information source are the  
  30. MySQL email archives available at http://lists.mysql.com/.  
  31.   
  32. Please check all of the above before mailing us!  And remember, if  
  33. you do mail us, you MUST use the /usr/scripts/mysqlbug script!  

oh shit,还是安装不了。试了很多都没有用。最后从官方下载了5.6的包进行安装。居然就OK了。我靠,这个源是cn.ubuntu的源啊。。。苦逼了。
所幸问题解决了。

多谢vampire,同时各位朋友也注意下。如果真的不行,也可以尝试从网上直接下载源码编译,要么。就换成中科大的源,然后再upgrade。中科大的更新比较快。

但因为要修改内容和启动参数还是有点危险的。。。