Cách cài đặt ISPConfig 3 ProFTPd cho Debian ?

nbbnbmn
nbbnbmn
Trả lời 12 năm trước

Đối với người dùng Linux, ISPConfig 3 là giải pháp hàng đầu trong lĩnh vực quản lý hosting trên nền mã nguồn mở. Nó cho phép quản lý nhiều server thông qua 1 hệ thống control cpanel. Nếu bạn đang sử dụng máy chủ VPS với OpenVZ, thật không may là bạn không thể chạy Pureftpd được đi kèm mặc định với ISPConfig. Bài viết sau sẽ hướng dẫn các bạn sử dụng ProFTPd để thay thế Pureftpd một cách dễ dàng.

Chuẩn bị cài đặt

Cài đặt ISPConfig 3 ProFTPd cho DebianProFTPd là một FTP server khá mạnh và đơn giản trong cài đặt cũng như cấu hình, được rất nhiều máy chủ dùng. Tuy nhiên, hướng dẫn này không bao gồm quota bởi nó không được hỗ trợ trong VPS (nếu không muốn chỉnh sửa ftp_user_edit.php trong ISPConfig 3).

Ở minh họa này chúng tôi sử dụng Debian 5.0 Lenny nhưng cũng có thể áp dụng cho bản 6.0. Một số Distribution khác có thể cần sửa đổi một chút.

Lưu ý: quá trình này làm việc tốt trên máy chủ sạch và cài đặt ISPConfig 3. Nếu sử dụng máy chủ hiện hành sẽ cần vào và editting/saving mọi user được tạo ra, do đó có thể gây một số sự cố.

Cài đặt

Đầu tiên bạn chạy độc lập lệnh sau:

apt-get remove pure-ftpd-common pure-ftpd-mysql
apt-get install proftpd proftpd-mod-mysql

Tạo Group & User

groupadd -g 2001 ftpgroup
useradd -u 2001 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser

Cấu hình cơ sở dữ liệu

Chạy lệnh sau:

mysql -u root -p
Use dbispconfig

Sau đó chạy các truy vấn dưới đây:

ALTER TABLE `ftp_user` ADD `shell` VARCHAR( 18 ) NOT NULL DEFAULT
'/sbin/nologin',
ADD `count` INT( 11 ) NOT NULL DEFAULT '0',
ADD `accessed` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
ADD `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
CREATE TABLE ftp_group (
groupname varchar(16) NOT NULL default '',
gid smallint(6) NOT NULL default '5500',
members varchar(16) NOT NULL default '',
KEY groupname (groupname)
) TYPE=MyISAM COMMENT='ProFTP group table';
INSERT INTO `ftp_group` (`groupname`, `gid`, `members`) VALUES
('ftpgroup', 2001, 'ftpuser');

Cấu hình ProFTPd

Trước tiên chúng ta sẽ chỉnh sửa lại tập tin /usr/local/ispconfig/interface/lib/config.inc.php:

nano /usr/local/ispconfig/interface/lib/config.inc.php

Tìm đến biến db_password và lưu ý mật khẩu cho sau này.

Chỉnh sửa tập tin /etc/proftpd/proftpd.conf:

nano /etc/proftpd/proftpd.conf

Tìm đến dòng:

#Include /etc/proftpd/sql.conf

Bỏ chú thích cho nó để trở thành:

Include /etc/proftpd/sql.conf

Chỉnh sửa file /etc/proftpd/sql.conf:

nano /etc/proftpd/sql.conf

Xóa bỏ toàn bộ nội dung trong đó và thay thế bằng:

#
# Proftpd sample configuration for SQL-based authentication.
#
# (This is not to be used if you prefer a PAM-based SQL authentication)
#

<IfModule mod_sql.c>
DefaultRoot ~

SQLBackend mysql

# The passwords in MySQL are encrypted using CRYPT

SQLAuthTypes Plaintext Crypt

SQLAuthenticate users groups

# used to connect to the database
# databasename@host database_user user_password
SQLConnectInfo dbispconfig@localhost ispconfig _insertpasswordhere_

# Here we tell ProFTPd the names of the database columns in the "usertable"
# we want it to interact with. Match the names with those in the db
SQLUserInfo ftp_user username password uid gid dir shell

# Here we tell ProFTPd the names of the database columns in the "grouptable"

# we want it to interact with. Again the names match with those in the db
SQLGroupInfo ftp_group groupname gid members

# set min UID and GID - otherwise these are 999 each
SQLMinID 500

# create a user's home directory on demand if it doesn't exist
CreateHome off

# Update count every time user logs in
SQLLog PASS updatecount
SQLNamedQuery updatecount UPDATE "count=count+1, accessed=now() WHERE userid='%u'" ftpuser

# Update modified everytime user uploads or deletes a file
SQLLog STOR,DELE modified
SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser

RootLogin off

RequireValidShell off

</IfModule>


Hãy chắc chắn rằng bạn đã thay đổi _insertpasswordhere_ bằng mật khẩu lấy từ ISPConfig.

Nếu cơ sở dữ liệu MySQL trên một máy chủ khác, thay đổi localhost để đại diện cho máy chủ MySQL của bạn.

Chỉnh sửa file /etc/proftpd/modules.conf:

nano /etc/proftpd/modules.conf

Tìm đến dòng:

#LoadModule mod_sql.c

và bỏ chú thích cho nó thành:

LoadModule mod_sql.c

Đổi dòng:

#LoadModule mod_sql_mysql.c

Thành:

LoadModule mod_sql_mysql.c

Cuối cùng chạy:

/etc/init.d/proftpd restart

Thay đổi ISPConfig 3

Bây giờ chúng ta cần thay đổi một số tập tin trong ispconfig. Mặc dù đây không phải ý kiến tốt nhất bởi khi nâng cấp lên phiên bản mới thì các thay đổi này sẽ biến mất. Tuy nhiên trong trường hợp này sẽ giúp ProFTPD hoạt động tốt hơn.

Chỉnh sửa file /usr/local/ispconfig/interface/web/sites/ftp_user_edit.php:

nano /usr/local/ispconfig/interface/web/sites/ftp_user_edit.php

Tìm dòng:

$uid = $web["system_user"];
$gid = $web["system_group"];

và thay thế bằng:

$userinfo = posix_getpwnam($web["system_user"]);
$uid = $userinfo['uid'];
$gid = $userinfo['gid'];

Vậy là xong! Lưu ý rằng nếu bạn đang đăng nhập vào giao diện điều khiển web của ISPConfig thì phải đăng xuất trước khi thay đổi các đăng ký trên máy tính của mình.