Installing vnstat
->
Step 1: Installing vnstat
cd /usr/local/src
wget http://humdi.net/vnstat/vnstat-1.6.tar.gz
tar -zxvf vnstat-1.6.tar.gz
cd vnstat-1.6
make && make install
vnstat -u -i eth0
Step 2: Making vnstat root only
chmod 700 /usr/bin/vnstat
chmod 700 /var/lib/vnstat/ -R
Step 3: Now you can check the stats, use help for possbible commands
vnstat --help
How to view or display a logfile in real time on screen in linux
->
How do I see the log file in real time including all incoming logs as well?
You can use the tail command in linux command line which outputs the last part of files in real time including all incoming logs to a file. So you can view the last parts of your logs file (like access logs for the server) using this in real time!
Note: you may need to login as root user to view log files.
Command
tail -f file-name command
If your log file name is /var/log/lighttpd/access.log, enter:
tail -f /var/log/lighttpd/access.log
If your php log file name is /var/log/lighttpd/scripts.log, enter
tail -f /var/log/lighttpd/scripts.log
You will get a scrolling view of the /var/log/lighttpd/scripts.log for all incoming entries on screen. To stop simply hit CTRL+C.
Ubuntu / Debian Linux: Install Monit Linux Server Monitoring Utility
How do I install monit to monitor my server under Debian / Ubuntu Linux?
Monit is a utility for managing and monitoring processes, files, directories and devices on a Debian / Ubuntu Linux server system. Here a few common uses of monit:
- Monit can start a process if it does not run
- Restart a process if it does not respond
- Stop a process if it uses to much resources etc
How do I install monit utility for monitoring services?
Type the following command as the root user:
$ sudo apt-get update $ sudo apt-get install monit
Configure monit
Open monit configuration file /etc/monit/monitrc using vi text editor or nano command in linux:
# vi /etc/monit/monitrc
OR
# nano /etc/monit/monitrc
You need to set following parameters:
set daemon 120 set logfile syslog facility log_daemon set mailserver localhost # primary mailserver set alert vivek@nixcraft.com # receive all alerts
The next step is to save and close this file. Where,
- set daemon 120 : Start monit in background as daemon and check the services at 2-minute intervals.
- set logfile syslog facility log_daemon : Log messages in /var/log/messsages file
- set mailserver localhost : Send email alert via localmail server such as sendmail. Set list of mailservers for alert delivery. Multiple servers may be specified using comma separator. By default monit uses port 25 - it is possible to override it with the PORT option.
- set alert vivek@nixcraft.com : You can set the alert recipients here, which will receive the alert for each service. The event alerts may be restricted using the list.
Now open /etc/default/monit file to turn on monit service:
# vi /etc/default/monit
OR
# nano /etc/default/monit
Set startup to 1, so monit can start:
startup=1
Save and close the file.
Start the monit Linux monitor tool / service:
# /etc/init.d/monit start
Enable Read Only Mode on a MySQL server
Here are some useful options that can prevent writing to MySQL databases, while retaining the right reading.
The activation of these features may be particularly interesting in the case of a change of server. You can then export and import all data from one server to another, being sure to maintain data integrity. As for customers, they can only read data.
1. Method by changing a variable server
To do this, connect to the server with root user:
mysql-h localhost-u root-p
and run the command:
mysql> set GLOBAL read_only = true;
The data in all databases are accessible only for reading. Note that root guard on the other hand always have the right to write.
Example of inserting data with a simple user:
mysql> INSERT INTO foo VALUES ( 'tata2');
ERROR 1290 (HY000): The MySQL server is running with the-read-only
option so it can not execute this statement
To disable this mode, you can then run the following command:
mysql> set GLOBAL read_only = false;
2. Method of positioning locks
There is also a second method is to put locks via:
mysql> FLUSH TABLES WITH READ LOCK;
The latter will then close all open tables and locks all the reading tables and bases.
At this time, applications that wish to make an entry will be queued until the unlock command:
mysql> UNLOCK TABLES;
It will be possible to see a list of requests waiting in the listing process as follows:
mysql> SHOW processlist;
| 5 | root | localhost | test | Query | 160 | Waiting for release of readlock | INSERT INTO foo VALUES ( 'tata2') |
Conclusion
The first method seems more adapted when transferring data from one MySQL server to another, while the second plutût it will be used in case of a backup cold.
How to Stop/Restart Lighttpd Web Server in Debian / Ubuntu / FreeBSD linux
/etc/init.d/lighttpd is a script under Linux to stop / restart lighttpd web server.
To stop lighttpd:
Use the following command to stop lighttpd:
# /etc/init.d/lighttpd stop
To restart lighttpd:
Just type the following command to restart lighttpd:
# /etc/init.d/lighttpd restart
To start lighttpd:
# /etc/init.d/lighttpd start
Debian / Ubuntu Linux Start lighttpd
# /etc/init.d/lighttpd start
Debian / Ubuntu Linux - Stop lighttpd
# /etc/init.d/lighttpd stop
Debian / Ubuntu Linux - Restart lighttpd
# /etc/init.d/lighttpd restart
FreeBSD Start lighttpd web server
# /usr/local/etc/rc.d/lighttpd start
FreeBSD - Stop lighttpd webserver
# /usr/local/etc/rc.d/lighttpd stop
FreeBSD - Restart lighttpd webserver
# /usr/local/etc/rc.d/lighttpd restart
In case if you don't have init script, type the following:
# killall lighttpd
Ubuntu Linux Start / Restart / Stop Apache 2.2 Web Server
Q. How to restart or stop Apache 2.2 web server under Ubuntu Linux?
Task: Start Apache 2.2 Server
# /etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start
Task: Restart Apache 2.2 Server
# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart
Task: Stop Apache 2.2 Server
# /etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop
Apache performance tips
If you run the command top on your box and the CPU is mostly idle and there is plenty of memory available, and yet Apache seemed sluggish. Here are a couple of things I would recommend to speed things up.
1. Increase MaxClients and ServerLimit
This is a well-known Apache performance optimization tip. Its effect is to increase the number of httpd processes available to service the HTTP requests.
However, when I tried to increase MaxClients over 256 in the prefork.c directives and I restarted Apache, I got a message such as:
WARNING: MaxClients of 1000 exceeds ServerLimit value of 256 servers, lowering MaxClients to 256. To increase, please see the ServerLimit directive.
There is no ServerLimit entry by default in httpd.conf, so I proceeded to add one just below the MaxClients entry. I restarted httpd, and I still got the message above. The 2 entries I had in httpd.conf in the IfModule prefork.c section were:
ServerLimit 1000
MaxClients 1000
(make sure that serverlimit comes before maxclients)
At this point I resorted to all kinds of Google searches in order to find out how to get past this issue, only to notice after a few minutes that the number of httpd processes HAD been increased to well over the default of 256!
Note: It turns out that the new MaxClient and ServerLimit values take effect only if you stop httpd then start it back again. Just doing a restart doesn't do the trick...
So, lesson learned? Always double-check your work and, most importantly, know when to ignore warnings 🙂
Now I have a procedure for tuning the number of httpd processes on a given box:
1. Start small, with the default MaxClients (150).
2. If Apache seems sluggish, start increasing both MaxClients and ServerLimit; restart httpd every time you do this.
3. Monitor the number of httpd processes; you can use something like:
ps -def | grep httpd | grep -v grep | wc -l
If the number of httpd processes becomes equal to the MaxClients limit you specified in httpd.conf, check your CPU and memory (via top or vmstat). If the system is not yet overloaded, go to step 2. If the system is overloaded, it's time to put another server in the server farm behind the load balancer.
That's it for now. There are many other Apache performance tuning tips that you can read from the official Apache documentation here.
How to install webmin on your Linux web server (Redhat Fedora Caldera Mandrake SuSE MSC)
Installing webmin on your linux webserver is easy. With webmin, you can use ispconfig which is a web hosting script that you can use to host many website in one server.
Webmin website: http://www.webmin.com/
Since I have fedora I can install like this:
(this tutorial is suitable for Redhat, SuSE, Caldera, Mandrake or MSC Linux, 13M)
Login to your shell, i will be using ssh so i send this command:
wget http://prdownloads.sourceforge.net/webadmin/webmin-1.350-1.noarch.rpm
Once it has finished downloadin i send this command:
rpm -U webmin-1.350-1.noarch.rpm
(make sure to use upper case U above)
The rest of the install will be done automatically to the directory /usr/libexec/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/ .
Webmin install complete. You can now login to https://hostname.domain:10000/
as root with your root password.
NOTE: the default login and password is your root and root password. this is the same login you used with you ssh to your server or whatever your root password is, so your login will be like this:
Username: root
Password: xxxx (what ever your root password is)
Star / Stop / Restart Apache 2 Web Server
Q. How do I restart Apache 2 Web Server under Debian / Ubuntu Linux?
A. Apache is primarily used to serve both static content and dynamic Web pages on the World Wide Web. Many web applications are designed expecting the environment and features that Apache provides.
First, login to server using ssh. To ssh to your server, you will need to a ssh client like putty (download putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html).
The ssh client will need you to enter the IP, username and password of your server. Choose port as 22.
Once logged in type the following commands as need be.
How To start Apache 2 web server, enter:
# /etc/init.d/apache2 startOR
$ sudo /etc/init.d/apache2 startLinux Command to restart Apache 2 web server, enter:
# /etc/init.d/apache2 restartIf you are using Ubuntu use sudo:
$ sudo /etc/init.d/apache2 restartHow To stop Apache 2 web server, enter:
# /etc/init.d/apache2 stopOR
$ sudo /etc/init.d/apache2 stop