Thursday, September 6, 2012

VirtualBox CentOS 5.8 guest DHCP add search

I have a CentOS 5.8 guest using VirutalBox. There are two network interface, one is NAT, and the other is "Host Only". I have three environments
  1. In company, there are three networks mycompany.corp.com, mycompany.net and mycompany.dmz.com;
  2. At home, I want to access the Internet without VPN;
  3. Use VPN at home to access company's networks.
Here is my issue: If check "Automatically obtain DNS information from provider" in network configuration, only mycompany.corp.name in search of /etc/resolv.conf
; generated by /sbin/dhclient-script
search mycompany.corp.com
nameserver 10.184.77.23
nameserver xx.10.217.47
nameserver 192.168.0.1

This is not convenient because I have to type the full DNS name if I want to access a host hostA.mycompany.net instead of hostA.

I can add the other twos in DNS tab network-configuration, but the change will be overwritten by dhclient when the interface is restarted, or machine reboot.

If set DNS name servers will be different for company and home. It works in one environment and fails in the others. Company internal DNS servers are accessible from outside without VPN.

Here is my solution to config dhclient to include the other two network in DNS search like this:

add /etc/dhclient-eth1.conf

interface "eth1" {
    append domain-name " mycompany.net mycompany.dmz.com";
};
Then restart the network:
sudo /sbin/service network restart
NOTES:
  • a blank in domain-name value is important because the string is simply concatenated to the string retrieved from the provider.
  • if it is not working, check /var/log/message
  • use "domain-name" for search. "domain-search" is not correct for CentOS 5.8.

Wednesday, August 1, 2012

Run multiple commands in db2cmd

In Windows DOS, you need to run db2cmd before you can do any db2 command. If you want to run multiple commands, usually you can output the commands into a file and call db2cmd like this:
db2cmd -c db2 -tvf cmd_file.sql
But if you don't want to generate a file, here is how
db2cmd -c db2 connect to mydb user me using passwd && db2 select * from my_table && db2 terminate
DOS uses && to run multiple commands in one line.

Monday, June 11, 2012

Fixing CentOS Root Certificate Authority Issues

Here is the link: http://eric.lubow.org/2011/security/fixing-centos-root-certificate-authority-issues/ I backed up the existing certificate file just to be on the safe side. # cp /etc/pki/tls/certs/ca-bundle.crt /root/backup/ To fix the issue, just download a new certificate bundle. I used the one from haxx.se. # curl http://curl.haxx.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt

Thursday, May 31, 2012

Issues after installing VirtualBox 4.1.16

After upgrading to VirtualBox 4.1.16 on my Windows 7 laptop, I found several issues.
  • My Guest "Host-Only Network Interface" stopped working.

    IP address for my guest CentOS 5.6 was 192.168.56.101, but CentOS said the address was already occupied. I found that there WERE processes in Resource Monitor using that address and listening on 137/138/139. It turns out that my "VirtualBox Host-Only Network adapter" was using 192.168.56.101.

    Here is how you can access Resources Monitor:

    • Right click task bar
    • Start Task Manager
    • Performance
    • Resource Monitor
    • Network
    • Listening Ports

    After installing/uninstalling VirutalBox several times, "VirtualBox Host-Only Network" adapter went back to 192.168.56.1.

  • Then another weird thing happened: I lost all printers and couldn't even access any Window File server. After several tries, I found that Network feature "Client for Microsoft Networks" were gone for "Local Area Connection" and "Wireless Network Connection". I forget if I deleted it or it was deleted during upgrading VirtualBox. Installing "Client for Microsoft Networks" restored my printers and I can access all file servers.

Wednesday, May 30, 2012

Setup Git-P4 using puppet

git-p4 is included into git RPM in CentOS 5.6, but it is not setup by default. Here is my puppet module for setup git-p4:
class git (
  $version = "1.7.4.1"
) {

  package { "git-$version":
    ensure => present
  }

  file { "/usr/local/bin/git-p4":
    source => "/usr/share/doc/git-$version/contrib/fast-import/git-p4",
    mode => 0755,
    require => Package["git-$version"]
  }

}
References:

Git-p4: create a new project in Perforce

The wiki and tutorial of Git-P4 usually ask you to clone a project from perforce. Can I create a new project in git and import it into Perforce using Git-P4? I don't know if there is a better way to do it. Here is how I do it:
  • Create a new p4 client spec: bewang-my-app-ws with this map "//depot/my-app/... //bewang-my-app-ws/..."
  • Create a p4 workspace directory: ~/p4-ws/my-app
  • Create .p4config with one line "P4CLIENT=bewang-my-app-ws" under ~/p4-ws/my-app
  • Create a new file in ~/p4-ws/my-app, and check it into perforce.

    Although you can see a Perforce file in nested folders/directories, but there are not such objects (folders/directories) in perforce indeed. You cannot just create an empty folder and check it into Perforce.

    This step creates the depot folder. Otherwise you may see this error when you run "git p4 rebase":

    [bewang@pmaster my-app]$ git p4 rebase 
    Traceback (most recent call last):
      File "/usr/local/bin/git-p4", line 1926, in ?
        main()
      File "/usr/local/bin/git-p4", line 1921, in main
        if not cmd.run(args):
      File "/usr/local/bin/git-p4", line 1716, in run
        sync.run([])
      File "/usr/local/bin/git-p4", line 1673, in run
        changes = p4ChangesForPaths(self.depotPaths, self.changeRange)
      File "/usr/local/bin/git-p4", line 442, in p4ChangesForPaths
        assert depotPaths
    
  • Create a folder for git repository: ~/git/my-app
  • Copy ~/p4-ws/my-app/.p4config to ~/git/my-app/.p4config
  • Run "git p4 clone //depot/my-app ."
  • You should see the file you just checked in and .git folder under ~/git/my-app
  • Work on your git repository
  • Run "git p4 rebase" before you want to check-in into perforce
  • Then run "git p4 submit" to submit each git commit to perforce
  • I can totally work offline without Perforce server

Thursday, May 17, 2012

Implements CORS using Backbone.js and Rails3

I encountered "406 Not Aceeptable" issue when my Backbone.js application fetch models in json from Rail server using CORS. Because this is a CORS call, I always doubt if something is wrong in my CORS headers, but it is Rails who causes the problem, because it tries to handle the request as HTML, see the log:
Started GET "/components/1" for 127.0.0.1 at 2012-05-14 07:48:08 -0700
Processing by ComponentsController#show as HTML
  Parameters: {"id"=>"1"}
Completed 406 Not Acceptable in 1424ms (ActiveRecord: 1283.8ms)
The reason why I got this error is that my application is supposed to accept and respond JSON only. So my controller only responds a JSON result.
  def show
    set_access_control_headers
    @components = ComponentModel.today_component_status(params[:id]).first
    respond_to do |format|
      format.json { 
        render :json => @components 
      } 
    end
  end 
This page is very helpful on stackoverflow: http://stackoverflow.com/questions/9241045/backbone-client-with-a-remote-rails-server