Friday 23 July 2010

Searching with GREP

posted by Tavis J. Hampton in: Web servers Software

Grep output

GREP, which stands for global regular expression print, is a sophisticated Linux/Unix tool that can serve many purposes, but one useful purpose on a dedicated server is its ability to search files and directories. With grep you can search within multiple files with relative ease. You can also parse printed screen data to simplify results.

To search a file, just enter “grep” followed by the search term and then the filename. For example, to search the file “httpd.conf” for the word “localhost”, you would type:

grep localhost httpd.conf

To use grep, to simplify printed screen lists, use the following format:

ls -al /usr/bin | grep make

This will list all of the files in the /usr/bin directory, but will only display those files that contain the word “make”. For more in-depth documentation, including use of regular expressions, type “man grep” from the command line.

Photo Source: Wikimedia Commons

Thursday 22 July 2010

Rsync Incremental Backups

posted by Tavis J. Hampton in: Web servers Software

Graphical rsync output

Question: How can I easily perform incremental backups on my dedicated server?

Answer: There are few tasks more important than backing up your server. Because of the nature of computers and especially the nature of the Internet, you are bound to have problems. They may or may not cause data loss, but that is not a chance you want to take.

Rsync is a tool that simply syncs the files in one directory with another. What makes it ideal for backups is that 1) it can archive files and compress them and 2) it can use SSH to perform the backups to remote servers.

To run an rsync backup, just execute the command like this:

rsync -avz ~/public_html username@hostname.com:/home/user/backupfiles/

This will backup, archive, and compress the files found in public_html on your server. Finally, it will send those archives to the remote server in the directory specified. The best part about rsync is that, the next time you perform a backup, it will only backup the files that have changed (i.e. incremental backups), saving you bandwidth and time.

ADVERTISING
ADVERTISING

Tuesday 20 July 2010

How to Use Email Forwarding

posted by Tavis J. Hampton in: Web servers Software

Email iconUsing multiple email addresses is a good way to organize messages and direct users to the right people. Rather than create accounts for each address, however, you can use email forwarding to redirect messages to the right people.

For example, you can forward all messages sent to billing@yourdomain, sales, and marketing all to the same address: tom@yourdomain. That way, Tom will handle those email messages accordingly without having to check each of those accounts separately.

Most web-based control panels have support for mail forwarding built into them. If, for some reason, you do not have that option, you can create forwards manually. To forward email from one address to another, use email aliases. To create aliases, edit the /etc/aliases file and add lines like the following:

billing: tom

That will forward all mail sent to “billing” to “tom”. Once you have created your alises, save the aliases file and run: “newaliases” from the command line.

Image Source: Wikimedia Commons

Monday 19 July 2010

How to Force YUM to Exclude Certain Packages

posted by Tavis J. Hampton in: Web servers Software

YUM logoYUM is a package management system for Red Hat Enterprise Linux (RHEL), CentOS, Fedora, and other Red Hat-based Linux operating systems. It is command-line driven and is an easy tool you can use to keep your server updated and install any new software you need.

Normally, when you perform updates, YUM will search the distribution’s online repository and select any newly updated packages for download and installation. These may include everything from Apache web server to the Linux kernel itself.

Most of the time, it is a general good practice to update all of the available packages, but there are times when this may not be ideal. For example, if you know for certain that a new version of a particular package that you have installed will not work with a version of one of your web applications, you may want to delay updating until you have patched your application. Another possible scenario is that you may want to update most of your other packages now but wait until later to update the kernel, which will require a reboot.

YUM has a built-in feature that allows you to exclude a package or group of packages of your choosing. You can either use the exclude function on a long-term basis or for one particular update. To make a long-term change, you should edit your repository file (usually yum.conf). Find the [main] section and add the following line:

Continue reading: How to Force YUM to Exclude Certain Packages

Friday 16 July 2010

How to Fix an Open Relay in Postfix

posted by Tavis J. Hampton in: Web servers Software

As I have been reiterating all week, an open relay is a bad idea. If your mail server is left open, anyone can use your SMTP service to send mail, and spammers will use it. This can result in your server being blacklisted and extraneous use of system resources that neither benefit you nor your users.
Postfix logoTo secure Postfix, there are a number of functions you can add the configuration file /etc/mail/main.cf. Edit the file and add the following lines:

smtpd_helo_required = yes
smtpd_delay_reject = no
disable_vrfy_command = yes

smtpd_helo_restrictions = permit_mynetworks,
reject_invalid_hostname,
reject_unknown_hostname,
reject_non_fqdn_hostname

This will force incoming requests to pause and identify themselves before proceeding, and will allow properly authenticated users to pass through and send mail. To finish, save the file and restart Postfix:

/etc/init.d/postfix restart

Thursday 15 July 2010

How Do Spammers Send Spam from My Server?

posted by Tavis J. Hampton in: Software

Wall of real spam

When your server has become a haven for spammers, it is never a pleasant ordeal. Your server will probably be blacklisted, causing many of the emails you send to bounce back, and you may have serious connection problems due to the spammer using valuable system resources.

There are a couple of ways in which spammers will use a server to send their emails. The first is through an open relay in your mail server. This is something that you can easily fix in both Postfix and Sendmail. I will post more about fixing an open relay tomorrow. The second method is by signing up for a legitimate hosting account with your web hosting service, but then using the account to send spam. By the time you figure out what they have done, they are usually long gone.

The third and probably most nefarious method of sending spam from your server is through an actual attack on your server. When a hacker finds a hole in your security, they will install a bot on the server. That bot will then act as a small mail server for the hacker, all without your knowledge. You may not even notice it unless it causes some side effects. All three methods should be fixed with increased security and careful scanning of your server for possible threats.

Photo Source: Flickr

Wednesday 14 July 2010

How to Remove Software in Linux

posted by Tavis J. Hampton in: Software

Delete icon
Question: How do I remote software that I installed from my Linux dedicated server?

Answer: The answer to that question depends on how you installed the software in the first place. Once you establish how and where the software has been installed, you can determine how to remove it.

1. Package Manager - Most software should be installed with a package manager like YUM or Apt. If that is the case, you remove it with the normal command for the package manager:

yum remove [packagename]
apt-get remove [packagename]

2. Manual Deb, RPM, etc - If you installed a distribution package manually, you can remove it manually or use your package manager to remove it.

3. Binary Archive - If you were given a tar.gz or similar package with binaries inside, and you unpacked them to a directory, simply remove the directory. If the package had an installer program, try using that to uninstall it.

4. Source - If you compiled the software from source and used “make install” to install it, removing it may be more tricky. If you still have the source files, you can simply run “make uninstall”. Otherwise, you will have to find out where the files were installed and remove. They may be in several directories.

Monday 12 July 2010

Troubleshooting Database Connections

posted by Tavis J. Hampton in: Web servers Software

Drupal database connection error

When MySQL works correctly, it can be a thing of beauty, but when something goes wrong, it can drive you mad. Here are a few things you can do to troubleshoot connection problems:

1. Make sure your username and password are correct.
2. Double-check the hostname. Although “localhost” works on most servers, it may not on yours.
3. Test the connection string (if you wrote the code yourself). You may have a simple typo.
4. If you have your own server, check the mysql server to see if it is running and running without errors.
5. Does the database you are trying to connect to actually exist? Sometimes automatic database creation fails, and you are left wondering why you cannot connect to it.
6. If you can connect locally but cannot connect remotely, check your firewall settings to see if port 3306 (or whichever port you use for mysql) is open.
7. Finally, be sure your mysql user has the necessary privileges to perform whatever task you are trying to accomplish.

Photo Source: Flickr

What is a Linux Package?

posted by Tavis J. Hampton in: VPS & Dedicated Software

Debian package iconQuestion: I have a new Linux dedicated server, and I have read a lot of documentation referring to packages. What are Linux packages?

Answer: In Linux distributions, a “package” refers to a compressed file archive containing all of the files that come with a particular application. The files are usually stored in the package according to their relative installation paths on your system. Most packages also contain installation instructions for the OS, as well as a list of any other packages that are dependencies (prerequisites required for installation.

Common types of Linux packages include .deb, .rpm, and .tgz. Since Linux packages do not usually contain the dependencies necessary to install them, many Linux distributions use package managers that automatically read dependencies files and download the packages needed before proceeding with the installation. Some examples of package managers are APT, YUM, and Pacman.

Friday 09 July 2010

How to Delete Tables and Rows in MySQL

posted by Tavis J. Hampton in: Web servers Software

Mysql logoAs I mentioned in a previous MySQL post, knowing how to quickly perform database tasks from the command line is a good idea if you are a Linux system administrator. Sometimes, it is the easier way to get things done, especially if you are helping another user and need root access to his or her database.

To delete a table, first login to MySQL:

mysql -u root -p

Enter your password and then switch to the database you want to edit by typing the following at the mysql> prompt:

mysql> use [db name];

Finally, drop the table:

mysql> drop table [table name];

Replace [table name] with the actual name of the table you want to remove.

To remove a row, type:

mysql> DELETE from [table name] where [field name] = 'whatever';

When you are finished, type “quit” to exit.

Network Blogo