Sunday, August 2, 2015

Yum Install Ipython on CentOS 6

1. Add EPEL repo.
    rpm -Uvh
2. Install Ipython with Yum.
    yum install ipython

Share files with You Colleagues through Python Simple HTTP Server

1. Start up the http server at directory where the files to share with. The server script can be found at section 3 in bold.

    $ python -m
    Serving HTTP on port 8000 ...

2. Your colleague can access your http server to check the list of files such as:

    $ curl

3. To display the content of the script, for example
$ curl
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

HandlerClass = SimpleHTTPRequestHandler
ServerClass  = BaseHTTPServer.HTTPServer
Protocol     = "HTTP/1.0"

if sys.argv[1:]:
    port = int(sys.argv[1])
    port = 8000
server_address = ('', port)

HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)

sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
4. To download the script either use wget or redirect the output of above to the file Please modify the server address to meet your need.

    $ wget
    $ curl >

Run Python script on remote server

Instead of copying over the Python script to the remote server to run, the local script can be run on remote server as follow as long as you are a valid user:

    cat | ssh user@machine python -

Thursday, July 23, 2015

Install LEMP on Centos 7.1

1. Install Nginx, then test it at http://ip_address
    yum install nginx -y
    systemctl start nginx 
    systemctl enable nginx

2. Modify /etc/nginx/nginx.conf to add following:
    location ~ \.php$ {
            root           /usr/share/nginx/html;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME \ $document_root$fastcgi_script_name;
            include        fastcgi_params;

3. Restart Nginx server:
    systemctl restart nginx

4. Install MySQL
    yum install mariadb-server mariadb
    systemctl start mariadb
    systemctl enable mariadb.service 

5. Install PHP
    yum install php php-common php-fpm php-mysql -y
    systemctl start php-fpm
    systemctl enable php-fpm

6. Modify /etc/php.ini to make "cgi.fix_pathinfo=0"

7. Modify /etc/php-fpm.d/www.conf to change both user and group equal to nginx instead of apache.

8. Restart Nginx:
    systemctl restart php-fpm

9. Create /usr/share/nginx/html/info.php with following code to test php. The php information page should be displayed at http://ip/info.php
    <?php phpinfo(); ?>

10. After the information on page http://ip/info.php confirmed. delete the file /usr/share/nginx/html/info.php.

If needed do the following to change the default PHP-FPM port to Unix socket:

1. Modify /etc/php-fpm.d/www.conf as show below:
    listen =
    listen = /var/run/php-fpm/php5-fpm.sock

2. Modify /etc/nginx/nginx.conf
    fastcgi_pass unix:/var/run/php-fpm/php5-fpm.sock;

Finally, restart Nginx and PHP-FPM:
    systemctl restart nginx
    systemctl restart php-fpm

Monday, July 13, 2015

Install FTP server vsftpd on CentOS 7.1

1. yum install vsftpd ftp -y
2. vi /etc/vsftpd/vsftpd.conf with following changes:
## Set to "NO" ##

## Uncomment ##

## Uncomment - Enter your Welcome message - This is optional ##
ftpd_banner=Welcome to UNIXMEN FTP service.

## Add at the end of this  file ##

3. systemctl restart vsftpd
4. systemctl enable vsftpd

Saturday, June 27, 2015

Install LAMP on Centos 7.1

Install Apache

  • yum install httpd 
  • systemctl start httpd.service 
  • systemctl enable httpd.service 

Install MySQL

  • yum install mariadb-server mariadb
  • systemctl start mariadb
  • mysql_secure_installation 
  • systemctl enable mariadb.service 

Install PHP

  • yum install php php-mysql 
  • systemctl restart httpd.service 

Install PHPmyadmin

  • yum install epel-release 
  • yum install phpmyadmin
  • systemctl restart httpd.service 

Thursday, June 25, 2015

Grant Sudo Privileges To a User on Centos 7

From the command line:
gpasswd -a webapp wheel

Monday, June 22, 2015

Install Elasticsearch on Centos 7.1

  1. Download Current Java Runtime Environment from:
  2. sudo rpm -Uvh jre-8u45-linux-x64.rpm
  3. java -version
  4. sudo rpm -Uvh
  5. Define localhost in /etc/elasticsearch/elasticsearch.yml
  6. sudo systemctl daemon-reload
  7. sudo systemctl enable elasticsearch.service
  8. sudo systemctl start elasticsearch.service
  9. Execute curl -XGET 'http://localhost:9200/_cluster/health?pretty=true' to make sure the server is up and running

Monday, May 25, 2015

Logrotate uses 100% CPU issue on CentOS

A typical /var/lib/logrotate.status looks like:

logrotate state -- version 2
"/var/log/daemon.log" 2015-5-9
"/var/log/portage/elog/summary.log" 2015-5-9
"/var/log/mysql/mysql.err" 2015-5-9
"/var/log/mysql/mysql.log" 2015-5-9
"/var/log/mysql/mysqld.err" 2015-5-9
"/var/log/atop/dummy_before" 2015-5-25
"/var/log/atop/dummy_after" 2015-5-25
"/var/log/net-snmpd.log" 2015-5-9
"/var/log/xinetd.log" 2015-5-23
"/var/log/wtmp" 2015-5-9

It is a small file say hundred bytes, but the size may reaches megabytes if there are some config errors.

Following command can be used to check the configuration of logrotate without change anything:

sudo /usr/sbin/logrotate -d /etc/logrotate.conf
reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file daemon
reading config info for /var/log/daemon.log
reading config file elog-save-summary
reading config info for /var/log/portage/elog/summary.log
reading config file mysql

It may indicate a bad logrotate.status file if the command hangs with a huge logrotate status file,  

To fix the problem, simply delete the logrotate.status. The logrotate will re-create a new one for you.

Sunday, April 26, 2015

SVN client side problems

If there is a performance or strange issue on a specific tree try the following:

  1. In Windows, delete the roaming profile folder %AppData%\Subversion. 
  2. Rename your current tree then chekout a fresh copy to work with. Then copy any uncommitted files from the old (renamed) tree to the new tree.  

Monday, January 12, 2015

Setup Color Scheme Distinguished For Vim

Run mkdir -p ~/.vim/colors

Download distinguished.vim and move to the directory.

Add following to ~/.vimrc
syntax on
colorscheme distinguished

Append following to ~/.bashrc
        export TERM=xterm-256color

Run . ~/.bashrc to bring up the term setting.

For more schemes examples see