Clint Liang's

I share my successful stories and things I learned about life, coding, startup and entrepreneurship

VMWare NAT Problem Fix: How to Set Up Host-only Virtual Network on Ubuntu

Purpose:

I only have one IP address assigned to my server and I have multiple virtual machines hosted on the server. In order to make those virtual machines access the Internet, I set up the VMWare network to be NAT. However, once a while the vmware NAT process runs 100% CPU and crashed the whole syste that I have to restart the machine. Replacing NAT with host-only virtual network is a work-around solution I found.

Procedure:

  1. Virtual server configuration:
    1. Run /usr/bin/vmware-config.pl, select host-only network instead of NAT

      *note: if the Network Connections can not find any network interface (e.g. eth0), edit /etc/network/interfaces and comment out all except the following:

      auto lo

      iface lo inet loopback

    2. On vmware web interface, change network adapter to host-only.
    3. Turn on virtual server and config its ethernet adapter as following:

      Static IP: 172.16.96.100
      Primary DNS: 64.15.139.162
      Secondary DNS: 208.67.222.222
      Gateway: 172.16.96.1

      *note: the subnetwork are different each time you run vmware-config.pl. Make it to whatever static IP address for iptable NAT rules

  2. Iptables rules

    Chain INPUT (policy ACCEPT)

    target prot opt source destination

    ACCEPT tcp — anywhere anywhere tcp dpt:www

    ACCEPT tcp — anywhere anywhere tcp dpt:ssh

    ACCEPT tcp — anywhere anywhere tcp dpt:2222

    ACCEPT tcp — anywhere anywhere tcp dpt:https

    ACCEPT tcp — anywhere anywhere tcp dpt:8222

    ACCEPT tcp — anywhere anywhere tcp dpt:8333

    ACCEPT tcp — anywhere anywhere tcp dpt:902

    ACCEPT tcp — anywhere anywhere tcp dpt:smtp

    DROP all — anywhere anywhere

    Chain FORWARD (policy ACCEPT)

    target prot opt source destination

    Chain OUTPUT (policy ACCEPT)

    target prot opt source destination

  3. Modify /etc/fstab to the new base virtual adapter IP address.
  4. Modify /etc/samba/smb.conf to recoganize the new virtual adapter vmnet1
  5. To fix SSH login slow problem edit /etc/ssh/sshd_config and add a line “UseDNS no”

How to Set Up Your Own Private Git Server on Ubuntu

This tutorial assumes that you have openssh-server installed on your server so that you can ssh on to it. You should have a local repository on your development machine ready to go.

Set up your sever

1. Install git on your server

sudo apt-get install git-core

2. Create a git ssh user on your server (if you wish to use your own user, jump to step 4)

sudo adduser git

3. Create git ssh user home folder

sudo mkdir /home/git/.ssh
sudo chown -R git:git /home/git/.ssh

4. Add your ssh key

if you wish to use your ssh key, copy your public key {development_machine}:~/.ssh/id_rsa.pub to {server}:/home/{GIT_SSH_USER}/.ssh/authorized_keys

5. Create an empty repository on server

mkdir {PATH_TO_REPO}/myrepo.git
cd {PATH_TO_REPO}/myrepo.git
git init –bare

Configure your development machine

cd {YOUR_LOCAL_REPO} git remote add {REPO_NAME} git@{SERVER_NAME_OR_IP}:{PATH_TO_REPO}/myrepo.git
git push {REPO_NAME} master

Add a default merge and remote:

git config branch.master.remote {repo_name} && git config branch.master.merge refs/heads/master

Reference

http://tumblr.intranation.com/post/766290565/how-set-up-your-own-private-git-server-linux

How to add weather indicator on Ubuntu 11.04 (Natty Narwhal)

Upgrading from Ubuntu 10.10 to 11.04, I enjoy the new unity launcher and other new features. However, I found one of the useful application indicator-weather is missing. After searching on the Internet, I found the solution and I am a happy Ubuntu user again:) Here’s how:

The weather indicator on Ubuntu 11.04 is not installed by default. You need to install it yourself. Open a terminal and type the following command: >

$ sudo apt-get install indicator-weather

After installing, you want to add it to startup application. Startup Applications>Add>Command: indicator-weather, fill the rest of fields and restart the x server. Enjoy:)

Set Up Trac On Ubuntu

1. Install dependencies:

$ sudo /etc/init.d/apache2 stop
$ sudo apt-get install libapache2-mod-python
$ sudo apt-get install apache2 libapache2-svn
$ sudo apt-get install python-setuptools
$ sudo apt-get install python-pgsql
$ sudo /etc/init.d/apache2 start

2. Create postgres user account “tracuser” and database “trac”

$ sudo su postgres
postgres@mapsys-dev-00: createuser -U postgres -E -P tracuser
postgres@mapsys-dev-00: createdb -U postgres -O tracuser -E UTF8 trac

3. Create trac environment directory (/var/www/trac_projects/mapsys_trac)

$ sudo mkdir /var/www/trac_projects
$ sudo chown -R www-data /var/www/trac_projects
$ sudo mkdir /var/www/trac_projects/mapsys_trac
$ sudo chown -R www-data /var/www/trac_projects/mapsys_trac

4. Install trac

$ sudo apt-get install trac

5. Initialize project with trac-admin

$ cd /var/www/trac_projects
/var/www/trac_projects$ sudo trac-admin mapsys_trac initenv

And then follow the instructions:

Project Name [My Project]> Mapsys
Database connection string [sqlite:db/trac.db]> postgres://tracuser:{password}@localhost/trac
Repository type [svn]>
Path to repository [/path/to/repos]> /repository

6. Change the owner and do a test run with the webuser.

$ sudo chown -R www-data /var/www/trac_projects/mapsys_trac
$ sudo -u www-data tracd –port 8000 /var/www/trac_projects/mapsys_trac
^C$

You can test it at: http://localhost:8000

7. Setup Trac to run with apache.

create trac.conf

$ sudo gedit /etc/apache2/sites-available/trac.conf

Configure the following in trac.conf

    <Location /trac> #set up Trac handling

        SetHandler mod_python

        PythonHandler trac.web.modpython_frontend

        PythonOption TracEnvParentDir /var/www/trac_projects

        PythonOption TracUriRoot /trac



        # Use the SVN password file.

        AuthType Basic

        AuthName "Subversion Repository"

        AuthUserFile /etc/apache2/dav_svn.passwd

        Require valid-user  

    </Location>



8. Setup svn password

$ sudo htpasswd -c /etc/apache2/dav_svn.passwd {first-svn-user}
$ sudo htpasswd /etc/apache2/dav_svn.passwd {more-user}
$ sudo /etc/init.d/apache2 restart

9. Install the python module and make the site available

$ sudo apt-get install libapache2-mod-python
$ cd /etc/apache2/sites-enabled
$ sudo ln -s ../sites-available/trac.conf 010-trac
$ sudo /etc/init.d/apache2 restart

10. Modify /etc/apache2/httpd.conf

$ sudo nano /etc/apache2/httpd.conf

Add the following to the end.

    Alias /trac "/var/www/trac_projects/mapsys_trac/htdocs"

    <Location "/cgi-bin/trac.cgi">

        SetEnv TRAC_ENV "/var/www/trac_projects/mapsys_trac"

    </Location>



And then restart apache service

$ sudo /etc/init.d/apache2 restart

Now you can test it at http://localhost/trac

*note the username and password is what you created in step 8

Reference: https://help.ubuntu.com/community/UbuntuTracHowto#Server