Centos useful commands

Now a days While working on latest version of CentOS , i get to know some important but initial commands,which are most frequently used or commonly used CentOS .

Common used phrase “yum” means: Yellowdog Updater Modified.
Search for any Installed Packages [ Syntax]:

#yum list

List of updated software (security fix) [ Syntax]:

#yum list updates

Example: for check installed mysql version:

#mysql -v

Switch User [ Syntax]:

#su –

is to connect as root

#su oracle

Anyway, If no username is specified, then the root user is assumed.

Get Full package info of Installed Package [Syntax]:

#yum info

Example:

#yum info php

Example: yum info php – Will show Full version info for php package.

Grep command [Syntax]:

#grep

Grep With custom Switch:

# rpm -qa | grep php

Pipe | used for transfer output of rpm command to grep command.
RPM (Redhat Package Manager): RPM installs already configured and compiled software in your system.

Search Any Package on Mirrors / Repository [ Syntax]:

#yum search

Example – Search All bcmath Package available on Mirrors / Repository :

#yum search bcmath

Install Any Package [ Syntax]:

#yum install

Example – Will install php-bcmath package/module :

#yum install php-bcmath

Remove package [Syntax]:

# yum remove

Example – Will remove mysql package :

#yum remove mysql

Command: lsblk

The “lsblk” stands for (List Block Devices), print block devices by their assigned name on the standard output in a tree-like fashion.

root@centos:~# lsblk

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 232.9G  0 disk 
├─sda1   8:1    0  46.6G  0 part /
├─sda2   8:2    0     1K  0 part 
├─sda5   8:5    0   190M  0 part /boot
├─sda6   8:6    0   3.7G  0 part [SWAP]
├─sda7   8:7    0  93.1G  0 part /data
└─sda8   8:8    0  89.2G  0 part /personal
sr0     11:0    1  1024M  0 rom

The “lsblk -l” command list block devices in ‘list‘ structure (not tree like fashion).

root@centos:~# lsblk -l

NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda    8:0    0 232.9G  0 disk 
sda1   8:1    0  46.6G  0 part /
sda2   8:2    0     1K  0 part 
sda5   8:5    0   190M  0 part /boot
sda6   8:6    0   3.7G  0 part [SWAP]
sda7   8:7    0  93.1G  0 part /data
sda8   8:8    0  89.2G  0 part /personal
sr0   11:0    1  1024M  0 rom

However, even if lsblk is more visual, I still prefer to use df -h. The latter gives you more information about the remaining space, the size of the partitions, and the percentage of memory in use.

centos-04


Services Enabling Levels

To display the current settings for a selected service only, use chkconfig --list followed by the name of the service:

chkconfig --list service_name
For example, to display the current settings for the sshd service, type:
~]#chkconfig --list sshd
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

You can also use this command to display the status of a service that is managed by xinetd. In that case, the output will only contain the information whether the service is enabled or disabled:

~]#chkconfig --list rsync
rsync           off

Enabling a Service

To enable a service in runlevels 2, 3, 4, and 5, type the following at a shell prompt as root :

chkconfig service_name on

For example, to enable the httpd/Apache service in these four runlevels, type:

~]#chkconfig httpd on

Listing running modules

But first you need to know which modules are currently running. The command for that is

lsmod

centos-05

whereis can locate binaries, manual entries, and various configuration files. Its syntax is also very simple:

whereis [name]

centos-06

In the example above, I asked where Firefox was, and the command returned the location for its binary and various directories, as well as the manual page.

But one of the greatest strengths of whereis is its ability to locate standalone configuration files. Here is another example, where I was searching for rc configuration files:

centos-07

Create a User and directories for Oracle

Create two groups, oinstall and dba

groupadd oinstall
groupadd dba

Create user oracle, and assign him to the groups and give him a password.

useradd -g oinstall -G dba -p password -d /home/oracle -s /bin/bash oracle
passwd oracle

Directories

Create the following directories and assign them to user and dba group for oracle install

mkdir -p /u01/app/oracle
mkdir -p /u02/app/oracle
mkdir -p /u03/app/oracle
chown -R oracle:dba /u01
chown -R oracle:dba /u02
chown -R oracle:dba /u03

Install lamp server on centos

LAMP is an acronym for a solution stack of free, open source software, originally coined from the first letters of Linux (operating system), Apache HTTP Server, MySQL (database software), and PHP, principal components to build a viable general purpose web server.

Install Apache. (httpd or apache2)

# yum -y install httpd

Adding Apache to startup, so it can automatic loaded if system restarted.

# chkconfig --levels 235 httpd on
# service httpd start

To check Apache has installed on server go to http://YourIPAddress/ and if you see as in the screenshoot that means Apache has been installed on your server.

To stop Firewall services you can follow the commands below :centos-10

if you want to keep firewall on and If you get message “No Route To Host” that means you must open port 80 that still closed by firewall.
To open port 80 simply do this step:

# vi /etc/sysconfig/iptables

Add this command and save (to save press key “Esc” and then type “:wq”)

-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

And then restart IPTABLES

# service iptables restart

Install MySQL

# yum install mysql mysql-server

Adding MySQL to startup

# chkconfig --levels 235 mysqld on
# /etc/init.d/mysqld start

Create MySQLadmin User and Password or use mysql_secure admin utility as below in screenshot

# mysqladmin -u root password YourPassSQL
# mysqladmin -h HostNameServer -u root password YourPassSQL

centos-11

Install PHP

# yum install php php-mysql php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

Restart Apache

# service httpd restart

To check php has been installed on server simply do following step:

# vi /var/www/http/php/index.php

and type following php code:

<?php
phpinfo();
?>

Save and go to http://YourIPAddress/php 
if php has been installed on your server, you will see php version and modules installed.

Install phpmyadmin on centos 5.5

You will need to install and Enable EPEL Repository :

## RHEL/CentOS 5 32 Bit OS ##
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm

Next, you’ll need to download and install DAG’s GPG key for your system.

# wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
# rpm --import RPM-GPG-KEY.dag.txt
yum --enablerepo=rpmforge install phpmyadmin

When installation is done, you can edit /etc/httpd/conf.d/phpmyadmin.conf and allow it to be opened from anywhere and not just the same computer. You are going to need this if you have installed it in a remote virtual server.
To do so, open up /etc/httpd/conf.d/phpmyadmin.conf using:

nano /etc/httpd/conf.d/phpmyadmin.conf

You will see:

<Directory “/usr/share/phpmyadmin”>
Order Deny,Allow
Allow from all
Allow from 127.0.0.1
</Directory>

Now, you can access phpMyAdmin by visiting http://vps_server_IP_or_domain/phpmyadmin. But you will get the following error:

Error
The configuration file now needs a secret passphrase (blowfish_secret).

nano /usr/share/phpmyadmin/config.inc.php

Find a line saying:

$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS
FOR
COOKIE AUTH! */

Fill in any secret keyword there, eg mysecretpassphrase, so that it looks like:

$cfg['blowfish_secret'] = 'mysecretpassphrase'; /* YOU MUST FILL IN THIS
FOR
COOKIE AUTH! */

and then save it.

Now, you must restart apache. To do so, run

service httpd restart

Now, you can access phpMyAdmin by visiting http://vps_server_IP_or_domain/phpmyadmin

Will be continued ….

 

extradrmtech

Since 30 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions and medias protecting solutions. I am experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. Besides my work, I like to work freelance only on some wordpress projects because it is relaxing and delightful CMS for me. When not working, I like to dance salsa and swing and to have fun with my little family.

You may also like...