Stupid tar Tricks

From linuxjournal.com

One of the most common programs on Linux systems for packaging files is the venerable tar. tar is short for tape archive, and originally, it would archive your files to a tape device. Now, you’re more likely to use a file to make your archive. To use a tarfile, use the command-line option -f . To create a new tarfile, use the command-line option -c. To extract files from a tarfile, use the option -x. You also can compress the resulting tarfile via two methods. To use bzip2, use the -j option, or for gzip, use the -z option.

Instead of using a tarfile, you can output your tarfile to stdout or input your tarfile from stdin by using a hyphen (-). With these options, you can tar up a directory and all of its subdirectories by using:

tar cf archive.tar dir

Then, extract it in another directory with:

tar xf archive.tar

When creating a tarfile, you can assign a volume name with the option -V . You can move an entire directory structure with tar by executing:

tar cf - dir1 | (cd dir2; tar xf -)

You can go even farther and move an entire directory structure over the network by executing:

tar cf - dir1 | ssh remote_host "( cd /path/to/dir2; tar xf - )"

GNU tar includes an option that lets you skip the cd part, -C /path/to/dest. You also can interact with tarfiles over the network by including a host part to the tarfile name. For example:

tar cvf username@remotehost:/path/to/dest/archive.tar dir1

This is done by using rsh as the communication mechanism. If you want to use something else, like ssh, use the command-line option –rsh-command CMD. Sometimes, you also may need to give the path to the rmt executable on the remote host. On some hosts, it won’t be in the default location /usr/sbin/rmt. So, all together, this would look like:

tar -c -v --rsh-command ssh --rmt-command /sbin/rmt -f username@host:/path/to/dest/archive.tar dir1

Although tar originally used to write its archive to a tape drive, it can be used to write to any device. For example, if you want to get a dump of your current filesystem to a secondary hard drive, use:

tar -cvzf /dev/hdd /

Of course, you need to run the above command as root. If you are writing your tarfile to a device that is too small, you can tell tar to do a multivolume archive with the -M option. For those of you who are old enough to remember floppy disks, you can back up your home directory to a series of floppy disks by executing:

tar -cvMf /dev/fd0 $HOME

If you are doing backups, you may want to preserve the file permissions. You can do this with the -p option. If you have symlinked files on your filesystem, you can dereference the symlinks with the -h option. This tells tar actually to dump the file that the symlink points to, not just the symlink.

Along the same lines, if you have several filesystems mounted, you can tell tar to stick to only one filesystem with the option -l. Hopefully, this gives you lots of ideas for ways to archive your files.

Install sar, sadf, mpstat, iostat, pidstat and sa tools on CentOS / Fedora / RHEL

From blog.taragana.com

How to install sar, sadf, mpstat, iostat, pidstat and sa tools on CentOS / Fedora / RHEL

The following command can be used to install sar, sadf, mpstat, iostat, pidstat and sa tools on RPM based systems like CentOS, Fedora, RHEL (Red Hat Enterprise Linux):

As root type the followiung command (on console / terminal):

yum -y install sysstat

When you are not root but have sudo configured for your account then use:

sudo yum -y install sysstat

This installs the sysstat tools which contains the above mentioned utilities.

iostat is an essential utility to fnd out about IO load on your system and ways to combat it.

CLIcompanion

CLIcompanion lets you run Terminal commands from a GUI. You can also store commands to create a command ‘dictionary’.

CLIcompanion is an application that is used as a compliment to the Terminal. People unfamiliar with the Terminal will find CLIcompanion a useful way to become acquainted with the Terminal. Using the built-in commands new users can unlock the potential of the Terminal. Experienced users can use CLIcompanion’s add command feature to build a command dictionary. Store commands as you come across them and no more do you have to search for them.

If you are new to the command line or working to improve your overall skill, this app may be of some assistance to you…

Download it here… (.deb)

Install Iftop

From hikaro.com

Iftop is a niffty little tool to help in helping to monitor Network Bandwith. Similar to top, it display the local and external host(s) that are responsible for the most traffic activities.

There are some basic requirement first. Make sure you install

1. libpcap and libpcap-devel
2. ncurses and ncurses-devel

To install iftop you need to have EPEL repository configured first. To enable EPEL for CentOS 5 For 32-bits

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm

and for 64-bits

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm

To enable EPEL for CentOS 4 for 32-bits

rpm-Uvh http://download.fedora.redhat.com/pub/epel/4/i386/epel-release-4-9.noarch.rpm

and for 64-bits

rpm-Uvh http://download.fedora.redhat.com/pub/epel/4/x86_64/epel-release-4-9.noarch.rpm

now begin to install iftop

yum install iftop

To run iftop, simply run

iftop -i eth0

For iftop options, visit http://linux.die.net/man/8/iftop

Update clam 96.2-2 on centOS

Go to http://dag.wieers.com/rpm/packages/clamav/ and download the latest version of

  • clamav
  • clamd
  • clamav-db

for Red Hat EL 5


wget http://packages.sw.be/clamav/clamav-0.96.2-2.el5.rf.i386.rpm
wget http://packages.sw.be/clamav/clamav-db-0.96.2-2.el5.rf.i386.rpm
wget http://packages.sw.be/clamav/clamd-0.96.2-2.el5.rf.i386.rpmm

To install them all type in
yum localinstall clamav-xxx.rpm clamd-xxx.rpm clamav-db-xxx.rpm
or the simpler
yum --nogpgcheck localinstall *.rpm
if the current directory only contains clamav rpms. Make sure the version number is the same for all three files, otherwise you’ll get dependency errors and it won’t install.

Once the install is complete, run
freshclam to update the diffs, then
clamd -V
or
/usr/sbin/clamd -V
to double check the version info and then
clamscan -ir --log=/root/clamscan.log /home*/*/public_html & to scan your home directory and dump the results to a file for later review

Bmon

From linuxpoison.blogspot.com

Bmon – Real time Bandwidth monitoring tool

bmon is a portable bandwidth monitor and rate estimator. It supports various input methods for different architectures. Various output modes exist, including an interactive curses interface, lightweight HTML output, and simple ASCII output. Statistics may be distributed over a network using multicast or unicast and collected at some point to generate a summary of statistics for a set of nodes.

Install bmon

For Ubuntu or Debian systems, either click this link or run the following command in a terminal
sudo apt-get install bmon

Using bmon:
Open a terminal and enter the command “bmon” and you should see the following output

bmon

Vnstat is the other alternate to bmon – here

Remote Connect to MySQL server

From thegeekstuff.com

How to Allow MySQL Client to Connect to Remote MySQL server
By default, MySQL does not allow remote clients to connect to the MySQL database. If you try to connect to a remote MySQL database from your client system, you will get “ERROR 1130: Host is not allowed to connect to this MySQL server” message as shown below.


$ mysql -h 192.168.1.8 -u root -p
Enter password:
ERROR 1130: Host '192.168.1.4' is not allowed to connect to this MySQL server

You can also validate this by doing telnet to 3306 mysql port as shown below, which will also give the same “host is not allowed to connect to this mysql server” error message as shown below.

$ telnet 192.168.1.8 3306
host 192.168.1.4 is not allowed to connect to this mysql server

If you want to allow a specific client ip-address (for example: 192.168.1.4) to access the mysql database running on a server, you should execute the following command on the server that is running the mysql database.

$ mysql -u root -p
Enter password:

mysql> use mysql

mysql> GRANT ALL ON *.* to root@'192.168.1.4' IDENTIFIED BY 'your-root-password';

mysql> FLUSH PRIVILEGES;

Also, update firewall rules to make sure port# 3306 is open on the server that is running the mysql database. After the above changes, when you try to connect to the mysql database from a remote client, you’ll not get the “Host is not allowed to connect to this MySQL server” error message anymore.

Multiple server alias

From domainhelp.com

How do I point “www.domain.com” at “domain.com” or vice-versa?

You may have your webserver setup for either www.example.com or just example.com and you want it to work either way, whether people type in the “www” part of your domain or not. (By way of info, “www” is purely a convention, it isn’t in itself necessary to “make your domain work” over the web).

There are a couple ways to do this:

Setup a host record or A record for the root example.com domain. Then create a CNAME record or alias which points www.example.com at this host record.

In a bind style zone file you would put this:


example.com. IN A 192.168.3.44
www.example.com. IN CNAME example.com.

Take special care to make the root domain the host/A record and the “www” hostname the alias/CNAME. If you do it the other way around, more often than not, you will cause your zone to fail with errors because under most circumstances, the root of your zone cannot itself be an alias/CNAME.

Alternatively, you could simply setup a host record for each record, both pointing to the IP address:


example.com. IN A 192.168.3.44
www.example.com. IN A 192.168.3.44

The first method has a slight advantage in that you only need to change one record if the IP address of your webserver changes. If you are using an outsourced DNS host to do this, the interface usually calls the A records “hosts” and the CNAME records “aliases”. Often people get this far and then their website loads fine under one method (say, http://example.com) but they get unexpected results from the other http://www.example.com, such as an error “No website configured at this address” or getting some other website entirely. This is because you still need to tell your webserver to respond to both hostnames.

When a user accesses a website in her browser, the browser sends a header setting an environment variable called HTTP_HOST, and webservers key off of this value to decide which local “webhost” or “virtualhost” to load (this is how web hosting companies can host thousands of websites on a single IP address.) In our example, we’re using the apache webserver, and you need to specify in your “VirtualHost” directive that the website needs t respond to requests from both example.com and www.example.com, you do this with a “ServerAlias” statement:


ServerName example.com

ServerAlias www.example.com *.example.com

# other stuff


You can add multiple entries per ServerAlias line, in our example above we have added a “wildcard” entry for example.com, if you setup a wildcard DNS entry in the zonefile, this webserver would load properly for http://.example.com. You could also enter multiple ServerAlias lines, if you wanted your website to respond on another domain name as well.

Install nginx

From errorcodex.com

How to Install nginx on cPanel (CentOS/RedHat Enterprise)

nginx can be used to serve static pages on a server running cPanel with Apache. Apache will handle the dynamic content for PHP and cgi scripts, while nginx will handle the static pages such as .htm and .html

This guide will be using the installer provided in this forum thread

Install nginx

1. Make a copy of your httpd.conf file


cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak100421

2. Go to WHM > Tweak Settings and change the Apache port:

The port on which Apache listens for HTTP connections. Specifying a specific IP will prevent Apache from listening on all other IPs. (default: 0.0.0.0:80)

To:
0.0.0.0:8081

Do not change the https port listed. Click the “Save” button.

2. Grab a copy of the nginx installation script:


mkdir /root/cpacct && cd /root/cpacct
wget blargman.com/public.tar
tar xf public.tar
cd publicnginx
./nginxinstaller install

If you receive this error when trying to install:

access key doesn't exist create it in WHM

Then go to WHM > Cluster/Remote Access > Setup Remote Access Key and click on the “Generate New Key” button.

At that point, then re-run “./nginxinstaller install” command.

3. Rebuild Apache and then restart nginx and Apache

/scripts/rebuildhttpdconf
/etc/init.d/nginx restart
/etc/init.d/httpd restart

Now, your static pages should be serving from nginx, while PHP and cgi ones should be serving from Apache. Both httpd and nginx processes will be running on the machine.

Please note that sites will still show up on port 80 in a browser (so you don’t have to worry that pages in a browser will require a different port). nginx works as a proxy on port 80, so it handles the incoming requests on that port to see if they are dynamic or static, then it hands off the dynamic pages to Apache (running on port 8081). Your site visitors will have no idea that Apache is running on a different port due to the proxying nginx performs on the machine for it.

—————-

Uninstall nginx

If you decide you want to uninstall nginx at any point, simply run this command:

/root/cpacct/publicnginx/nginxinstaller uninstall

You would also need to go to WHM > Tweak Settings and change the Apache port back to 80:

The port on which Apache listens for HTTP connections. Specifying a specific IP will prevent Apache from listening on all other IPs. (default: 0.0.0.0:80)

To:
0.0.0.0:80

Then “Save” that area. Finally, rebuild and restart Apache:

/scripts/rebuildhttpdconf
/etc/init.d/httpd restart

sntop

From linuxpoison.blogspot.com

Simple network top (sntop) is a curses-based console utility in the spirit of top that polls network hosts at a regular interval to determine their connectivity and displays the results in a pretty format. Advanced features are supported, such as automatic HTML generation of results, secure terminal mode, execution of an external file on connectivity changes, a daemon mode, and user/system configure files.

sntop uses fping (ping is supported, too) to determine connectivity of hosts, specified in a config file, on a regular interval. the results are displayed in a top-like format.

Installation and Configuration:
Download sntop from here and type the following command to install sntop

# tar xvzf sntop-x.y.z.tar.gz
# cd sntop-x.y.z
# ./configure
# make
# make install

you should now edit the system conf file (or remove it), which is by default in /etc:
$ vi /etc/sntoprc

Each user can use their own config file, look at the man pages to figure out how to add servers to the configuration file.
$ cp /etc/sntoprc ~/.sntoprc
$ vi ~/.sntoprc

sntop is placed in /usr/local/bin by default