Tuesday, December 21, 2010

How to know free memory on linux

Command to know free memory on Linux/Unix machines

$ free -m

It will show you status in MB. You can optionally use other filters as well

-b switch displays the amount of memory in bytes

-k switch (set by default) displays it in kilobytes

-m switch displays it in megabytes.

-t switch displays a line containing the totals.

-o switch disables the display of a "buffer adjusted" line. If the -o option is not specified, free subtracts buffer memory from the used memory and adds it to the free memory reported.

-s switch activates continuous polling delay seconds apart. You may actually specify any floating point number for delay, usleep(3) is used for microsecond resolution delay times.

You can also use /proc/meminfo to see the current status of memory

$ cat /proc/meminfo

Sphere: Related Content

Sunday, December 12, 2010

Create subversion repository on Ubuntu

Recently I had to setup a ubuntu box with subversion on it. I had to also provide web access from subversion with authentication. After few hiccups I managed to do this with installing few packages and configuring them.

Step 1: login to your ubuntu box

#ssh root@x.y.z.t

Step 2: Install required packages
#yum install subversion
#yum install mod_dav_svn httpd

Step 3: Create a parent directory where all your repositories will be set up.
#mkdir -p /srv/svn

Step 4: Create a sample repository using svnadmin tool
#svnadmin create /srv/svn/app
In this step we have created a repository named as app.

Step 5: Change the user and group of the created app repository to give the permission to apache user.
#chown -R apache.apache /srv/svn/app
This user is created when you installed httpd package in step 2. Without this step user will not be able to access it via webserver http protocal, they can however access it using command promp using ssh protocol.

Step6: Restart apache webserver.
#service httpd restart

Step 7: Create a password file for the authentication of users which will be accessing your app repository via http protocol.
#mkdir -p /srv/auth/svn/
#htpasswd -c /srv/auth/svn/app.htpasswd ahsan.javed
In this step we are creating a directory first to store the htpasswd file. then using the htpasswd tool we are creating an user name and password hash entry in created file. This htpasswd tool is by default installed when you perform step 2.

Step 8: Create a virtual host for hosting your subversion access
create a new virtual host file at /etc/httpd/conf.d/svn.conf with the content

    LoadModule dav_svn_module     modules/mod_dav_svn.so
    LoadModule authz_svn_module   modules/mod_authz_svn.so

    <Location /repos>
       DAV svn
       SVNParentPath /srv/svn
    </Location>
    <Location /repos/app>
       AuthType Basic
       AuthName "Subversion Repository"
       AuthUserFile /srv/auth/svn/app.htpasswd
       Require valid-user
    </Location>

Step 9: Restart apache webserver
#service httpd restart


Step 10: Access your setup repository in a browser by typing
http://x.y.z.t:80/repos/app
This will ask a user name and password, provide the username and password created in step 7 to access the repository.

Sphere: Related Content

Thursday, December 9, 2010

Enable mysql to connect from desired remote IP

Recently I had to work on mysql server on Linux platform.

All our development was done on windows machine and everything went fine.

When we tried to migrate the same code to Linux platform, everything worked fine except that our program was not able to connect to mysql. It was continuously throwing this exception.

Caused by: java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at java.net.Socket.connect(Socket.java:478)
        at java.net.Socket.(Socket.java:375)
        at java.net.Socket.(Socket.java:218)
        at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)
        at com.mysql.jdbc.MysqlIO.(MysqlIO.java:292)

However we were able to connect via mysqladmin as follows


#mysql -u username -h localhost -p password


After doing some google I found that mysql was actually not allowing remote connections from our program. It was only allowing the Unix socket connections in case of mysql admin, thats why it was able to connect to it.

I had to change few configuration parameters in mysql configuration files as follows to allow remote connections to mysql and restart it.

# vi /etc/my.cnf
Once file opened, locate line that read as follows

[mysqld]

Add the following line at the end of this block

bind-address=YOUR-SERVER-IP
#skip-networking


Where,

    * bind-address : IP address to bind to.
    * skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should be removed from my.cnf or put it in comment state

Restart the mysql server, enter:
# /etc/init.d/mysql restart

Sphere: Related Content