How to create a symlink in the Linux command console?
->
ln -s <destination> <linkname>
If the desired link filename is the same as the destination's filename, and the current working directory is the desired location for the link, then you only need:
ln -s <destination>
A symbolic link (also symlink or soft link) is a special type of file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution. Symbolic links were already present by 1978 in mini-computer operating systems from DEC and Data General's RDOS.
Today they are supported by the POSIX operating-system standard, most Unix-like operating systems such as FreeBSD, GNU/Linux, and Mac OS X, and also Windows operating systems such as Windows Vista, Windows 7 and to some degree in Windows 2000 and Windows XP.Symbolic links operate transparently for most operations: programs which read or write to files named by a symbolic link will behave as if operating directly on the target file. However, programs that need to handle symbolic links specially (e.g., backup utilities) may identify and manipulate them directly.
How to Open rar file or Extract rar files under Linux or UNIX
->
RAR files are in compressed archive format, if you have downloaded rar files from the Internet, you need to unpack or unrar them (extract rar files).RAR is a proprietary file format for data compression and archiving, developed by Eugene Roshal.Under Linux and UNIX, use command called unrar. By default unrar is not being installed on Linux, FreeBSD or UNIX oses. You can install unrar command with the help of apt-get or yum command.
Install unrar command
Under Debian Linux, you need to type apt-get as follows to install unrar program:
# apt-get install unrar
If you are using Fedora core Linux then use yum command as follows (see discussion below):
# yum install unrar
If you are using FreeBSD, use:
# pkg_add -v -r unrar
If any of above, methods is not working for you, download binary package from official rarlab site:
$ cd /tmp
$ wget http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz
Untar file
$ tar -zxvf rarlinux-3.6.0.tar.gz
Both unrar and rar commands are located in rar sub-directory. Just go to rar directory:
$ cd rar
$ ./unrar
Now copy rar and unrar to /bin directory:
# cp rar unrar /bin
How to use unrar
unrar command supports various options below are common options that you need to use everyday.
Task: To open rar (unpack) file in current directory type command:
$ unrar e file.rar
Please note that replace file.rar filename with your actual filename.
Task: List (l) file inside rar archive:
$ unrar l file.rar
Task: To extract (x) files with full path type command:
$ unrar x file.rar
(D) To test (t) integrity of archive, file type command:
$ unrar t file.rar
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 determine which sevices are enabled at boot time in linux
How do I find out which services are enabled at Boot under Ubuntu/CentOS/RHEL/Fedora Linux? How can I disable a service which is not needed or I dont want to run every time the linux machine starts?
Open terminal and login as root user.
Type the following command to list all services which are enabled at boot:
#chkconfig --list | grep $(runlevel | awk '{ print $2}'):on
Sample output:
acpid 0:off 1:off 2:off 3:on 4:on 5:on 6:off anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off dkms_autoinstaller 0:off 1:off 2:on 3:on 4:on 5:on 6:off haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off hidd 0:off 1:off 2:on 3:on 4:on 5:on 6:off irqbalance 0:off 1:off 2:on 3:on 4:on 5:on 6:off kudzu 0:off 1:off 2:off 3:on 4:on 5:on 6:off lighttpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off lm_sensors 0:off 1:off 2:on 3:on 4:on 5:on 6:off lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off mcstrans 0:off 1:off 2:on 3:on 4:on 5:on 6:off mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off messagebus 0:off 1:off 2:off 3:on 4:on 5:on 6:off microcode_ctl 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off named 0:off 1:off 2:on 3:on 4:on 5:on 6:off netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off pcscd 0:off 1:off 2:on 3:on 4:on 5:on 6:off psacct 0:off 1:off 2:on 3:on 4:on 5:on 6:off readahead_early 0:off 1:off 2:on 3:on 4:on 5:on 6:off restorecond 0:off 1:off 2:on 3:on 4:on 5:on 6:off rhnsd 0:off 1:off 2:on 3:on 4:on 5:on 6:off rpcgssd 0:off 1:off 2:off 3:on 4:on 5:on 6:off rpcidmapd 0:off 1:off 2:off 3:on 4:on 5:on 6:off sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off setroubleshoot 0:off 1:off 2:off 3:on 4:on 5:on 6:off smartd 0:off 1:off 2:on 3:on 4:on 5:on 6:off snmpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off xfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off yum-updatesd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
The first column of above output is the name of a service which is currently enabled at boot. You need to review each service.
Task: Disable services
To stop service, enter:
# service {service-name} stop # service vmware stop
To disable service, enter:
# chkconfig {service-name} off # chkconfig vmware off
You may also use ntsysv command to manage all services.
A note about outdated insecure service
All of the following services must be disabled to improve server security:
- Inetd and Xinetd (inetd xinetd) - Use direct services configured via SysV and daemons.
- Telnet (telnet-server) - Use ssh
- Rlogin, Rsh, and Rcp ( rsh-server ) - Use ssh and scp.
- NIS (ypserv) : Use OpenLDAP or Fedora directory server.
- TFTP (tftp-server) : Use SFTP or SSH.
To delete all of the service enter:
# yum erase inetd xinetd ypserv tftp-server telnet-server rsh-serve
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
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)