Monday, February 24, 2014

Install and Configure Webmin & Virtualmin on CentOS



Download Webmin RPM
Webmin rpms are available on its official site. Download it from there or use below command to download.
# cd /opt
# wget http://prdownloads.sourceforge.net/webadmin/webmin-1.660-1.noarch.rpm
Step 2: Install Webmin Using rpm Command
Use following command to install webmin.
# rpm -Uvh webmin-1.660-1.noarch.rpm
Step 3: Access Webmin in Browser
Webmin by default works on port 10000. Access your server on port 10000 using FQDN or IP, and login with username root and system root password.
http://IP:10000/
 

How to Start/Stop Webmin Service

Webmin provides an init script to start or stop its service. Use below commands to do it.
# /etc/init.d/webmin start
# /etc/init.d/webmin stop
# /etc/init.d/webmin restart
# /etc/init.d/webmin status

How to Change/Reset Webmin root Password

In order to change webmin root account password use following command. ( Note: It will not change your systems root password )
# /usr/libexec/webmin/changepass.pl /etc/webmin root secretpassword

How to Change Webmin default Port

If you do not want to run webmin with default port, use below steps to change the default port.
Login Webmin as root >> Webmin >> Webmin Configuration >> Ports and Addresses… you can change port there.

Using the Webmin YUM repository

If you like to install and update Webmin via RPM, create the /etc/yum.repos.d/webmin.repo file containing :
[Webmin]
name=Webmin Distribution Neutral
#baseurl=http://download.webmin.com/download/yum
mirrorlist=http://download.webmin.com/download/yum/mirrorlist
enabled=1
 You should also fetch and install my GPG key with which the packages are signed, with the commands :
 wget http://www.webmin.com/jcameron-key.asc


rpm --import jcameron-key.asc
 You will now be able to install with the command :
 yum install webmin All dependencies should be resolved automatically.

CentOS - Installing VirtualMin

Update System

First we will update the system to ensure that we have all of the latest software installed.
# sudo yum -y update

Install pre-requisites

We need to install a few things before VirtualMin will install. Type the following:
# sudo yum -y install perl

Download VirtualMin Installer

Now we need to download the VirtualMin installer. Type the following to download it:
 # wget http://software.virtualmin.com/gpl/scripts/install.sh

Installation

Now it is time to install VirtualMin. To do so, use the command below:
# sudo sh install.sh
You will be prompted with a license agreement. Press Y followed by Enter to continue.
It will begin performing several checks and installing the required components.
Once it has completed you should see a line similar to the following:
ssapi mod_ssl ruby ruby-devel rubygems perl-XML-Simple perl-Crypt-SSLeay: Succeeded.

Logging In

You are now ready to log into your VirtualMin console. To do this point your web browser to https://IP:10000/ where you will be prompted with a login screen On your first login use the username root and type in your root password.

Post Setup Wizard

Once you login you will be prompted with a Post Setup Wizard. Click Next.

You will be prompted if you would like to pre-load certain libraries. Click Yes and then Next.

You will be prompted if you would like to run ClamAV virus scanner on your server. It is suggested that you select Yes and click Next.

You will be prompted if you would like to run the SpamAssassin e-mail spam scanner. If you are not running e-mail services it is not necessary to run this. However if you are hosting e-mail it is highly advised. Click Yes and Next if you are going to use SpamAssassin, otherwise click Next.
Next you will be prompted if you would like to run MySQL and/or PostgreSQL servers. This is entirely up to you as to which database servers you will provide to your customers (if any). Select your options and click Next. You will be prompted on the following screens for password information.

Once finished, you will be presented with an 'All Done' page. Click Next.

Once the main page loads you will need to reload your configuration. Click the Re-check and refresh configuration button in the yellow box.

Information related rpm



  Install : It is used to install any RPM package.
  Remove : It is used to erase, remove or un-install any RPM package.
  Upgrade : It is used to update the existing RPM package.
  Verify : It is used to query about different RPM packages.
  Query : It is used for the verification of any RPM package

1. How to Check an RPM Signature Package

Always check the PGP signature of packages before installing them on your Linux systems and make sure its integrity and origin is OK. Use the following command with checksig (check signature) option to check the signature of a package called pidgin.
[root@arun]# rpm --checksig pidgin-2.7.9-5.el6.2.i686.rpm
 
pidgin-2.7.9-5.el6.2.i686.rpm: rsa sha1 (md5) pgp md5 OK

RPM command and options
  1. -i : install a package
  2. -v : verbose for a nicer display
  3. -h: print hash marks as the package archive is unpacked.

3. How to check dependencies of RPM Package before Installing

Let’s say you would like to do a dependency check before installing or upgrading a package. For example, use the following command to check the dependencies of BitTorrent-5.2.2-1-Python2.4.noarch.rpm package. It will display the list of dependencies of package.
[root@arun]# rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm

RPM command and options
  1. -q : Query a package
  2. -p : List capabilities this package provides.
  3. -R: List capabilities on which this package depends..

4. How to Install a RPM Package Without Dependencies

If you know that all needed packages are already installed and RPM is just being stupid, you can ignore those dependencies by using the option nodeps (no dependencies check) before installing the package.
[root@arun]# rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm
 

7. How to List Recently Installed RPM Packages

Use the following rpm command with -qa (query all) option, will list all the recently installed rpm packages.
[root@arun]# rpm -qa --last
 

10. How to Remove a RPM Package

To un-install an RPM package, for example we use the package name nx, not the original package name nx-3.5.0-2.el6.centos.i686.rpm. The -e (erase) option is used to remove package.
[root@arun]# rpm -evv nx

11. How to Remove an RPM Package Without Dependencies

The nodeps (Do not check dependencies) option forcefully remove the rpm package from the system. But keep in mind removing particular package may break other working applications.
[root@arun]# rpm -ev --nodeps vsftpd

12. How to Query a file that belongs which RPM Package

Let’s say, you have list of files and you would like to find out which package belongs to these files. For example, the following command with -qf (query file) option will show you a file /usr/bin/htpasswd is own by package httpd-tools-2.2.15-15.el6.centos.1.i686.
[root@arun]# rpm -qf /usr/bin/htpasswd
 

20. How To rebuild Corrupted RPM Database

Sometimes rpm database gets corrupted and stops all the functionality of rpm and other applications on the system. So, at the time we need to rebuild the rpm database and restore it with the help of following command.
[root@arun]# cd /var/lib
[root@arun]# rm __db*
[root@arun]# rpm --rebuilddb
[root@arun]# rpmdb_verify Packages



1. Uptime Command

In Linux uptime command shows since how long your system is running and the number of users are currently logged in and also displays load average for 1,5 and 15 minutes intervals.

# uptime

08:16:26 up 22 min,  1 user,  load average: 0.00, 0.03, 0.22

Check Uptime Version

Uptime command don’t have other options other than uptime and version. It gives information only in hours:mins if it less than 1 day.

[arun@arun ~]$ uptime -V
procps version 3.2.8

2. W Command

It will displays users currently logged in and their process along-with shows load averages. also shows the login name, tty name, remote host, login time, idle time, JCPU, PCPU, command and processes.

# w

08:27:44 up 34 min,  1 user,  load average: 0.00, 0.00, 0.08
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
arun  pts/0    192.168.50.1     07:59    0.00s  0.29s  0.09s w

Available options
  1. -h : displays no header entries.
  2. -s : without JCPU and PCPU.
  3. -f : Removes from field.
  4. -V : (upper letter) – Shows versions.
3. Users Command
Users command displays currently logged in users. This command don’t have other parameters other than help and version.
# users

root
4. Who Command
who command simply return user name, date, time and host information. who command is similar to w command. Unlike w command who doesn’t print what users are doing. Lets illustrate and see the different between who and w commands.
# who

arun  pts/0        2012-09-18 07:59 (192.168.50.1)
# w

08:43:58 up 50 min,  1 user,  load average: 0.64, 0.18, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
arun  pts/0    192.168.50.1     07:59    0.00s  0.43s  0.10s w
Who command Options
  1. -b : Displays last system reboot date and time.
  2. -r : Shows current runlet.
  3. -a, –all : Displays all information in cumulatively.
5. Whoami Command
whoami command print the name of current user. You can also use “who am i” command to display the current user. If you are logged in as a root using sudo command “whoami” command return root as current user. Use “who am i” command if you want to know the exact user logged in.
# whoami

arun
6. ls Command
ls command display list of files in human readable format.
# ls -l

total 114
dr-xr-xr-x.   2 root root  4096 Sep 18 08:46 bin
dr-xr-xr-x.   5 root root  1024 Sep  8 15:49 boot

Sort file as per last modified time.
# ls -ltr

total 40
-rw-r--r--. 1 root root  6546 Sep 17 18:42 install.log.syslog
-rw-r--r--. 1 root root 22435 Sep 17 18:45 install.log
-rw-------. 1 root root  1003 Sep 17 18:45 anaconda-ks.cfg
Crontab Command
List schedule jobs for current user with crontab command and -l option.
# crontab -l

00 10 * * * /bin/ls >/ls.txt
Edit your crontab with -e option. In the below example will open schedule jobs in VI editor. Make a necessary changes and quit pressing :wq keys which saves the setting automatically.
# crontab -e
For more examples of Linux Cron Command, please read our earlier article on 11 Cron Scheduling Task Examples in Linux.
8. Less Command
less command allows quickly view file. You can page up and down. Press ‘q‘ to quit from less window.
# less install.log

Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
9. More Command
more command allows quickly view file and shows details in percentage. You can page up and down. Press ‘q‘ to quit out from more window.
# more install.log

Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
--More--(10%)
10. CP Command
Copy file from source to destination preserving same mode.
# cp -p fileA fileB
You will be prompted before overwrite to file.
# cp -i fileA fileB
11. MV Command
Rename fileA to fileB. -i options prompt before overwrite. Ask for confirmation if exist already.
# mv -i fileA fileB
12. Cat Command
cat command used to view multiple file at the same time.
# cat fileA fileB
You combine more and less command with cat command to view file contain if that doesn’t fit in single screen / page.
# cat install.log | less

# cat install.log | more
13. Cd command (change directory)
with cd command (change directory) it will goes to fileA directory.
# cd /fileA
14. pwd command (print working directory)
pwd command return with present working directory.
# pwd

/root
15. Sort command
Sorting lines of text files in ascending order. with -r options will sort in descending order.
#sort fileA.txt

#sort -r fileA.txt
16. VI Command
Vi is a most popular text editor available most of the UNIX-like OS. Below examples open file in read only with -R option. Press ‘:q‘ to quit from vi window.
# vi -R /etc/shadows
17. SSH Command (Secure Shell)
SSH command is used to login into remote host. For example the below ssh command will connect to remote host (192.168.50.2) using user as user.
# ssh user@192.168.50.2
To check the version of ssh use option -V (uppercase) shows version of ssh.
# ssh -V

OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
18. Ftp or sftp Command
ftp or sftp command is used to connect to remote ftp host. ftp is (file transfer protocol) and sftp is (secure file transfer protocol). For example the below commands will connect to ftp host (192.168.50.2).
# ftp 192.168.50.2

# sftp 192.168.50.2
Putting multiple files in remote host with mput similarly we can do mget to download multiple files from remote host.
# ftp > mput *.txt

# ftp > mget *.txt
19. Service Command
Service command call script located at /etc/init.d/ directory and execute the script. There are two ways to start the any service. For example we start the service called httpd with service command.
# service httpd start
OR
# /etc/init.d/httpd start
20. Free command
Free command shows free, total and swap memory information in bytes.
# free
             total       used       free     shared    buffers     cached
Mem:       1030800     735944     294856          0      51648     547696
-/+ buffers/cache:     136600     894200
Swap:      2064376          0    2064376
Free with -t options shows total memory used and available to use in bytes.
# free -t
             total       used       free     shared    buffers     cached
Mem:       1030800     736096     294704          0      51720     547704
-/+ buffers/cache:     136672     894128
Swap:      2064376          0    2064376
Total:     3095176     736096    2359080
21. Top Command
top command displays processor activity of your system and also displays tasks managed by kernel in real-time. It’ll show processor and memory are being used. Use top command with ‘u‘ option this will display specific User process details as shown below. Press ‘O‘ (uppercase letter) to sort as per desired by you. Press ‘q‘ to quit from top screen.
# top -u arun

top - 11:13:11 up  3:19,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 116 total,   1 running, 115 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1030800k total,   736188k used,   294612k free,    51760k buffers
Swap:  2064376k total,        0k used,  2064376k free,   547704k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
1889 arun   20   0 11468 1648  920 S  0.0  0.2   0:00.59 sshd
1890 arun   20   0  5124 1668 1416 S  0.0  0.2   0:00.44 bash
6698 arun   20   0 11600 1668  924 S  0.0  0.2   0:01.19 sshd
6699 arun   20   0  5124 1596 1352 S  0.0  0.2   0:00.11 bash
22. Tar Command
tar command is used to compress files and folders in Linux. For example the below command will create a archive for /home directory with file name as archive-name.tar.
# tar -cvf archive-name.tar /home
To extract tar archive file use the option as follows.
# tar -xvf archive-name.tar
23. Grep Command
grep search for a given string in a file. Only arun user displays from /etc/passwd file. we can use -i option for ignoring case sensitive.
# grep arun /etc/passwd

arun:x:500:500::/home/arun:/bin/bash
24. Find Command
Find command used to search files, strings and directories. The below example of find command search arun word in ‘/‘ partition and return the output.
# find / -name arun

/var/spool/mail/arun
/home/arun
/root/home/arun
25. lsof Command
lsof mean List of all open files. Below lsof command list of all opened files by user arun.
# lsof -u arun

COMMAND  PID    USER   FD   TYPE     DEVICE SIZE/OFF   NODE NAME
sshd    1889 arun  cwd    DIR      253,0     4096      2 /
sshd    1889 arun  txt    REG      253,0   532336 298069 /usr/sbin/sshd
sshd    1889 arun  DEL    REG      253,0          412940 /lib/libcom_err.so.2.1
sshd    1889 arun  DEL    REG      253,0          393156 /lib/ld-2.12.so
sshd    1889 arun  DEL    REG      253,0          298643 /usr/lib/libcrypto.so.1.0.0
sshd    1889 arun  DEL    REG      253,0          393173 /lib/libnsl-2.12.so
sshd    1889 arun  DEL    REG      253,0          412937 /lib/libkrb5support.so.0.1
sshd    1889 arun  DEL    REG      253,0          412961 /lib/libplc4.so
26. last command
With last command we can watch user’s activity in the system. This command can execute normal user also. It will display complete user’s info like terminal, time, date, system reboot or boot and kernel version. Useful command to troubleshoot.
# last

arun  pts/1        192.168.50.1     Tue Sep 18 08:50   still logged in
arun  pts/0        192.168.50.1     Tue Sep 18 07:59   still logged in
reboot   system boot  2.6.32-279.el6.i Tue Sep 18 07:54 - 11:38  (03:43)
root     pts/1        192.168.50.1     Sun Sep 16 10:40 - down   (03:53)
root     pts/0        :0.0             Sun Sep 16 10:36 - 13:09  (02:32)
root     tty1         :0               Sun Sep 16 10:07 - down   (04:26)
reboot   system boot  2.6.32-279.el6.i Sun Sep 16 09:57 - 14:33  (04:35)
narad    pts/2        192.168.50.1     Thu Sep 13 08:07 - down   (01:15)
You can use last with username to know for specific user’s activity as shown below.
# last arun

arun  pts/1        192.168.50.1     Tue Sep 18 08:50   still logged in
arun  pts/0        192.168.50.1     Tue Sep 18 07:59   still logged in
arun  pts/1        192.168.50.1     Thu Sep 13 08:07 - down   (01:15)
arun  pts/4        192.168.50.1     Wed Sep 12 10:12 - 12:29  (02:17)
27. ps command
ps command displays about processes running in the system. Below example show init process only.
# ps -ef | grep init

root         1     0  0 07:53 ?        00:00:04 /sbin/init
root      7508  6825  0 11:48 pts/1    00:00:00 grep init
28. kill command
Use kill command to terminate process. First find process id with ps command as shown below and kill process with kill -9 command.
# ps -ef | grep init
root         1     0  0 07:53 ?        00:00:04 /sbin/init
root      7508  6825  0 11:48 pts/1    00:00:00 grep init

# kill- 9 7508
29. rm command
rm command used to remove or delete a file without prompting for confirmation.
# rm filename
Using -i option to get confirmation before removing it. Using options ‘-r‘ and ‘-f‘ will remove the file forcefully without confirmation.
# rm -i test.txt

rm: remove regular file `test.txt'?
30. mkdir command example.
mkdir command is used to create directories under Linux.
# mkdir directoryname

Display of Top Command
In this example, it will show information like tasks, memory, cpu and swap. Press ‘q‘ to quit window.
# top

Linux Top Command
2. Sorting with -O (Uppercase Letter ‘O’).
Press (Shift+O) to Sort field via field letter, for example press ‘a‘ letter to sort process with PID (Process ID).
Sorting Process ID’s with Top
Type any key to return to main top window with sorted PID order as shown in below screen. Press ‘q‘ to quit exit the window.
Sorting Process ID’s
3. Display Specific User Process
Use top command with ‘u‘ option will display specific User process details.
# top -u arun
Top with Specific User Processes
4. Highlight Running Process in Top
Press ‘z‘ option in running top command will display running process in color which may help you to identified running process easily.
Top Process with Colorful
5. Shows Absolute Path of Processes
Press ‘c‘ option in running top command, it will display absolute path of running process.
Top with Specific Process Path
6. Change Delay or Set ‘Screen Refresh Interval’ in Top
By default screen refresh interval is 3.0 seconds, same can be change pressing ‘d‘ option in running top command and change it as desired as shown below.
Top – Set Refresh Time
7. Kill running process with argument ‘k’
You can kill a process after finding PID of process by pressing ‘k‘ option in running top command without exiting from top window as shown below.
Top – Kill Process ID
8. Sort by CPU Utilisation
Press (Shift+P) to sort processes as per CPU utilization. See screenshot below.
Top – High CPU Utilization
9. Renice a Process
You can use ‘r‘ option to change the priority of the process also called Renice.
Top – Renice Process
10. Save Top Command Results
Press (Shift+W) to save the running top command results under /root/.toprc.
Top Command Save Results
11. Getting Top Command Help
Press ‘h‘ option to obtain the top command help.
Top Command Help
12. Exit Top Command After Specific repetition
Top output keep refreshing until you press ‘q‘. With below command top command will automatically exit after 10 number of repetition.
# top -n 10