Thursday, December 12, 2013

Installing Ruby using RVM

RVM (Ruby Version Manager) - program that lets you use several versions of Ruby on one VPS. In this we will use ruby 2.0.0p247

Step 1: Install RVM

Update the system.
sudo yum update
make sure you have curl on the system
sudo yum install curl
To install RVM
curl -L get.rvm.io | bash -s stable
After it is done installing, load RVM. To install RVM
source /etc/profile.d/rvm.sh
To check all the dependencies of the RVM. Install the results using rvmsudo.
rvm requirements
Additional Dependencies:
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
  ruby: yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel ## NOTE: For centos >= 5.4 iconv-devel is provided by glibc
rvmsudo yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel

Step 2: Install Ruby

I want to use ruby 2.0.0p247 and I will download in via rvm remote installation. You can skip the two command below and proceed to the next on but If you need some information or you want to another version of ruby you can check the rvm help and list
rvm help install
rvm list known
To get ruby 2.0.0p247 fron remote
rvm list remote
To download and install: rvm install {name} --binary
rvm install ruby-2.0.0-p247 --binary
Check the your ruby version and the location.
ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
which ruby
/usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby
reference: https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-centos-6-with-rvm

Wednesday, December 4, 2013

Solved "-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory" on Centos 6.5 (64 bit)



Don't want to see:

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

Solution:

execute
[root@CentosAshley ~]# locale
Result for english language
[root@CentosAshley ~]# locale
LANG=en_US.UTF-8
LC_CTYPE=ja_JP.UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
Go to the /etc/sysconfig/i18n and add
LC_ALL=en_US.UTF-8
SUPPORTED=en_US.UTF-8:en_US:en 
then on the .bashrc
export LC_TYPE=en_US.UTF-8
export LC_All=en_US.UTF-8
Don't forget to source .bashrc && reboot
then
[root@CentosAshley ~]# locale
LANG=en_US.UTF-8
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Tuesday, November 26, 2013

Installing Ruby on Rail on Centos 6 (64 bit) Virtual Machine

Ruby on Rails


Prerequisites

  • Ruby language version 1.9.3 or newer
  • The RubyGems packaging system
  • A working installation of the SQLite3 Database

  • On my development environment, I used centos 6 64 bit minimal (no GUI) operating system to run ruby on rails. I installed it on Oracle Virtualbox.

    Step 1: Install the Ruby
    Check the ruby version.
    [root@centosAshley02 ~]# ruby -v
    -bash: ruby: command not found
    
    No found command means we have to intall ruby.
    Install the wget command to download source files
    [root@centosAshley02 ~]# yum install wget
    
    Download rpm and update the system
    [root@centosAshley02 ~]# cd /tmp/
    [root@centosAshley02 ~]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    [root@centosAshley02 ~]# rpm -Uvh epel-release-6-8.noarch.rpm
    [root@centosAshley02 ~]# yum -y update
    
    [root@centosAshley02 ~]# yum -y groupinstall "Development Tools"
    [root@centosAshley02 ~]# yum -y install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel zlib-devel openssl-devel libyaml-devel readline-devel curl-devel openssl-devel pcre-devel git memcached-devel valgrind-devel mysql-devel ImageMagick-devel ImageMagick
     
    
    Get the latest ruby version using wget command
    [root@centosAshley02 ~]# cd /usr/src/
    [root@centosAshley02 ~]# wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz
    [root@centosAshley02 ~]# tar zxvf ruby-2.0.0-p353.tar.gz
    [root@centosAshley02 ~]# cd ruby-2.0.0-p353
    [root@centosAshley02 ~]# ./configure
    [root@centosAshley02 ~]# make
    [root@centosAshley02 ~]# make install
    
    Show the ruby version.
    [root@centosAshley02 ~]# ruby -v
    ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
    
    Step 2: Install the Rubygems
    [root@centosAshley02 ~]# cd /usr/src/
    [root@centosAshley02 src]# wget http://production.cf.rubygems.org/rubygems/rubygems-2.1.7.tgz
    [root@centosAshley02 src]# tar zxvf rubygems-2.1.7.tgz
    [root@centosAshley02 src]# cd rubygems-2.1.7
    [root@centosAshley02 rubygems-2.1.7]# /usr/local/bin/ruby setup.rb
    
    Check the rubygem installation, the back to parent directory
    [root@centosAshley02 rubygems-2.1.7]# gem -v
    2.1.7
    [root@centosAshley02 rubygems-2.1.7]# cd
    
    Step:3 Install Sqlite
    If you don't have curl then execute the following
    [root@centosAshley02 ~]# yum install curl
    
    Install rvm
    curl -L get.rvm.io | bash -s stable
    
    Source the file rvm.sh
    source /etc/profile.d/rvm.sh
    
    for me to check, I type.
    [root@centosAshley02 ~]# rvm requirements
    Checking requirements for centos.
    Requirements installation successful.
    
    Step 4: Sqlite
    [root@centosAshley02 ~]# cd /opt/
    [root@centosAshley02 opt]# wget http://www.sqlite.org/2013/sqlite-autoconf-3080100.tar.gz
    [root@centosAshley02 opt]# tar xvzf sqlite-autoconf-3080100.tar.gz
    [root@centosAshley02 opt]# ln -s /opt/sqlite-autoconf-3080100/ /opt/sqlite3
    [root@centosAshley02 opt]# cd sqlite3/
    [root@centosAshley02 opt]# ./configure --prefix=/opt/sqlite3
    
    Configure the .bashrc
    [root@centosAshley02 ~]# vi .bashrc
    
    add on the .bashrc LD_LIBRARY_PATH=/usr/local/lib64 then source and test the varibale
    [root@centosAshley02 ~]# source .bashrc
    [root@centosAshley02 ~]# echo $LD_LIBRARY_PATH
    /usr/local/lib64
    [root@centosAshley02 ~]# export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
    
    Then make and make install
    [root@centosAshley02 ~]# cd /opt/sqlite3
    [root@centosAshley02 sqlite3]# make
    [root@centosAshley02 sqlite3]# make install
    
    Test the sqlite,
    [root@centosAshley02 ~]# mkdir -p /usr/local/sqlite/var
    [root@centosAshley02 ~]# sqlite3 /usr/local/sqlite/var/testdb
    SQLite version 3.6.20
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite>
    

    Then .exit, for more info type .help
    Step 5: Install the rails
    This may take time. Please be patient.
    [root@centosAshley02 ~]# gem install rails
    
    Check the gems installed.
    [root@centosAshley02 ~]# gem list
    
    *** LOCAL GEMS ***
    
    actionmailer (4.0.1)
    actionpack (4.0.1)
    activemodel (4.0.1)
    activerecord (4.0.1)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.1)
    arel (4.0.1)
    atomic (1.1.14)
    bigdecimal (1.2.0)
    builder (3.1.4)
    bundler (1.3.5)
    erubis (2.7.0)
    hike (1.2.3)
    i18n (0.6.5)
    io-console (0.4.2)
    json (1.7.7)
    mail (2.5.4)
    mime-types (1.25.1)
    minitest (4.3.2)
    multi_json (1.8.2)
    polyglot (0.3.3)
    psych (2.0.0)
    rack (1.5.2)
    rack-test (0.6.2)
    rails (4.0.1)
    railties (4.0.1)
    rake (0.9.6)
    rdoc (4.0.0)
    sprockets (2.10.1)
    sprockets-rails (2.0.1)
    test-unit (2.0.0.0)
    thor (0.18.1)
    thread_safe (0.1.3)
    tilt (1.4.1)
    treetop (1.4.15)
    tzinfo (0.3.38)
    
    Install the sqlite-ruby
    [root@centosAshley02 ~]# yum install sqlite-devel
    [root@centosAshley02 ~]# gem install sqlite3
    
    check the gem list again and find the sqlite
    [root@centosAshley02 ~]# gem list
    
    *** LOCAL GEMS ***
    
    actionmailer (4.0.1)
    actionpack (4.0.1)
    activemodel (4.0.1)
    activerecord (4.0.1)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.1)
    arel (4.0.1)
    atomic (1.1.14)
    bigdecimal (1.2.0)
    builder (3.1.4)
    bundler (1.3.5)
    erubis (2.7.0)
    hike (1.2.3)
    i18n (0.6.5)
    io-console (0.4.2)
    json (1.7.7)
    mail (2.5.4)
    mime-types (1.25.1)
    minitest (4.3.2)
    multi_json (1.8.2)
    polyglot (0.3.3)
    psych (2.0.0)
    rack (1.5.2)
    rack-test (0.6.2)
    rails (4.0.1)
    railties (4.0.1)
    rake (0.9.6)
    rdoc (4.0.0)
    sprockets (2.10.1)
    sprockets-rails (2.0.1)
    sqlite3 (1.3.8)
    sqlite3-ruby (1.3.3)
    test-unit (2.0.0.0)
    thor (0.18.1)
    thread_safe (0.1.3)
    tilt (1.4.1)
    treetop (1.4.15)
    tzinfo (0.3.38)
    
    Almost done, We have to install execjs for javascript runtime and rubyracer
    gem install debugger-ruby_core_source -v 1.2.2
    sources: http://guides.rubyonrails.org/getting_started.html
    https://gist.github.com/fabrizioc1/1083087
    http://sqlrelay.sourceforge.net/sqlrelay/gettingstarted/sqlite.html https://github.com/cldwalker/debugger/issues/12

    Monday, November 25, 2013

    Configuring Network in Centos 6.4 Virtual Box with Screen Shots

    This is a guide on configuring network in Centos Virtual Box with screenshots

    Requirements

    1. Virtual Box 
    2. Centos 6.3 or 6.4 (I used 6.4 )

    Step 1 : Configure Virtual Box Network Settings

    There are different modes or ways you can configure Virtual box network settings.
    1. Not Attached
    2. NAT
    3. Bridged Adapter
    4. Internal Network
    5. Host-Only Adapter
    6. Generic Driver
    7. You can find more details about the different modes here.
    I will be using the Bridged Adapter mode for this guide. It is faster as it treat the VM as an individual host within the network.
    Open Virtual Box and right click on your CentOS VM, and click on “Settings“.
    Go to the "Network tab" then changed the "Attached to" field to "Bridged Adapter". Choose "Name" to your network interface. Then click "ok" to save the configuration. Click "Show" to run the machine.
     

    Step 2: Configure CentOS network settings

    Method 1: Dynamic IP

    We can configure the network by using Dynamic IP address which are assigned automatically by the DHCP server. This is the simplest way to configure your network.

    NOTE: You will have a line that starts with HWADDR in the your config file, do not change or modify that line. In your terminal, type the following:
    vi /etc/sysconfig/network-scripts/ifcfg-eth0
    Now, add/modify the file as follows (DO NOT CHANGE the HWADDR line your config file):
    DEVICE=eth0
    HWADDR=08:00:27:36:3F:37
    TYPE=Ethernet
    UUID=1e4ee4d1-e438-4db2-9cb5-45e7a488be88
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=dhcp
    
    Now, save the file by pressing “ESC” and typing :wq and hit ENTER.
    To view your network config file. type the following in the terminal:
    [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    HWADDR=08:00:27:36:3F:37
    TYPE=Ethernet
    UUID=1e4ee4d1-e438-4db2-9cb5-45e7a488be88
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=dhcp
    
    Now, you will have to restart your network. You can do so by typing the following in the terminal:
    service network restart
    Your result must be
    [root@localhost ~]# service network restart
    Shutting down interface eth0:                              [  OK  ]
    Shutting down loopback interface:                          [  OK  ]
    Bringing up loopback interface:                            [  OK  ]
    Bringing up interface eth0:
    Determining IP information for eth0... done.
                                                               [  OK  ]
    
    To view your IP address, type the following in your terminal:
    ifconfig eth0
    You can see your IP Address of the interface eth0 next to the field “inet addr:” as shown below:
    Now, if you have internet access, then you can check if you are able to ping any website. And you should be able to get the reply. For example, in your terminal type:
     
    ping google.com
    
     
    You can press CTRL+ C to stop the ping command.
    So, Hurray! you have successfully setup up your network in your CentOS Virtual Box.

    Method 2: Static IP

    We can also assign the network information manually by assigning the IP Address, NETMASK , GATEWAY in the network interface config file.
    NOTE: You will have a line that starts with HWADDR in your config file, do not change or modify that line.

    Step 1:

    In you terminal, type:
    vi  /etc/sysconfig/network-scripts/ifcfg-eth0
    
    Now, edit/merge the file to the following
    DEVICE=eth0
    HWADDR=08:00:27:EB:C1:68
    TYPE=Ethernet
    UUID=38341514-767c-4546-9154-859a7b495642
    ONBOOT=yes
    NM_CONTROLLED=no
    BOOTPROTO=static
    IPADDR=172.16.2.105
    GATEWAY=172.16.0.1
    
    Now, press ESC and type :wq and hit ENTER to save and exit the configuration file.
    cat /etc/sysconfig/network-scripts/ifcfg-eth0
    
     

    Step 2: Change Host name: 

    To change host name , you have to edit the config file /etc/sysconfig/network.
    vi /etc/sysconfig/network
    
    Now, you will see a file such as the one shown below:

    To change the hostname , you can change the highlighted to any thing you want. Press ‘i‘ or INSERT to edit the file. After making necessary changes, you can save the file by pressing ESC followed by :wq and hit ENTER.
    Now, restart to make necessary changes. You can reboot by typing the following in the command line:
    reboot
    After reboot, login and check your hostname by typing the following in the terminal / command line :
    hostname
    Step 3: Assign DNS Server IP

    To manually assign primary and secondary DNS Server IP addresses, in your terminal type:
    vi /etc/resolv.conf
    Now, edit this file to the following:
    ; generated by /sbin/dhclient-script
    nameserver 8.8.8.8
    nameserver 8.8.4.4
    
    Now, press ESC and type :wq and hit ENTER to save and exit the configuration file.
    Now, if you want you can make sure you have entered and saved the correct configuration(It is a good practice to double check :D ). To view your dns config file, in your terminal type:
    cat  /etc/resolv.conf

    Step 4: Restart network:

    Finally, all you have to do is to restart your network service. To so so, type the following in the terminal:
     service network restart
    
    [root@centosAshley02 ~]# service network restart
    Shutting down interface eth0:                              [  OK  ]
    Shutting down loopback interface:                          [  OK  ]
    Bringing up loopback interface:                            [  OK  ]
    Bringing up interface eth0:                                [  OK  ]
    
    Now, you can check your Current IP configuration, by typing the following in the terminal:
    Now, if you have internet access, then you can check if you are able to ping any website. And you should be able to get the reply. For example, In your terminal type:
    ping imbaprogramming.blogspot.com
    

    You can press CTRL+ C to stop the ping command.
    So, Hurray! you have successfully setup up your network manually in your CentOS Virtual Box.
     
    source : http://extr3metech.wordpress.com/2013/05/23/configuring-network-in-centos-6-3-virtual-box-screenshots/

    Monday, November 18, 2013

    Asterisk RealTime MeetMe

    1. Installing and Configuring ODBC


    The ODBC connector is a database abstraction layer that makes it possible for Asterisk to communicate with a wide range of databases without requiring the developers to create a separate database connector for every database Asterisk wants to support.
    First Install the ODBC LINUX

    yum install -y unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel
    unixODBC-devel package because it is used by Asterisk to create the ODBC modules Next,

     Configure the PostgreSQL ODBC driver  
    [PostgreSQL]
    Description             = ODBC for PostgreSQL
    Driver          = /usr/lib/psqlodbc.so
    Setup           = /usr/lib/libodbcpsqlS.so
    Driver64                = /usr/lib64/psqlodbc.so
    Setup64         = /usr/lib64/libodbcpsqlS.so
    FileUsage               = 1
    UsageCount              = 5
    
    To test execute
    # odbcinst -q -d 
    [PostgreSQL]
    

    Configuring ODBC for MySQL

    On CENTOS
    [MySQL]
    Description = ODBC for MySQL
    Driver = /usr/lib/libmyodbc3.so
    Setup = /usr/lib/libodbcmyS.so
    FileUsage = 1
    
    On UBUNTU
    [MySQL]
    Description = ODBC for MySQL
    Driver = /usr/lib/odbc/libmyodbc.so
    Setup = /usr/lib/odbc/libodbcmyS.so
    FileUsage = 1
    
    NOTE: On 64-bit systems, you will need to change the path of the libraries from /usr/lib/ to /usr/lib64/ in order to access the correct library files.
    On my 64 bit CENTOS
     
    [MySQL]
    Description             = ODBC for MySQL
    Driver          = /usr/lib/libmyodbc5.so
    Setup           = /usr/lib/libodbcmyS.so
    Driver64                = /usr/lib64/libmyodbc5.so
    Setup64         = /usr/lib64/libodbcmyS.so
    FileUsage               = 1
    UsageCount              = 5
    
    Verify the driver
    # odbcinst -q -d
    [PostgreSQL]
    [MySQL]
    
    Next, configure the /etc/odbc.ini file, which is used to create an identifier that Asterisk will use to reference this configuration.
    [ConfConnection]
    Description             = MySQL connection to 'asterisk' database
    Driver          = MySQL
    Database                = asteriskdb
    Server          = localhost
    UserName                = root
    Password                = allysamae
    Port            = 3306
    Socket          = /var/lib/mysql/mysql.sock
    
    NOTE: On Ubuntu 10.10, the socket location is /var/run/mysqld/mysqld.sock.

    Validating the ODBC Connector
     
    Now, verify that you can connect to your database using the isql application. echo the select 1 statement and pipe it into isql, which will then connect using the asterisk-connector section you added to /etc/odbc.ini. You should get the following output (or at least something similar; we’re looking for a result of 1 rows fetched):
    # echo "select 1" | isql -v ConfConnection
    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    SQL> select 1
    +---------------------+
    | 1                   |
    +---------------------+
    | 1                   |
    +---------------------+
    SQLRowCount returns 1
    1 rows fetched
    
     
    Recompile Asterisk

    With unixODBC installed, configured, and verified to work, you need to recompile Asterisk so that the ODBC modules are created and installed. Change back to your Asterisk source directory and run the ./configure script so it knows you have installed unixODBC:
    # cd /usr/src/asterisk*
    # ./configure
    # make menuselect
    # make install
    
    NOTE: You will want to run make menuselect to verify that the ODBC-related modules are enabled. These include cdr_odbc, cdr_adaptive_odbc, func_odbc, func_realtime, pbx_realtime, res_config_odbc, and res_odbc. For voicemail stored in an ODBC database, be sure to select ODBC_STORAGE from the Voicemail Build Options menu. You can verify that the modules exist in the /usr/lib/asterisk/modules/ directory.

    Configuring res_odbc to Allow Asterisk to Connect Through ODBC

    Asterisk ODBC connections are configured in the res_odbc.conf file located in /etc/asterisk. The res_odbc.conf file sets the parameters that various Asterisk modules will use to connect to the database.
    NOTE: The pooling and limit options are quite useful for MS SQL and Sybase databases. These permit you to establish multiple connections (up to limit connections) to a database while ensuring that each connection has only one statement executing at once (this is due to a limitation in the protocol used by these database servers).
    ; The context name is what will be used in other configuration files, such
    ; as extconfig.conf and func_odbc.conf, to reference this connection.
    [asteriskdb]
    ;
    ; Permit disabling sections without needing to comment them out.
    ; If not specified, it is assumed the section is enabled.
    enabled => yes
    ;
    ; This value should match an entry in /etc/odbc.ini
    ; (or /usr/local/etc/odbc.ini, on FreeBSD and similar systems).
    dsn => ConfConnection
    ;
    ; Username for connecting to the database.  The user defaults to the context name if unspecified.
    username => root
    ;
    ; Password for authenticating the user to the database.  The default
    ; password is blank.
    password => mypassword
    ;
    ; Build a connection at startup?
    pre-connect => yes
    
    The dsn option points at the database connection you configured in /etc/odbc.ini, and the pre-connect option tells Asterisk to open up and maintain a connection to the database when loading the res_odbc.so module. This lowers some of the overhead that would come from repeatedly setting up and tearing down the connection to the database.
    Once you’ve configured res_odbc.conf, start Asterisk and verify the database connection with the odbc show CLI command:
    *CLI> odbc show asteriskdb
    
    ODBC DSN Settings
    -----------------
    
      Name:   asteriskdb
      DSN:    ConfConnection
        Last connection attempt: 2013-11-19 09:29:44
      Pooled: No
      Connected: Yes
    
    

    grant all privileges on *.* to root@172.16.2.133 identified by '!green0909!';

    sources: http://www.asteriskdocs.org/en/2nd_Edition/asterisk-book-html-chunk/installing_configuring_odbc.html