Tuesday, July 12, 2016

How to resize the tmpfs (/dev/shm) in Linux

There are times when the tmp file system may become full and a need arises for resizing (or increasing the size) of the file system. This can be achieved in two ways, one is to make the change temporarily without rebooting the host; the other is to make the change permanently so that everytime the host is rebooted, the tmp file system is mounted with the modified size.

Note that the size of tmp file system can be increased to a certain predefined limit. If the size specified during mount/resize(remount) is beyond the set limit, the mount would fail and the tmp file system will not be mounted.

To view the current size of the tmp file system, the following command can be run.

~]# df -h

The output would show something like below.

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              91G   26G   61G  30% /
tmpfs                 1.9G  107M  1.8G   6% /dev/shm

  • Increasing/resizing the file system temporarily:
    The following command can be run to remount the tmp file system with an increased size.

    ~]# mount -o remount,resize=4g /dev/shm
    ~]#

  • Making the size change persist across reboot:
    To make the change persist across reboot, the entry for mounting the tmp file system in the file /etc/fstab must be modified as shown below.

    ~]# vim /etc/fstab
    #
    # /etc/fstab
    # Created by anaconda on Mon Feb 8 15:28:09 2016
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    tmpfs   /dev/shm  tmpfs  defaults,size=4g  0 0
    devpts  /dev/pts    devpts  gid=5,mode=620  0 0
    sysfs   /sys    sysfs   defaults  0 0
    proc   /proc    proc    defaults  0 0
    ~]#

Once the changes are made (using either approach) run the following command to see that the change in the size.

~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              91G   26G   61G  30% /
tmpfs                 4.0G  107M  3.9G   3% /dev/shm

Tuesday, May 10, 2016

How to Setup VNCServer on CentOS 7 for Remote Access

VNCServer helps connect to a host remotely, the clients see a graphical interface (typically the desktop manager like GNOME or XFCE or KDE). The following steps can be followed to configure VNCServer on CentOS 7 (and also RHEL7.x).

  • Install the X Window system (if not already there):

    First make sure that yum is configured. You may run the following commands (as root) view and install the X Windows System (GNOME).

    ~]# yum group list
    Installed Environment Groups:
        Server with GUI
    Available Environment Groups:
        Minimal Install
        Infrastructure Server
        File and Print Server
        Basic Web Server
        Virtualization Host
    Available Groups:
        Compatibility Libraries
        Console Internet Tools
        Development Tools
        Graphical Administration Tools
        Legacy UNIX Compatibility
        Scientific Support
        Security Tools
        Smart Card Support
        System Administration Tools
        System Management
    Done

    ~]# yum groupinstall "Server with GUI"

  • Install VNCServer:

    Install the tigervnc-server package, which provides the required VNCServer functionality.

    ~]# yum install tigervnc-server*

  • Setup VNCServer user and Firewall:

    The VNCServer runs at ports starting from 5900 and port identifies a display number. For instance port 5901 indicates VNCServer display :1 which can typically be accessed via hostname/ipaddress:1. If needed these ports should be added to the firewall as well.

    Create a user test which will be used to login from the VNC client.

    ~]# useradd testuser
    ~]# passwd testuser

    Login as testuser and set a password for VNCServer.

    ~]# su - testuser
    ~]$ vncpasswd
    ~]$ logout
    ~]#

    Let us assume that we will be hosting VNCServer at display :1 (port 5901). Add this port to the firewall.

    ~]# firewall-cmd --permanent --zone=public --add-port=5901/tcp
    ~]# firewall-cmd --reload

  • Configure VNCServer at display :1 (port 5901):

    Copy the template service file that came with the VNCServer package to /etc/systemd/system/. Rename the file to indicate display :1.

    ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

    Edit the file with an editor (vim or emacs) and change the <USER> to the testuser we have created above.

    [Unit]
    Description=Remote desktop service (VNC)
    After=syslog.target network.target

    [Service]
    Type=forking
    # Clean any existing files in /tmp/.X11-unix environment
    ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
    ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
    PIDFile=/home/<USER>/.vnc/%H%i.pid
    ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

    [Install]
    WantedBy=multi-user.target

    Save the changes made to the file. Now enable the service to run at boot and start the service.

    ~]# systemctl daemon-reload
    ~]# systemctl enable vncserver@:1.service
    ~]# systemctl start vncserver@:1.service

Now use a VNC Client software to connect to the VNCServer running on the host at <hostname>:1.

That's it!

How to Use Beyond Compare 4 as the default Mergetool and Difftool in Git

Beyond Compare 4 is a fantastic tool for comparing a variety of files and view differences in a folder tree. The feature list goes on and on. A tool so powerful as this can also be used as the default difftool and mergetool with Git Version Control system.

The following steps can be run to setup Git to work with Beyond Compare. These work on any operation system i.e., Windows, Linux etc., on Git version higher than 1.8. Ensure that bcomp.exe (Windows) or bcomp (Linux) are in the PATH, i.e., Git can access them from where difftool or mergetool commands are run.

  • Set Beyond Compare 4 as the default difftool

    ~]# git config --global diff.tool bc3
    ~]# git config --global difftool.bc3 trustExitCode true

  • Set Beyond Compare 4 as the default mergetool

    ~]# git config --global merge.tool bc3
    ~]# git config --global mergetool.bc3 trustExitCode true

Now you may run git difftool and git mergetool commands and the Beyond Compare will open up as expected.

Monday, April 18, 2016

How to Setup NFS share in Linux

NFS or Network File System is a very convenient way of allowing the data on one Linux host to be accessible on another. The procedure for setting up a NFS share and accessing the same on a client is very simple.

Step 1: Install the nfs utilities and rpcbind (portmap) on the source host.

]# yum install nfs-utils nfs-utils-lib

Step 2: Create a file /etc/exports and enter the following information.

/tmp *(rw,sync,no_root_squash)

In the line above:

/tmp           - The folder to be shared
*              - Allow access to all clients
rw             - Provide read/write access
sync           - The requests are honored only after changes are committed
no_root_squash - Allow root user to access the share

Step 3: Make sure nfs and rpcbind services start at boot. Export the list of shared folders and start these services now.

]# chkconfig rpcbind on
]# chkconfig nfs on

]# exportfs -rv

]# service rpcbind restart
]# service nfs restart

Step 4: To see the list of nfs exports, run:

]# showmount -e localhost

To see the same list from a different host, run:

]# showmount -e <ip address/hostname>

Step 5: Mount and access the contents:

]# mount -t nfs <ipaddress/hostname>:/tmp /mnt/share

How to use wget to Download all files in Linux

wget on Linux is a very useful tool to download files from the web. In its default use, one can download individual files from a directory on the web. However, downloading all files form a HTTP directory may be achieved using the following command.

]# wget -r -nH -nd -np -R index.html* http://example.com/directory/

The arguments in the command above have the following meanigns:

     -r   Recursive download
    -nH   This prevents the creation of directory structure as on the host
    -nH   This ensures that all files are saved in the current direcotry
    -nH   Don't download parent folder when -r option is given
    -nH   Reject list, exclude these file(s) from the download

Monday, March 21, 2016

How to enable 'SplitTunneling' in Windows 10

On Windows 10, when connected to a VPN connection, the computer cannot connect to other areas of internet. This is because of an issue in Windows 10 settings which doesn't allow the IPV4 properties of the VPN connection to be modified via settings (or via Control Panel). To get around this, the following fix can be used.

Open the Windows PowerShell (Windows key+S, search for PowerShell, press Enter when the search completes). In the PowerShell, type the following commands:

To display the list of VPN connections:

PS C:\> Get-VpnConnection

From this list pick the connection for which SplitTunneling needs to be enabled, and then run the following command.

PS C:\> Set-VpnConnection -Name "MY_VPN" -SplitTunneling $True

After this is done, run the Get-VpnConnection command again to ensure that the settings are saved. That's it!

Friday, February 12, 2016

How to Install pep8 utility in Python 2.6.6

Python 2.6.6 doesn't include pep8 utility by default. This can be installed by using the pip (Pip Installs Packages) package manager. However, even pip isn't available by default with Python 2.6.6.

The following steps help with installing pip and then pep8.

  • Download get-pip.py from bootstrap.pypa.io/get-pip.py.

  • Install pip by running the following command:

    C:\Python26>python.exe get-pip.py

    Once pip is installed, the pip utility can be found at C:\Python26\Scripts\pip.exe.

  • Now use the pip package manager to download pep8.

    C:\Python26\Scripts\pip.exe install pep8

    Once the installation completes, the pep8 utility can be found at C:\Python26\Scripts\pep8.exe.

Wednesday, February 10, 2016

How to Manage Software Repositories in RedHat Enterprise Linux

Software management is performed using the 'yum' utility in RedHat Enterprise Linux. Software sources or software repositories could be a media (cd), nfs or a ftp location.

  • Add a new repository:

    To add a new repository, first create a file under /etc/yum.repos.d/example.repo. Remember that the extension has to be .repo. Then run the following command to validate the repository.

    ]# yum repolist

    If the information provided in the .repo file is verified, the repository will be contacted and the file_list gets downloaded. Software hosted by that repository can then be installed onto the system.

  • Enable/Disable a repository:

    To enable an already added repository, run the following command.

    ]# yum-config-manager --enable repo_name

    To disable a repository, run the following command.

    ]# yum-config-manager --disbale repo_name

  • Delete a yum repository:

    To delete a yum repository, first delete the .repo file created at /etc/yum.repos.d/ and then run the following command. This would update the list of repositories.

    ]# yum repolist

  • List all available repositories with details:

    To list all available repositories with full details, run the following command.

    ]# yum-config-manager

Monday, February 8, 2016

How to Enable Remote Connections to a PostgreDB

The following steps can be followed to enable remote connections to Postgres Database.

1. First set a password for 'postgres' in psql, if there's already a password set, move onto next step.

~]# sudo -u postgres psql

postgres=# \password postgres
postgres=# \q

2. Next, enable Postgres service to listen on all ports. As 'root' user, edit the following file and add the line shown below and save the file. An editor like vi/vim maybe used for this task.

~]# vim /var/lib/pgsql/9.3/data/postgresql.conf

listen_addresses = '*'          # what IP address(es) to listen on;

3. Next step is to modify the Postgres configuration to customize the which hosts are allowed to access the Database remotely. Edit the following file, scroll down to the IPv4 section and add the line shown below. This indicates that Postgres may accept connections from any host. Obviously, this can be customized as per the user's needs.

~]# vim /var/lib/pgsql/9.3/data/pg_hba.conf

host    all             all             0.0.0.0/0               md5

4. Finally, restart the postgres service

~]# service postgresql-9.3 restart

Any tool such as TOAD for Postgres or pgAdmin can be used to connect to the Database.