{"id":1604,"date":"2013-10-23T23:52:55","date_gmt":"2013-10-23T21:52:55","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=1604"},"modified":"2013-10-28T00:46:44","modified_gmt":"2013-10-27T22:46:44","slug":"centos-useful-commands","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=1604","title":{"rendered":"Centos useful commands"},"content":{"rendered":"<p>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 .<\/p>\n<p>Common used phrase \u201c<strong>yum<\/strong>\u201d means: Yellowdog Updater Modified.<br \/>\n<strong>Search for any Installed Packages [ Syntax]:<\/strong><\/p>\n<pre>#yum list<\/pre>\n<p><strong>List of updated software (security fix) [ Syntax]:<\/strong><\/p>\n<pre>#yum list updates<\/pre>\n<p><strong>Example: for check installed mysql version:<\/strong><\/p>\n<pre>#mysql -v<\/pre>\n<p><strong>Switch User [ Syntax]:<\/strong><\/p>\n<pre>#su \u2013<\/pre>\n<p>is to connect as root<\/p>\n<pre>#su oracle<\/pre>\n<p>Anyway, If no username is specified, then the root user is assumed.<\/p>\n<p><strong>Get Full package info of Installed Package [Syntax]:<\/strong><\/p>\n<pre>#yum info<\/pre>\n<p>Example:<\/p>\n<pre>#yum info php<\/pre>\n<p>Example: yum info php \u2013 Will show Full version info for php package.<\/p>\n<p><strong>Grep command [Syntax]:<\/strong><\/p>\n<pre>#grep<\/pre>\n<p>Grep With custom Switch:<\/p>\n<pre># rpm -qa | grep php<\/pre>\n<p>Pipe | used for transfer output of rpm command to grep command.<br \/>\nRPM (Redhat Package Manager): RPM installs already configured and compiled software in your system.<\/p>\n<p><strong>Search Any Package on Mirrors \/ Repository [ Syntax]:<\/strong><\/p>\n<pre>#yum search<\/pre>\n<p>Example &#8211; Search All bcmath Package available on Mirrors \/ Repository :<\/p>\n<pre>#yum search bcmath<\/pre>\n<p><strong>Install Any Package [ Syntax]:<\/strong><\/p>\n<pre>#yum install<\/pre>\n<p>Example \u2013 Will install php-bcmath package\/module :<\/p>\n<pre>#yum install php-bcmath<\/pre>\n<p><strong>Remove package [Syntax]:<\/strong><\/p>\n<pre># yum remove<\/pre>\n<p>Example \u2013 Will remove mysql package :<\/p>\n<pre>#yum remove mysql<\/pre>\n<hr \/>\n<h2 class=\"nolinks\">Checking disk usage (lsblk or df or fdisk)<\/h2>\n<h3>Command: lsblk<\/h3>\n<p>The \u201c<strong>lsblk<\/strong>\u201d stands for (<strong>List Block Devices<\/strong>), print block devices by their assigned name on the standard output in a tree-like fashion.<\/p>\n<pre>root@centos:~# lsblk\r\n\r\nNAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT\r\nsda      8:0    0 232.9G  0 disk \r\n\u251c\u2500sda1   8:1    0  46.6G  0 part \/\r\n\u251c\u2500sda2   8:2    0     1K  0 part \r\n\u251c\u2500sda5   8:5    0   190M  0 part \/boot\r\n\u251c\u2500sda6   8:6    0   3.7G  0 part [SWAP]\r\n\u251c\u2500sda7   8:7    0  93.1G  0 part \/data\r\n\u2514\u2500sda8   8:8    0  89.2G  0 part \/personal\r\nsr0     11:0    1  1024M  0 rom<\/pre>\n<p>The \u201c<strong>lsblk -l<\/strong>\u201d command list block devices in \u2018<strong>list<\/strong>\u2018 structure (not tree like fashion).<\/p>\n<pre>root@centos:~# lsblk -l\r\n\r\nNAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT\r\nsda    8:0    0 232.9G  0 disk \r\nsda1   8:1    0  46.6G  0 part \/\r\nsda2   8:2    0     1K  0 part \r\nsda5   8:5    0   190M  0 part \/boot\r\nsda6   8:6    0   3.7G  0 part [SWAP]\r\nsda7   8:7    0  93.1G  0 part \/data\r\nsda8   8:8    0  89.2G  0 part \/personal\r\nsr0   11:0    1  1024M  0 rom<\/pre>\n<p>However, even if <em>lsblk<\/em> is more visual, I still prefer to use <strong><em>df -h<\/em><\/strong>. The latter gives you more information about the remaining space, the size of the partitions, and the percentage of memory in use.<\/p>\n<p><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-04.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1633\" alt=\"centos-04\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-04.jpg\" width=\"412\" height=\"154\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-04.jpg 412w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-04-300x112.jpg 300w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/a><\/p>\n<hr \/>\n<h2>Services Enabling Levels<\/h2>\n<p>To display the current settings for a selected service only, use <code>chkconfig --list<\/code> followed by the name of the service:<\/p>\n<pre>chkconfig --list service_name<\/pre>\n<div>For example, to display the current settings for the <code>sshd<\/code> service, type:<\/div>\n<pre>~]#chkconfig --list sshd\r\nsshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/pre>\n<p>You can also use this command to display the status of a service that is managed by <strong>xinetd<\/strong>. In that case, the output will only contain the information whether the service is enabled or disabled:<\/p>\n<pre>~]#chkconfig --list rsync\r\nrsync           off<\/pre>\n<h4>Enabling a Service<\/h4>\n<p>To enable a service in runlevels 2, 3, 4, and 5, type the following at a shell prompt as root :<\/p>\n<pre>chkconfig service_name on<\/pre>\n<p>For example, to enable the httpd\/Apache service in these four runlevels, type:<\/p>\n<pre>~]#chkconfig httpd on<\/pre>\n<hr \/>\n<h2>Listing running modules<\/h2>\n<p>But first you need to know which modules are currently running. The command for that is<\/p>\n<pre>lsmod<\/pre>\n<p><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-05.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1632\" alt=\"centos-05\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-05.jpg\" width=\"463\" height=\"353\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-05.jpg 463w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-05-300x228.jpg 300w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><\/a><\/p>\n<p><strong><em>whereis<\/em> <\/strong>can locate binaries, manual entries, and various configuration files. Its syntax is also very simple:<\/p>\n<pre>whereis [name]<\/pre>\n<p><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-06.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1631\" alt=\"centos-06\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-06.jpg\" width=\"424\" height=\"100\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-06.jpg 424w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-06-300x70.jpg 300w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p>But one of the greatest strengths of <em>whereis<\/em> is its ability to locate standalone configuration files. Here is another example, where I was searching for <em>rc<\/em> configuration files:<\/p>\n<p><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-07.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1641\" alt=\"centos-07\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-07.jpg\" width=\"516\" height=\"58\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-07.jpg 516w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-07-300x33.jpg 300w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><\/a><\/p>\n<h3>Create a User and directories for Oracle<\/h3>\n<p>Create two groups, oinstall and dba<\/p>\n<pre>groupadd oinstall\r\ngroupadd dba<\/pre>\n<p>Create user oracle, and assign him to the groups and give him a password.<\/p>\n<pre>useradd -g oinstall -G dba -p password -d \/home\/oracle -s \/bin\/bash oracle\r\npasswd oracle<\/pre>\n<h3>Directories<\/h3>\n<p>Create the following directories and assign them to user and dba group for oracle install<\/p>\n<pre>mkdir -p \/u01\/app\/oracle\r\nmkdir -p \/u02\/app\/oracle\r\nmkdir -p \/u03\/app\/oracle\r\nchown -R oracle:dba \/u01\r\nchown -R oracle:dba \/u02\r\nchown -R oracle:dba \/u03<\/pre>\n<hr \/>\n<h3>Install lamp server on centos<\/h3>\n<p>LAMP is an acronym for a solution stack of free, open source software, originally coined from the first letters of <b>L<\/b>inux (operating system), <b>A<\/b>pache HTTP Server, <b>M<\/b>ySQL (database software), and <b>P<\/b>HP, principal components to build a viable general purpose web server.<\/p>\n<p><b>Install Apache. (httpd or apache2)<\/b><\/p>\n<pre><i>#\u00a0yum -y install httpd<\/i><\/pre>\n<p>Adding Apache to startup, so it can automatic loaded if system restarted.<\/p>\n<pre><i>#\u00a0chkconfig --levels 235 httpd on<\/i><\/pre>\n<pre><i># service httpd start<\/i><\/pre>\n<p>To check Apache has installed on server go to <i><b>http:\/\/YourIPAddress\/<\/b><\/i> and if you see as in the screenshoot that means Apache has been installed on your server.<\/p>\n<p>To stop Firewall services you can follow the commands below :<a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-10.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1644\" alt=\"centos-10\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-10.jpg\" width=\"600\" height=\"103\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-10.jpg 600w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-10-300x51.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>if you want to keep firewall on and If you get message &#8220;<i>No Route To Host<\/i>&#8221; that means you must open port 80 that still closed by firewall.<br \/>\nTo open port 80 simply do this step:<\/p>\n<pre><i># vi \/etc\/sysconfig\/iptables<\/i><\/pre>\n<p>Add this command and save (to save press key &#8220;Esc&#8221; and then type &#8220;:wq&#8221;)<\/p>\n<pre>-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 80 -j ACCEPT<\/pre>\n<pre>-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT<\/pre>\n<p>And then restart IPTABLES<\/p>\n<pre><i># service iptables restart<\/i><\/pre>\n<p><b>Install MySQL<\/b><\/p>\n<pre><i># yum install mysql mysql-server<\/i><\/pre>\n<p>Adding MySQL to startup<\/p>\n<pre><i># chkconfig --levels 235 mysqld on<\/i>\r\n<i># \/etc\/init.d\/mysqld start<\/i><\/pre>\n<p>Create MySQLadmin User and Password or <strong>use <span style=\"text-decoration: underline;\">mysql_secure admin<\/span> utility as below in screenshot<\/strong><\/p>\n<pre><i># mysqladmin -u root password YourPassSQL<\/i><\/pre>\n<pre><i># mysqladmin -h HostNameServer -u root password Y<\/i><i>ourPassSQL<\/i><\/pre>\n<p><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-11.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1645\" alt=\"centos-11\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-11.jpg\" width=\"592\" height=\"345\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-11.jpg 592w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2013\/10\/centos-11-300x174.jpg 300w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/a><\/p>\n<p><b>Install PHP <\/b><\/p>\n<pre><i># yum install php php-mysql php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc<\/i><\/pre>\n<p>Restart Apache<\/p>\n<pre><i># service httpd restart<\/i><\/pre>\n<p>To check php has been installed on server simply do following step:<\/p>\n<pre><i># vi \/var\/www\/http\/php\/index.php<\/i><\/pre>\n<p>and type following php code:<\/p>\n<pre><i>&lt;?php\r\nphpinfo();\r\n?&gt;<\/i><\/pre>\n<p>Save and go to <i><b>http:\/\/YourIPAddress\/php\u00a0 <\/b><\/i><br \/>\nif php has been installed on your server, you will see php version and modules installed.<\/p>\n<p><strong>Install phpmyadmin on centos 5.5<br \/>\n<\/strong><\/p>\n<p>You will need to install and Enable <a href=\"http:\/\/www.tecmint.com\/install-and-enable-rpmforge-repository-in-rhel-centos-6-5-4\/\">EPEL Repository<\/a> :<\/p>\n<pre><strong>## RHEL\/CentOS 5 32 Bit OS ##<\/strong>\r\n# wget http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.i386.rpm\r\n# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm<\/pre>\n<p>Next, you\u2019ll need to download and install <strong>DAG\u2019s GPG<\/strong> key for your system.<\/p>\n<pre># wget http:\/\/dag.wieers.com\/rpm\/packages\/RPM-GPG-KEY.dag.txt\r\n# rpm --import RPM-GPG-KEY.dag.txt<\/pre>\n<pre>yum --enablerepo=rpmforge install phpmyadmin<\/pre>\n<p>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.<br \/>\nTo do so, open up \/etc\/httpd\/conf.d\/phpmyadmin.conf using:<\/p>\n<pre>nano \/etc\/httpd\/conf.d\/phpmyadmin.conf<\/pre>\n<p>You will see:<\/p>\n<p><strong>&lt;Directory \u201c\/usr\/share\/phpmyadmin\u201d&gt;<\/strong><br \/>\n<strong> Order Deny,Allow<\/strong><br \/>\n<strong> Allow from all<\/strong><br \/>\n<strong> Allow from 127.0.0.1<\/strong><br \/>\n<strong> &lt;\/Directory&gt;<\/strong><\/p>\n<p>Now, you can access phpMyAdmin by visiting http:\/\/vps_server_IP_or_domain\/phpmyadmin. But you will get the following error:<\/p>\n<p>Error<br \/>\nThe configuration file now needs a secret passphrase (blowfish_secret).<\/p>\n<pre>nano \/usr\/share\/phpmyadmin\/config.inc.php<\/pre>\n<p>Find a line saying:<\/p>\n<pre>$cfg['blowfish_secret'] = ''; \/* YOU MUST FILL IN THIS\r\nFOR\r\nCOOKIE AUTH! *\/<\/pre>\n<p>Fill in any secret keyword there, eg mysecretpassphrase, so that it looks like:<\/p>\n<pre>$cfg['blowfish_secret'] = 'mysecretpassphrase'; \/* YOU MUST FILL IN THIS\r\nFOR\r\nCOOKIE AUTH! *\/<\/pre>\n<p>and then save it.<\/p>\n<p>Now, you must restart apache. To do so, run<\/p>\n<pre>service httpd restart<\/pre>\n<p>Now, you can access phpMyAdmin by visiting http:\/\/vps_server_IP_or_domain\/phpmyadmin<\/p>\n<p>Will be continued &#8230;.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 \u201cyum\u201d means:&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2843,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[241,14],"tags":[],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/1604"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1604"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/1604\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2843"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}