Difference between revisions of "Red Cloud Linux Instances"

From CAC Documentation wiki
Jump to navigation Jump to search
Line 107: Line 107:
 
# run <code>~/bin/start_vncserver.sh</code>
 
# run <code>~/bin/start_vncserver.sh</code>
  
You can '''stop''' the NVC server by running <code>vncserver -kill :1</code>
+
To find the port, you can run e.g. <code>ps gxu | grep vnc</code>.
 +
 
 +
You can '''stop''' the NVC server by running <code>vncserver -kill :1</code>. If this doesn't work,
 +
you can try <code>pkill Xvnc</code>.
  
 
To '''change or reset the VNC password''', you can simply run <code>vncpassword</code>
 
To '''change or reset the VNC password''', you can simply run <code>vncpassword</code>

Revision as of 16:13, 21 September 2020

Linux Instances can be created and maintained on Red Cloud using the OpenStack Web Interface. This documentation assumes a basic understanding of OpenStack, so please review that page as needed. If you are new to Linux, you may want to read the Linux Tutorial first. It is also a good idea to be familiar with the Linux Tutorial if you have not previously done Linux system administration, which is an assumed prerequisite to managing Linux Instances. Additionally, you may find the Introduction to Linux topic on the Cornell Virtual Workshop helpful.

Creating a New Linux Instance

You can boot an instance with most modern Linux distributions. Currently Red Cloud offers pre-made VM images running the following Linux distributions:

  • CentOS
  • Ubuntu (including LTS)

Steps

  1. Log in to the OpenStack Web Interface (check out how to log in if you need to)
  2. If you have not already, create a key pair
  3. If you have not already, create a security group. Note that your security group should include the inbound SSH rule so you can connect to it.
  4. Optional: Set up a Private Network
  5. Select Launch Instance from the Instances page
  6. Follow the instructions about launching a new instance, and select one of the a CentOS or Ubuntu images under the Source tab
  7. Optional: Create and attach a Volume
  8. Optional: Associate a Floating IP address

Now that you have created and launched an instance, your next steps will be to connect to it and set up a new user account. See the CentOS steps or Ubuntu steps for more information on how to set up a new user, update, and install software for each distribution.

Accessing Instances

First, establish access to your instance using Secure Shell (ssh), possibly including X Windows for remote graphical display. If you are at all unfamiliar with Linux, we recommend following the Linux Tutorial. If you would like to have a desktop environment (not available by default for Linux instances), then you may want to follow the steps for XFCE Desktop on CentOS. Establishing an SSH connection is a prerequisite for creating a Linux desktop environment such as XFCE.

Secure Shell (SSH)

The main requirements for logging in to your instance using secure shell are:

  • The security group for your instance must permit SSH connections (TCP port 22) from your current IP address.
  • You must use the private key that matches the public key in the key pair you specified when launching the instance.
  • You must log in to your instance using the correct initial user name:
    • For CentOS 6 and 7, the user name is centos,
    • For CentOS 8, the user name is cloud-user, and
    • For Ubuntu, it is ubuntu.

To log in through SSH, specify the key pair file (for example my_key.pem), account name and IP address as follows:

 ssh -i my_key.pem <account>@<IP address of your instance>

For more information on how to use SSH, see the Connect to Linux page.

Note: Transferring files can also be done over ssh. See the scp and sftp commands, or programs like WinSCP and similar software for Mac OS X.

Troubleshooting

  • Check the instance's console in the OpenStack Web Interface. Did the instance boot successfully?
  • Do the security group's rules allow incoming ssh connections (TCP port 22) from the IP address of your computer?
  • Is your instance on the public network? If not, does it have an associated floating IP address?
  • Make sure you are using the correct username:
    • If you are using Ubuntu, did you login as the ubuntu user instead of root? For more information on that, see the Linux Tutorial.
    • If you are using CentOS 6 or 7, did you login as the centos user instead of root?
    • If you are using CentOS 8, did you login as the cloud-user user?
  • Did you create a key pair and make sure to select it when creating an instance?
  • Are you using your key pair in the command? See the SSH instructions above for an example.
  • If you get an unexpected password prompt:
    • Did you use the correct user name? See suggestions above.
    • Make sure your private key matches the public key of the key pair.
      1. On your computer, run: ssh-keygen -y -f <private key file>
      2. Does the output match the public key list here? https://redcloud.cac.cornell.edu/dashboard/project/key_pairs/<your keypair name>/
    • Make sure your private key file is saved as a ".pem" extension and that it has the proper permissions:

      chmod 600 <key name>.pem

XFCE Desktop on CentOS

In case one would prefer a desktop environment over a command-line, this section details the steps to setting up an XFCE Desktop Environment on a CentOS 7.4 instance. Other typical Linux desktop environments, such as Gnome, are also available but XFCE is used as an example here. Additionally, setting up a desktop environment may work on Ubuntu instances as well, with some differences. Once the environment is set up, you can run a VNC server and connect to it through an ssh tunnel.

XFCE Setup

  1. Log in as root via ssh as described above.
  2. Install needed packages:
    • yum groupinstall xfce
    • yum install tigervnc-server
  3. Install some additional software that most users will want. These are only suggestions, and this is not a comprehensive list

VNC User Setup

For each user that will want to use the XFCE Desktop, you will need to set up VNC (Virtual Network Computing) cability. To do this, follow the directions below. Alternatively, there is also an Easy guide to secure VNC server with TLS encryption.

  1. Open a shell as that user
  2. vncpasswd
    • Sets the user's VNC password
    • This step is not necessary for read-only VNC
    • This creates a ~/.vnc folder
  3. vim ~/.vnc/xstartup
    • Paste this text into the file:
      #!/bin/bash
      xrdb $HOME/.Xresources
      startxfce4 &
  4. chmod 775 ~/.vnc/xstartup
  5. mkdir ~/bin
  6. vim ~/bin/start_vncserver.sh
    • Paste this text into the file:
      #!/bin/bash
      vncserver -geometry 1680x1050
  7. chmod 775 ~/bin/start_vncserver.sh

Using VNC

A brief overview for users is provided here, and for more information please see the Using VNC section on our Getting Started page.

Manage the VNC Server

Whenever an instance gets rebooted, you can restart the VNC server by doing the following

  1. ssh into the instance
  2. run ~/bin/start_vncserver.sh

To find the port, you can run e.g. ps gxu | grep vnc.

You can stop the NVC server by running vncserver -kill :1. If this doesn't work, you can try pkill Xvnc.

To change or reset the VNC password, you can simply run vncpassword

To change the screen resolution:

  • Permanently: edit the script ~/.vnc/xstartup
  • For this session only: use Applications->Display
View the Desktop
  1. Open a local shell and ssh to establish the tunnel (recommended local port 10000):
    • ssh -L 10000:localhost:5901 <remote ip>
    • Note: When this shell is closed, the VNC viewer will have to close, too, though VNC is still running.
  2. In a VNC viewer app, connect to the VNC server localhost:10000 (or whichever port you chose above).
    • This should open a window showing the desktop
    • The first time you do this:
      • For the remote computer, you may have to dismiss a warning dialog
      • You will need to initialize a "panel". Click "Use default config"

Note for Windows users: You can also find useful instructions on the VNC Tunnel Windows page. You may also want to look into OpenSSH or Bash on Ubuntu on Windows.

Instance Maintenance

All self-managed desktops, laptops, servers, and Red Cloud instances, both Windows and Linux, should be updated with Operating System, Adobe Flash, Acrobat, and Reader critical and security updates on a monthly basis. For Linux instances:

  1. Check for updates
    • Ubuntu: sudo apt update
    • CentOS: yum check-update
  2. Install updates
    • Ubuntu: sudo apt upgrade
    • CentOS: sudo yum update
  3. Reboot the instance with sudo reboot on both Ubuntu and CentOS

Before rebooting make sure to save all active work. Rebooting will disconnect you from the instance. Wait a minute or two to allow the instance to restart before reconnecting. When you reconnect, you should verify that the updates were applied by repeating step 1.

Initialize and Mount a Volume

The instructions here are for formatting and mounting attached volumes, though steps like these can only be performed if you have allocated and attached the volume through OpenStack, which can be done while the instance is running.

Note: These instructions assume you are the root user. If you are not (such as on Ubuntu), then you may need to prepend sudo where appropriate.

  1. Set up file system:
    • mkfs.ext4 /dev/vdb
  2. Make a directory where device will be mounted, for example "scratch":
    • mkdir /scratch
  3. Mount the device:
    • mount /dev/vdb /scratch
  4. To have the mount automatically renewed after reboot, add an fstab entry (this is a little dangerous)
    • vim /etc/fstab
    • Add a line with tab separations between four fields: disk device, mounted location, "ext4", "defaults":
      • /dev/vdb /scratch ext4 defaults