Servidor FTP com NetBSD (PureFTPD + MySQL)

cvs

Vamos falar sobre a instalação de um servidor ftp usando NetBSD, que tentando aproveitar sua portabilidade e sua robustez, quem sabe não rola instalar um servidor de ftp na geladeira ou no fogão? hehehe...

[ Hits: 24.914 ]

Por: Thiago Alves em 04/10/2007 | Blog: http://www.seeufosseopresidente.com.br


Instalação e configuração do PureFTPD



Primeiramente adicione a seguinte linha ao arquivo /etc/mk.conf:

PKG_OPTIONS.pureftpd=ssl mysql virtualchroot utf8

Se ele não existir, pode criá-lo. Esses parâmetros serão usados na compilação do pure... Mágica... hehehehe

Vamos então instalar o dito cujo:

# cd /usr/pkgsrc/net/pure-ftpd
# make install clean


Vamos configurar ele para iniciar junto do sistema:

# cp /usr/pkg/share/examples/rc.d/pure_ftpd /etc/rc.d/
# chmod +x /etc/rc.d/pure_ftpd


Adicione no arquivo /etc/rc.conf a linha:

pure_ftpd=YES

Agora vamos fazer umas modificações importantes:

No arquivo /etc/rc.d/pure_ftpd, altere o seguinte parâmetro, na linha:

command_args="-B"

Altere para:

command_args="-B -A -E -O stats:/var/log/pureftpd.log -s -Z -l mysql:/etc/pure-ftpd/mysql.conf"

Crie o arquivo /etc/pure-ftpd/mysql.conf e nele coloque esses parâmetros:

# Optional : MySQL server name or IP. Don't define this for unix sockets.
# MYSQLServer 127.0.0.1
#
# Optional : MySQL port. Don't define this if a local unix socket is used.
# MYSQLPort 3306
#
# Optional : define the location of mysql.sock if the server runs on this host.

MYSQLSocket /tmp/mysql.sock
#
# Mandatory : user to bind the server as.
MYSQLUser sql_username
#
# Mandatory : user password. You must have a password.
MYSQLPassword sql_password
#
# Mandatory : database to open.
MYSQLDatabase pureftpd
#
# Mandatory : how passwords are stored
# Valid values are : "cleartext", "crypt", "md5" and "password"
# ("password" = MySQL password() function)
# You can also use "any" to try "crypt", "md5" *and* "password"
MYSQLCrypt cleartext
#
# In the following directives, parts of the strings are replaced at
# run-time before performing queries :
#
# \L is replaced by the login of the user trying to authenticate.
# \I is replaced by the IP address the user connected to.
# \P is replaced by the port number the user connected to.
# \R is replaced by the IP address the user connected from.
# \D is replaced by the remote IP address, as a long decimal number.
#
# Very complex queries can be performed using these substitution strings,
# especially for virtual hosting.
#
# Query to execute in order to fetch the password
MYSQLGetPW SELECT password FROM ftpusers WHERE username ='\L' AND active='1'
# Query to execute in order to fetch the system user name or uid
MYSQLGetUID SELECT uid FROM ftpusers WHERE username = '\L'
# Query to execute in order to fetch the system user group or gid
MYSQLGetGID SELECT gid FROM ftpusers WHERE username = '\L'
# Query to execute in order to fetch the home directory
MYSQLGetDir SELECT homedir FROM ftpusers WHERE username = '\L'
# Optional : bandwidth throttling.
# The server has to be compiled with throttling support.
# Values are in KB/s .
MySQLGetBandwidthUL SELECT ULbw FROM ftpusers WHERE username = '\L'
MySQLGetBandwidthDL SELECT DLbw FROM ftpusers WHERE username = '\L'
# Optional : ratios. The server has to be compiled with ratio support.
MySQLGetRatioUL SELECT ULRatio FROM ftpusers WHERE username ='\L'
MySQLGetRatioDL SELECT DLRatio FROM ftpusers WHERE username ='\L'
#Query to get the maximal disk usage (virtual quotas) in Megabytes.
MySQLGetQTASZ SELECT Quota FROM ftpusers WHERE username ='\L'
#Query to get the maximal number of files.
MySQLGetQTAFS SELECT QuotaFiles FROM users WHERE username = '\L'
# If you upgraded your tables to transactionnal tables (Gemini,
# BerkeleyDB, Innobase...), you can enable SQL transactions to
# avoid races. Leave this commented if you are using the
# traditionnal MyIsam databases or old (< 3.23.x) MySQL versions.
MySQLTransactions On

Altere de acordo com suas necessidades.

Crie o banco de dados pro ftp, por exemplo:

# mysql -u root -p
mysql> create database pureftpd;
mysql> use pureftpd;

Agora vamos criar os campos necessários.

mysql> CREATE TABLE `ftpusers` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`uid` int(5) NOT NULL default '80',
`gid` int(5) NOT NULL default '80',
`homedir` varchar(255) NOT NULL default '/web',
`active` tinyint(1) NOT NULL default '1',
`Quota` int(10) NOT NULL default '0',
`ULbw` int(10) NOT NULL default '0',
`DLbw` int(10) NOT NULL default '0',
`ULRatio` int(10) NOT NULL default '0',
`DLRatio` int(10) NOT NULL default '0',
`QuotaFiles` int(10) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='FTP users';


Pra ver se foi tudo ok:

mysql> show tables;
+--------------------+
| Tables_in_pureftpd |
+--------------------+
| ftpusers           |
+--------------------+
1 row in set (0.00 sec)

Vamos adicionar nosso primeiro usuário para fazermos o teste:

mysql> insert into ftpusers values(1,'cvs','thiago','80','80','/ftp/cvs/',1,100,0,0,0,0,0)

# mkdir /ftp/cvs
# chown -R 80.80 /ftp/cvs


Agora é só conectar no servidor e testar.



Página anterior     Próxima página

Páginas do artigo
   1. Introdução
   2. Instalação e configuração do PureFTPD
   3. Script para administrar o ftp
   4. Conclusão
Outros artigos deste autor

Compilando o Apache 2 com PHP e MySQL

Gcombust, um frontend para cdrecord

Servidor web com CentOS + Apache

OpenBSD Proxy - Squid, SquidGuard, SquidClamAV e AdZapper

MPlayer - The Movie Player

Leitura recomendada

A gerência da miséria

Análise do Seamonkey - A evolução da espécie

Ligando, conectando e desligando automaticamente com o Kurumin

Como verificar conexões abertas no Linux

Criando VPN site-to-site, conectando diversas filiais a matriz com openVPN

  
Comentários
[1] Comentário enviado por killer_val em 28/01/2010 - 21:10h

Esse script e em php
como que instala ele sou novo no linux


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts