User Tools

Site Tools


server:ubuntu20.04

Install Ubuntu 20.04 LTS as Standalone Server

This will guide you through the installation of Ubuntu 20.04 LTS as a Standalone Server.

Do Not Forget To

  • backup webapps
  • backup mysql database
  • backup ./ssh/authorized_keys
  • backup minecraft worlds (if running on ubuntu)
  • move the AP to a new adoption (if running UniFi Controller on ubuntu)
  • backup /etc/fstab (if lots of drives mounted)
  • use lsblk to get list of current drives and mount points

Install Ubuntu Server 20.04 LTE from CD / USB

  • Custom storage layout
  • Partitions: (ext4)
Size Location Notes
4 GB swap (primary) should be min sqrt(RAM) and max double RAM
6 GB / (logical) current install uses about 2.6 GB
5 GB /home (logical) current install uses about 45 MB
1 GB /boot (logical) current install uses about 145 MB
19.498 GB /var (logical) current install uses about 9.3 GB
4 GB /tmp (logical) current install uses about 21 MB
  • Full Name: Dirk Rockface
  • Server: brimble
  • User Name: dirk
  • Finish installing. I didn't install any “common packages” from the setup CD.

Setup

Update Packages

sudo apt-get update
sudo apt-get dist-upgrade

Install SSH Server

sudo apt-get install openssh-server

Mount other hard drives

sudo mkdir /mnt/storage
sudo mkdir /mnt/minecraft
sudo mkdir /mnt/plex
sudo mkdir /mnt/timemachine
sudo blkid

and

sudo lsblk

to get info for fstab.

sudo vim /etc/fstab

Install ex-fat (for USB drives or FAT formats)

sudo apt-get install exfat-fuse exfat-utils

Reboot

sudo reboot -h now

Create ssh-rsa key auth

  • Turn off Password Auth
    sudo vim /etc/ssh/sshd_config
    UsePAM yes
    PasswordAuthentication no

Reboot

sudo reboot -h now

Install Tomcat

sudo apt-get install tomcat9

Change to port 80

sudo vim /etc/tomcat9/server.xml
<Connector port="80" protocol="HTTP/1.1"
       	connectionTimeout="20000"
       	URIEncoding="UTF-8"
       	redirectPort="8443" />

Copy webpage files

sudo rm -rf /var/lib/tomcat9/webapps/ROOT
sudo cp -a /mnt/backup/webpage/webapps/. /var/lib/tomcat9/webapps/
sudo cp -a /mnt/backup/webpage/plex /var/lib/tomcat9/
  • <html><span style=“color:red;font-size:100%;”>Note:</span> You might have to set ownership and permissions back to normal for those folders</html>
    sudo chown tomcat:tomcat webapps
    sudo chmod 755 webapps

Allow Directory Browsing

sudo vim /etc/tomcat9/web.xml
<init-param>
  <param-name>listings</param-name>
  <param-value>true</param-value>
</init-param>

Faster Tomcat Startup

  • <html><span style=“color:red;font-size:100%;”>Note:</span> This is due to using random vs urandom</html>
  • edit java.security

Install MySql

sudo apt-get install mysql-server

Import database dump

sudo mysql -u root -p < dumpfile.sql

Create mysql user

sudo mysql -u root -p
CREATE USER 'dirk'@'localhost' IDENTIFIED BY 'password';
show databases;
GRANT ALL PRIVILEGES ON *.* TO 'dirk'@'localhost';
exit

Allow write access for user

GRANT FILE ON *.* TO 'dirk'@'localhost';
exit

Allow mysql to write to files

sudo aa-status
  • This should show mysqld in enforce mode
sudo vim /etc/apparmor.d/usr.sbin.mysqld
  • add folders near the bottom like this:
    /var/lib/tomcat9/webapps/ r,
    /var/lib/tomcat9/webapps/** rwk,
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
  • add at bottom:
    secure_file_priv=""
  • while in this file, decrease sleep time to avoid max connections (default is 8 hrs)
    wait_timeout = 20
  • <html><span style=“color:red;font-size:100%;”>Note:</span> In order to get sql to write, I had to make everything in the webapps folder root:dirk (which it probably was) and the export folder 777. Not sure which of those did the trick (or both)</html>
  • <html><span style=“color:red;font-size:100%;”>Note:</span> New in mysqlserver v8: files writen from mysql are only readable by root and the mysql group so you have to add the use tomcat (the one reading the files in the march madness bracket) to the mysql group (the one creating the files)</html>
    sudo usermod -a -G mysql tomcat
  • Changes will take effect after restart
    sudo reboot -h now

Tomcat - Mysql linking / JDK / JAVA cleanup

  • Install Java Development Kit
     sudo apt-get install default-jdk
  • Install Java / Mysql connector
     sudo apt-get install libmysql-java
  • <html><span style=“color:red;font-size:100%;”>Note:</span> This was not supported in 20.04 at the time and must be installed manually.</html>
  • Create symlink for connector
    sudo ln -sf /usr/share/java/mysql-connector-java.8.0.20.jar /usr/share/tomcat9/lib/mysql-connector-java.jar
  • New change for 20.04: had to add
    &serverTimezone=UTC

    to the end of the SQL_PARAMS section in all of the config.jsp files. They should be all converted for the next install and no action required. (hopefully)

  • If webinf files need to be compiled:
    sudo javac -cp /usr/share/java/servlet-api-3.0.jar:/usr/share/java/jsp-api-2.2.jar util/*.java
  • reboot
    sudo reboot -h now

Install Samba

sudo apt-get install samba
sudo smbpasswd -a dirk
sudo vim /etc/samba/smb.conf
[webapps]
  comment = Webpage Files
    path = /var/lib/tomcat9/webapps
    available = yes
    browsable = yes
    guest ok = yes
    read only = no
    writable = yes
    admin users = dirk
[storage]
[plex]
  • you may have to chmod correct permissions for webapps folder (775)

Add football season

LOAD DATA LOCAL INFILE "/home/dirk/2019o.csv" INTO TABLE games COLUMNS TERMINATED BY ',';

Allow rsync to run on own

sudo visudo -f /etc/sudoers.d/nopass
dirk ALL=(ALL:ALL) NOPASSWD:/usr/bin/rsync

Add cron job for backup

crontab -e
0 3 * * * /home/dirk/scripts/backup

Change timezone

sudo dpkg-reconfigure tzdata
server/ubuntu20.04.txt · Last modified: by 127.0.0.1