Showing posts with label CentOS. Show all posts
Showing posts with label CentOS. Show all posts

A way to install Google Chrome on CentOS 6

Download a install script, written by Richard. For more information, go to http://chrome.richardlloyd.org.uk.
wget http://chrome.richardlloyd.org.uk/install_chrome.sh
chmod u+x install_chrome.sh
sudo ./install_chrome.sh  -d -s
# -s, install stable version
# -d, delete temporary files in install successfully.

CentOS Httpd Reverse Proxy Using VirtualHost

Make modifications to file /etc/httpd/conf/httpd.conf by adding the following lines to it:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName ncw0116.com
ProxyRequests off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
Then restart httpd:sudo /etc/init.d/httpd restart , you could visit your new website by omitting the port number 8080. I could also call the upper method as port forwarding.

Autostart application after CentOS reboots

If you only want to run a script after CentOS boots, you could put the command to rc.local file.
vim /etc/rc.d/rc.local
# type in your script at the bottom of this file
If you want to start and shutdown the program along with the system, you might need to create a service using chkconfig. To do so,

1.create a script file at /etc/init.d/
Here is an example of the content of the file
# create file( you need root privilege to do)
cd /etc/init.d/
vim emen2
and add the followings to the file
#!/bin/sh
#chkconfig: 235 80 05
#description: EMEN2 database server
#source function library
EMEN2_HOME=/srv/EMAN2
if [ ! -f $EMEN2_HOME/eman2.bashrc ]
then
  echo "EMEN2 startup: cannot start, missing eman2.bashrc"
  exit
fi
case "$1" in
  "start")
    echo -n "Start emen2 service"
    source $EMEN2_HOME/eman2.bashrc
    # To run it as root
    $EMEN2_HOME/Python/bin/emen2ctl start -h /srv/db_env -e default,site,em --port 8080
    # Or to run it as dedicated user
    /bin/su - username -c $EMEN2_HOME/Python/bin/emen2start
    echo "."
    ;;
  "stop")
    echo - n "Stop emen2 service"
    source $EMEN2_HOME/eman2.bashrc
    # To run it as root
    $EMEN2_HOME/Python/bin/emen2ctl stop -h /srv/db_env -e default,site,em --port 8080
    # Or to run it as dedicated user
    /bin/su - username -c $EMEN2_HOME/Python/bin/emen2stop
    echo "."
    ;;
  *)
    echo "Usage: /sbin/service emen2 {start|stop}"
    exit 1
esac
exit 0

**About the three values after #chkconfig
(1). The first value ’235′ states the default runlevels at which the service should be started. In this case, the service is configured to start at runlevel 2,3 & 5.
(2). The second value ’80′ states the start priority of the service. In this case the service shall be started after starting all those services having start priority less than 80.
(3). The third value ’05′ states the stop priority of the service. In this case the service shall be stopped after stopping all those services having stop priority less than 05.

**/bin/su -c can only accept simple command, which means there should be no "-" or "--" in the command.

2. make the file runnable:
chmod a+x emen2
 
3. add the newly created service to the start up list by
/sbin/chkconfig/emen2 on

Install Berkeley DB-5.3.21 on Centos

Berkeley DB source file at Oracle. Install optional dependence: Tcl-8.6.0, OpenJDK-1.7.0.9, and Sharutils-4.13.3 (for the uudecode command)
sudo yum install tcl
sudo yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel
sudo yum install sharutils
Install Berkeley DB
wget http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz
tar zvxf db-5.3.21.tar.gz 
cd db-5.3.21/build_unix
# configure the program
../dist/configure --prefix=/opt --enable-compat185 --enable-dbm --disable-static --enable-cxx
make
# install
sudo make docdir=/usr/share/doc/db-5.3.21 install
sudo chown -v -R root:root /usr/bin/db_* /usr/include/db{,_185,_cxx}.h /usr/lib/libdb*.{so,la} /usr/share/doc/db-5.3.21
Questions:
when you run db_recover or other commands, you may encounter "libdb-5.3.so: cannot open shared object file: No such file or directory" Answer:
sudo /sbin/ldconfig

Port Forwarding in CentOS Using Iptables

Port forwarding could be useful when you do not want to you client to put a port nuimber after you web address. In my case I forward port 8080 to 80. 1. check if IP forwarding is enabled:
/sbin/sysctl net.ipv4.ip_forward
if return net.ipv4.ip_forward = 1 then it is enabled. if not edit /etc/sysctl.conf and set net.ipv4.ip_forward = 1.
2. COnfigure and restart iptables
/sbin/sysctl -p /etc/sysctl.conf
/sbin/service iptables restart
3. Adding IP forwarding rules to IpTables
/sbin/iptables -I FORWARD 1 -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -I FORWARD 1 -p tcp --dport 80 -j ACCEPT
/sbin/iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.0.1.1:8080
/sbin/iptables -t nat -A POSTROUTING -j MASQUERADE
/sbin/service iptables save
/sbin/service iptables restart
The content of /etc/sysconfig/iptables files looks like:
# Generated by iptables-save v1.3.5 on Fri Mar 8 10:27:21 2013
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A PREROUTING -p tcp -m tcp --dport 80 -j DNAT --to-destination 10.0.1.1:8080
-A POSTROUTING -j MASQUERADE
COMMIT
# Completed on Fri Mar 8 10:27:21 2013
# Generated by iptables-save v1.3.5 on Fri Mar 8 10:27:21 2013
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [234:26336]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -p tcp -m tcp --dport 80 -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p esp -j ACCEPT
-A RH-Firewall-1-INPUT -p ah -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
....
....
....
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

Restore CentOS top panel

Have you ever messed up top panel of your CentOS?
Here is a way to restore it to it's default.
sudo mv ~/.gconf/apps/panel ~/.gconf/apps/panel.bak
sudo reboot

Disable system beep for CentOS

Here is way to disable the system beep for CentOS
# unloading the pcspkr module: 
rmmod -v pcspkr
In addition, add the following line in /etc/rc.d/rc.local file to automatic disable it during boot.
/sbin/rmmod pcspkr
if you ever want to re-enable the speaker, run the following command:
/sbin/modprobe pcspkr

Eclipse and CentOS

1. install
$ sudo yum groupinstall Eclipse
2. configuration

3. install Django
$sudo pip install django
4. install PyDev: use eclipse install new software feature by adding http://pydev.org/updates

use rdesktop to access windows desktop from CentOS

CentOS comes with rdesktop installed:
run the following command to access your windows desktop:
rdesktop -u user_name -f ip_address
To toggle full screen mode, use
ctrl+alt+enter

Problems and solution


1. While suing this program you may encounter WARNING: Remote desktop does not support colour depth 24; falling back to 16 if your windows system is Windows XP.
To fix the problem go to windows machine:

# go to Start -> Run -> gpedit.msc
# In the Group Policy Editor, navigate to Local Computer Policy -> Computer Configuration -> Administrative Templates -> Windows Components -> Terminal Services, and double-click on the 'Limit maximum Color Depth' object. Set the item to "Enabled" and set "Color Depth" to "24 bit"
2. One other problem you may encounter is: Idle time over and rdesktop closed the connection. To fix this problem:
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows NT\terminal services\MaxIdleTime
It was set to 900,000 mSec. or 15-minutes. I increased the value to 10,800,000 or 3-hours.

Dual Head display on CentOS using ATI Radeon HD 3450

Go to official AMD site to download the official linux driver for this video adapter:
1. install the driver:
$ sudo sh ./ati-driver-installer-x86.x86_64.run 
#Here I choose custom installation and opt out Catalyst Control Center.
2. Configure the driver after installation and enable dual head display
$ sudo aticonfig –initial
# if your second display is at the right of your main display
$ sudo aticonfig --initial=dual-head --screen-layout=right

Install R CentOS 5

I have tried installing R on CentOS 5.5 by the following way and it test good.

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum install R



You can run the R with scripts from cmd line by doing one of the following:

R < mean.R
R CMD BATCH mean.R
Rscript mean.R

CentOS user and user group

Create user and add to the esiting group:

/usr/sbin/useradd -G {group-name} username

if the group does not exist, create it first:

groupadd group_name

If you do not use the group option then the user will be assigned to thegroup with the same name user name.

Remove a user:

sudo /usr/sbin/userdel

User and group related files:

cat /etc/passwd

cat /etc/gshdow

Configuring Samba on CentOS

1 .Installing samba via yum

yum -y install samba samba-common samba-client

Configuring samba. Before changing the configure file, back up the original file:

cp /etc/samba/smb.conf /etc/samba/smb.conf.orig

1.1 Examples on setting password protected Samba share

vi /etc/samba/smb.conf


[global]
workgroup = WORKGROUP
server string = ncu12345678
security = User 
load printers = yes
cups options = raw
[share]
writeable = yes
path = /home/ajohn/dataswitch/windows
#do not use this setting since it will cause all created files owned by root
#admin users = user
force user = ajohn
valid users = ajohn
public = yes
available = yes
guest ok = no
# I changes the permissions to rw-rw-r--
create mask = 664
force create mode = 664
security mask = 664
force security mode = 664

directory mask = 0775
force directory mode = 0775
directory security mask = 0775
force directory security mode = 0775


Save and exit the configuration file.



2. Create Samba User

After you have install samba sever, yous still can’t login samba server. You will need create a samba user :
smbpasswd -a username
‘-a’ switch tell smbpasswd we want to add a new user, username is the user you want to add.

Please take note, username must exist in /etc/passwd file or you will need use ‘useradd’ to create a user in Linux :

sudo /usr/sbin/useradd -d /home/username -s /bin/false -n username
 
This will create a new user with same group name with (told by ‘-n’), but the user can’t login and run any shell command (because you have specfic the login shell is /bin/false by the ‘-s’ switch, if you want allow user to able to login to a shell, replace /bin/false with /bin/sh).

Ok now you have create a new samba user, how about you want delete or disable them? ‘-d’ switch will disable the user to login to samba server:
smbpasswd -d username
If you want to delete a user permanently:
smbpasswd -x username
3. Start the Samba service

sudo /etc/init.d/smb start

Question: If you encounter "access denied error"? check whether you have set SeLinux to disabled or permissive

Add other language support for CentOS

By default, CenOS does not install other languages, to install you can use the following command:

sudo yum install @chinese-support

CPAN error: failed with code[400] message[URL must be absolute}

While I was trying to install Imager::QRCode using cpan, I have this problem: failed with code[400] message[URL must be absolute]

Searching online I found that my urllist for cpan is empty. To correct problem:

run this command with in cpan O conf urllist push "Your_cpan_mirror_url" for example,

S sudo cpan

cpan> o conf urllist push http://cpan.yahoo.com/

Here are other o conf related commands for use:

To view the urllist: o conf urllist

To remove the first url from the urllist: o conf urllist shift

To save the configuration after you made modification: o conf commit

Curious which verison of the CentOS you are running?

try typing uname -a in the command line

if you see

Linux XXXXXX 2.6.18-238.19.1.el5 #1 SMP Fri Jul 15 07:31:24 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

Then you are running 64 bit of CentOS.

Command cat /etc/redhat-release  will show you the version of theCentOS

Linux find and replace text within all files within a directory



There is a fast way to replace all the occurrences of one world within a certain directory including subdirectory by using a one line Linux code (by using Perl):



find /path/to/start/from/ -type f | xargs perl -pi -e 's/old_word/new_word/g'





REMEMBER ALWAYS BACKUP BEFORE DOING SOMETHING
If you want to do word replacement using the vim
:%s/search/replace/g                     whole file
:2,12s/search/replace/g                 from line 2 to line 12

Install a new version of the Python on CentOS without overwriting the system's python installation

Install a new version of the Python on CentOS without overwriting the system's python installation
** You have to decide where to install it based on your needs. If you want to run web server later using this copy of the Python, you may not want to install it in your home directory. Most popular place to go is /opt/.
The default Python comes with the CentOS is version 2.4 which can not meet the requirements of some programs. Here is an instruction of installing a separate newer version of the Python on CnetOS.
Prepare the source code
  1. cd
  2. wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
  3. tar –zvxf Python-2.7.2.tgz
  4. cd Python-2.7.2
  5. configure python so it will not overwriting the system’s default python
    ./configure –prefix= /usr/local/opt/python2.7 --with-threads --enable-shared
1)     --enable-shared is required if you are going to install mod_wsgi. Or you have to rebuild the python library.
2)        However, if you choose –enable-shared parameter you may encounter error while you are trying to install pscopg2. The error message is "ld cannot find lpython2.7". Here is a solution to that:
$ cd /usr/lib64
$ sudo ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 libpython2.7.so.1.0
   $ sudo ln -s libpython2.7.so.1.0  libpython2.7.so

  1. make and install
  $ make
 $ make install
Now you have successfully installed a fully functional copy of the python library. In order to use it you can do some configuration for this version of the python.
  1. add the following line to user’s .bashrc to create an alias, so you do not need reboot to start using the alias
    alias python='/usr/local/opt/python2.7/bin/python'
2.  Make a symbolic link in the /usr/bin folder:
    $ ln –s /usr/local/python2.7/bin/python /usr/bin/python2.7
3. to make a permanent change then you can run the following as root:
     ln -f /usr/local/python2.7/bin/python /usr/local/bin/python
  1. Configure ld to find your shared libs:
a. create file opt-python2.7.conf under /etc/ld.so.conf.d folder
b. add /usr/local/python2.7/lib into the created file
c. run $ sudo /sbin/ldconfig

After the installation of the new versions of the Python you might need to install the setuptools and pip to work with this version of the Python:
1. Install setuptools
a.         cd
b.        wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
c.        tar -zvxf setuptools-0.6c11.tar.gzll
d.        cd setuptools-0.6c11
e.        python2.7 setup.py build  ###here use the newly installed python to make sure you are installing it for it
f.        python2.7 setup.py install

     2 Install pip

        Follow the same operation process for installing setuptools.  After installing the pip you may want to make a symbolic link for it in the /usr/bin folder
sudo ln –s /usr/local/python2.7/bin/pip /usr/bin/pip2.7









Reference:

1. Thanks http://thebuild.com/blog/2009/10/17/wordpress-to-djangopostgresql-part-3-installing-apache-python-2-6-psycopg2-and-mod_wsgi/ for tips on overcoming the errors while installing the psycopg2 by link thelibraries to /usr/lib64.

2. http://blog.hackedexistence.com/mediatemple-centos-5-5-ve-server-build-django-1-3-python-2-7-mysql-5-5-php-5-3

Configure mod_wsgi with Apache for running Django project

Part One: prepare the environment
 1. Download source code of modwsgi from http://code.google.com/p/modwsgi/downloads/list
 2. Unpack the downloaded package tar -zvxf package_name
 3. Enter the unpackaged folder, run. /configure 
 4. if you encounter an error, make sure you have development package of httpd (apache) installed on your machine.
 to install the development package of Apache, run yum install httpd-devel.x86_64 
 5. re-run $./configure
 6. $ make
 7. sudo make install
 8. create file mod_wsgi.conf under /etc/httpd/conf.d, ans add th efollowing line to the file you created:
 LoadModule wsgi_module modules/mod_wsgi.so
 9. restart the httpd service: sudo /etc/init.dhttpd restart
10. make clean

 Part two: make necessary configuration in httpd.conf file located in /etc/httpd/conf/
 In this part of the configuration we are using the Apache VirtualHost to host the django project.
 1. Configure apache to server VirtualHost:
 a. add one more port for listening by Apache which will be specifically used for virtual host:
 Listen 8081
 b.  uncomment NameVirtualHost *:80 and change the port number from 80 to the port number you defined in step (a), which is 8081 in my case
 2.  Add the following configuration for virtual host:
 <VirtualHost *:8081>
    ServerName virtual name of your server
    ServerAdmin your email address
    DocumentRoot /srv/www/...../cmsdj/
    WSGIScriptAlias / /srv/www/..../cmsdj/apache/django.wsgi
    <Directory /srv/www/..../cmsdj/apache>
      Order allow,deny
      Allow from all
    </Directory>
    ErrorLog /srv/www/..../cmsdj/logs/error.log
    CustomLog /srv/www/..../cmsdj/logs/access.log combined
</VirtualHost>
3. Create django.wsgi file under your app folder
 The detail path to your wsgi file is in the upper virtual host configuration file:
 /srv/www/foodborn.nctr.fda.gov/cmsdj/apache/django.wsgi

The content of this file:
import os
import sys
path = '/srv/www/foodborn.nctr.fda.gov/' #do not add the project folder name to this path
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'cmsdj.settings'
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/foodborn.nctr.fda.gov/.python-eggs'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

4.  Check your project’s urls.py file to make sure that you are using the full path to the models you are importing and in the urls maps:
  a. (r'^$', 'core.views.index') is not the full path since you are omitting the name of the project, which should be changed to (r'^$', 'cmsdj.core.views.index'),
b.  “from core import views”  is not the full path, you need add project name “from cmsdj.core import views”

Part Three: serving the admin files
 Make sure your project’s settings.py file contents this sentence:
 ADMIN_MEDIA_PREFIX = '/media/'
  Then you run the followingcommand to collect all the static files needed by admin models into the project admin folder.
 python manage.py collectstatic

 
References:
1.      http://blog.perplexedlabs.com/2008/11/10/setup-python-25-mod_wsgi-and-django-10-on-centos-5-cpanel/
2.      https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#module-django.contrib.staticfiles
3.      https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/






Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...