Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

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!

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