Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

How to install vsftpd on FreeBSD

Michel Nadeau, August 28, 2009    --    Filed under Programming
vsftpd is a very light-weight, full-featured FTP server that can be installed and ready to use in only a couple of minutes. It's used by many huge FTP sites like RedHat, Debian, GNU, ISC and many more!

NOTE: you can use this tutorial to install vsftpd on almost any UNIX/Linux distribution, except for the step 4.

1. Installing vsftpd

Installing vsftpd is very simple. First, you need to download and extract it:

mkdir -p /usr/local/src
cd /usr/local/src
fetch ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.2.0.tar.gz
tar xvfz vsftpd-2.2.0.tar.gz

Then, you're ready to compile it:

cd vsftpd-2.2.0
make

And then to install it:

make install

2. Configuration

vsftpd uses the /etc/vsftpd.conf configuration file. A good idea is to start with the default one:

cp vsftpd.conf /etc

Here's a complete reference guide to customize each options of vsftpd.conf:

http://vsftpd.beasts.org/vsftpd_conf.html

3. Start/stop vsftpd

To start vsftpd, simply run:

vsftpd

To stop it, you have to kill it:

killall vsftpd

4. Start vsftpd automatically on boot

To start vsftpd automatically on boot, simply create the /usr/local/etc/rc.d/vsftpd.sh file, change its mode to 755, and put this content in it:

#!/bin/sh

/usr/local/sbin/vsftpd &

Conclusion

vsftpd is faster than proftpd, easier to install and to configure. It's very secure, stable and flexible: try it and give me your opinion about it!

View 1 Comment(s)

How to setup web server vhost + FTP account on NGinx and ProFTPD

Adrian Singer, August 26, 2009    --    Filed under Programming
As part of this post I will walk you through the process of setting up shared hosting, using an NGinx web server, ProFTPD ftp and Bind DNS.

Before you get started, you're going to need three things:

* Domain name to setup vhost under
* A dedicated ip address to use for the vhost
* Select username and password for ftp

Step 1 - Point to DNS servers

Login to your domain registrar (GoDaddy, eNom etc.), click on the designated domain and then update the DNS servers managed by this domain to DNS servers that you control.

Here at SPI, we use AlwaysUpDNS, so the two DNS servers to setup with the new domain, are going to be:

dns1.alwaysupdns.com
dns2.alwaysupdns.com

Once you update the DNS servers, it may take anywhere from 1 to 48 hours for the changes to propagate.

To check whether or not DNS propagated, you can run this command

dig mydomainname.com

Step 2 - Setup DNS hosting

Add new DNS hosting entry for the designated domain.

Here at SPI we use a custom version of Bind, so the way this is done is:

(a) Create a copy of a template 'blank' DNS hosting record

cp /etc/alwaysupdns/template.dns /etc/alwaysupdns/mydomainname.dns

Replace mydomainname with the domain name

The end file should look like this:

$TTL 60

@ IN SOA mydomain.com. mydomain.com. (
20090710 ; Serial number
60 ; Refresh
900 ; Retry
864000 ; Expire
60 ; Min TTL
)

; A record (web browsers go here)
@ IN A 1.2.3.4

; Email server
mydomain.com. MX 10 mx1.softwareprojects.com.

; DNS Servers
@ IN NS dns1.alwaysupdns.com.
@ IN NS dns2.alwaysupdns.com.

(b) Edit /etc/alwaysupdns/mydomainname.dns in your favorite editor and update the A record to point to the new dedicated ip address (replacing 1.2.3.4).

Also while you're at it, replace all occurrences of 'mydomain' with your domain name.

You can leave everything else as is.

(c) Edit /var/named/etc/namedb/named.conf and add this block to the end of the file

zone "mydomain.com"
{
type master;
file "/etc/alwaysupdns/mydomain.dns";

allow-transfer { 204.13.249.76; 208.78.69.76; 91.198.22.76; 203.62.195.76; };
};

Replace 'mydomain' everywhere with the domain name.

The zone-trafser details, make it possible to use DynDNS as a secondary level dns server.

(d) Restart Bind DNS by issuing:

killall named
named

(e) Test Bind is returning the correct response:

nslookup
server dns1.alwaysupdns.com
set q=a
mydomain.com

Step 3 - Add vhost record to Nginx

Open the NGinx config file (/usr/local/nginx/conf/nginx.conf) in your favorite editor and add this section to the bottom of the file, right before the closing }

# MyDomain
server {
listen 1.2.3.4:80;
server_name www.mydomain.com *.mydomain.com;
server_name_in_redirect off;

# set regular docroot
location /
{
root /home/mydomain.com/;
index index.php index.html index.htm;
}

location ~* \.(php)$
{
fastcgi_intercept_errors on;

fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/mydomain.com/$fastcgi_script_name;
include /etc/nginx/fastcgi_top.conf;
fastcgi_param DOCUMENT_ROOT /home/mydomain.com;
include /etc/nginx/fastcgi_bottom.conf;
}

}

Replace 1.2.3.4 with the new dedicated ip address

Replace mydomain with the new domain name and create a new folder under /home/mydomain.com to host the new site

Once done, tell NGinx to reload its config file, by issuing

kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

Step 4 - Create FTP user

First we have to create a system user, by issuing an adduser and providing a username and password you've preselected for this website.

Be sure to specify the folder as /home/mydomain.com (replacing mydomain with the chosen domain) and enter ftponly as the new user shell.

For example:

adduser

Username: mydomain
Full name: My Domain
Uid (Leave empty for default):
Login group [mydomain]:
Login group is mydomain. Invite mydomain into other groups? []:
Login class [default]:
Shell (sh csh tcsh bash rbash ftponly nologin) [sh]: ftponly
Home directory [/home/mydomain]: /home/mydomain.com
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password:
Enter password again:
Lock out the account after creation? [no]:
Username : mydomain
Password : *****
Full Name : My Domain
Uid : 1031
Class :
Groups : mydomain
Home : /home/mydomain.com
Home Mode :
Shell : /sbin/ftponly
Locked : no
OK? (yes/no): yes
adduser: INFO: Successfully added (mydomain) to the user database.

Step 5 - Jail FTP user

To prevent the FTP user from gaining access to any other folders on this server, we need to jail the user to the home directory for the new domain.

Open ProFTPd config file (/usr/local/etc/proftpd.conf) and locate the block that begins with DefaultRoot

Add this line below, replacing mydomain with the new domain name

DefaultRoot /home/mydomain.com mydomain

Restart ProFTPD by issuing

killall proftpd
/usr/local/etc/rc.d/proftpd.sh

Then connect to the new site via FTP and verify it is working properly, not letting you access any parent folders above the current directory.

Step 6 - Update permissions

The last step is to update the new folder permissions, so that our FTP user will be able to create / delete files.

chown -R mydomain:mydomain /home/mydomain.com/

Replace mydomain with the chosen domain name

How to fix: MySQL Duplicate entry for key PRIMARY on Auto_Increment

Adrian Singer, August 20, 2009    --    Filed under Programming
We encountered an interesting error on a client database this past few days, where MySQL was issuing random errors, complaining about:

Duplicate entry '1' for key 'PRIMARY'

These errors were coming up on various tables at different times in the day, but the crazy thing is - the duplicate key error is on an auto-increment field!

That's not normal.

When you have a table defined as

CREATE TABLE test (id int auto_increment, somevalue int, primary key (id));

There's no way you can generate a duplicate key error on the 'id' field, unless you manually pass the value of the auto_increment id field (which we were not)

Running a mysqlcheck reported all tables are OK. We proceeded to issue OPTIMIZE TABLE statements (this rebuilds indexes) as well as manually running REPAIR TABLE for each table, but nothing helped.

The table indexes were obviously corrupted in some way, although MySQL tools reported all is well...

How to fix this problem

The only way we could fix it, is by rebuilding the entire database from scratch.

Dropping all tables and reloading them from a backup.

Step 1

Create a backup of the database by issuing:


mysqldump
-uUSER -pPASSWORD DBNAME > /tmp/my_backup.sql

Replace USER with your MySQL username, PASSWORD with your MySQL password and DBNAME with the databasename you are looking to repair.

Step 2

Drop and recreate the database


drop database DBNAME
;
create database DBNAME;

Step 3

Reload the import


mysql
-uUSER -pPASSWORD DBNAME < /tmp/my_backup.sql


View 4 Comment(s)

How to avoid Rsync Endless Loop

Adrian Singer, July 27, 2009    --    Filed under Programming
Rsync is a great command-line sync tool, that allows fast replication from one web server to another.

If you are running more than one Rsync command in a cronjob, replicating several folders into a target machine, watch out for the Rsync endless loop bug.

There are two steps you can take to avoid this:

Step 1:

Consider this scenario:

Destination machine B has these two cronjobs, set to run every 5 minutes:

*/5 * * * * /usr/local/bin/rsync --progress --stats --archive -z --compress -t MachineA.com:/usr/home/ /usr/home/

*/5 * * * * /usr/local/bin/rsync --progress --stats --archive -z --compress -t MachineA.com:/usr/home/something/ /usr/home/something/

Since the folder /usr/home/something/ is also included by the first cronjob, this can easily cause the infamous Rsync endless loop bug.

The fix, add an --exclude to the first cronjob, like this:

*/5 * * * * /usr/local/bin/rsync --exclude /usr/home/something/ --progress --stats --archive -z --compress -t MachineA.com:/usr/home/ /usr/home/

*/5 * * * * /usr/local/bin/rsync --progress --stats --archive -z --compress -t MachineA.com:/usr/home/something/ /usr/home/something/

Step 2:

If it takes more than 5 minutes for Rsync to complete, before the next instance runs, you're in trouble.

To be safe, write a php script that will check if the Rsync daemon is running, prior to launching another one.

How to Restore a MySQL Backup

Brett Batie, July 23, 2009    --    Filed under Programming
This tutorial goes over all the necessary steps to restore a MySQL backup via the shell or command line.

Determine The Basics About Your Database

We need some basic information about the MySQL installation before we get started restoring the backup.

First, lets determine the location of the mysql databases. It is generally located at /var/mysql/data but it is always good to double check. Issue the following command to see where it is:

cat /etc/my.cnf | grep 'innodb_data_home_dir'

This will output something like the following and tells us that the mysql databases are located at /usr/local/var. This location will be used for the remainder of the tutorial so please be sure to replace it with the location that you received from the above command.

innodb_data_home_dir = /usr/local/var/


Remove The Old Database(s)

If MySQL is not corrupted and your backup files are set to drop the table before inserting the new data. You can skip this section. If you are not sure it will not hurt to complete the following steps but we will need to take the database offline for a few minutes.

First we need to shutdown mysql with the following command:

mysqladmin -uroot -pYourPassword shutdown

Now we need to backup the current mysql data directory and create a new one. This can be done with the following 2 commands:

mv /usr/local/var /usr/local/var-old
mkdir /usr/local/var

Next, we will install the basic mysql table by running the mysql_install.sh script. Generally, it is located at /usr/local/mysql/bin/mysql_install_db. If it is not there you can use the following command to find it.

locate mysql_install_db

Note: you may need to update your locate database if the script is not found with the above command. To update your database issue one of the following commands and then repeat the above command.

FreeBSD and Mac OSX
/usr/libexec/./locate.updatedb

For CentOS or RH cores
updatedb

Now that we have found the script we can run it

/usr/local/bin/./mysql_install_db

Restore the Backup

The first step is to take your backup file and uncompress it.

tar -xvzf /usr/local/var/yourBackup.tgz

If mysql.sql was not listed in the backup you can either manually reset the permissions or copy it from the backup you just made.

cp /usr/local/var-old/mysql/user* /usr/local/var/mysql/

Now lets set the ownership of the directory and all files in the directory. Make sure to use the appropriate group and user with the below command.

chown -R mysql:mysql /usr/local/var/

Now create any databases that you are going to restore with a command like the following (repeat the command for every database that you will restore):

echo 'create database YourNewDatabase' | mysql -uroot -pYourPassword

Restore the backup with the below command and repeat the command for every sql file/database that you will restore.

mysql -uroot -pyourPassword YourDatabase < backup.sql

Startup MySQL

mysqld_safe &

Email Mailserver Blacklist Check - New Tool

Adrian Singer, July 21, 2009    --    Filed under Traffic
Whether you are an individual user sending email to friends & colleagues, or use a commercial email-sending service like Constant Contact, it is important to regularly check your sending ip address hasn't been black listed.

Today we released a simple tool that lets you easily test if your mail server is black listed with any popular black-list DNS service:

Email mail server Blacklist Checker



-

Don't know your sending mail server ip address? Send an email to yourself, then view the message headers.

View 1 Comment(s)
« Previous Posts » Next Posts



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions