Tomcat7 install

apt-get install tomcat7

apt-get install tomcat7 tomcat7-docs tomcat7-examples tomcat7-admin tomcat7-user

Created for you:
Creating config file /etc/default/tomcat7 with new version
Adding system user `tomcat7' (UID 107) …
Adding new user `tomcat7' (UID 107) with group `tomcat7' …

apt-get install tomcat7-docs tomcat7-examples tomcat7-admin tomcat7-user

# find / -name "tomcat-users.xml"
There will be 2 tomcat-users.xml
• /etc/tomcat7/tomcat-users.xml is for the site created on port 8080
• /usr/share/tomcat7/skel/conf/tomcat-users.xml is the default used for create instance.

vi /etc/tomcat7/tomcat-users.xml
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="user" password="password" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

Restart tomcat:
/etc/init.d/tomcat7 restart

CD to the directory where you want to put the new instance.
mkdir /etc/tomcat7inst
cd /etc/tomcat7inst

tomcat7-instance-create -p 8100 -c 8105 810
You are about to create a Tomcat instance in directory '810'
* New Tomcat instance created in 810
* You might want to edit default configuration in 810/conf
* Run 810/bin/startup.sh to start your Tomcat instance

Modify/verify

/etc/tomcat7inst/810/conf/server.xml
<Server port="8105" shutdown="SHUTDOWN">
<Connector port="8100" protocol="HTTP/1.1"
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />

Modify/verify

/etc/tomcat7inst/810/conf/ tomcat-users.xml (same as above).

To get ROOT app
cp -r /var/lib/tomcat7/webapps/ROOT/ /etc/tomcat7inst/810/webapps/
Restart tomcat:

./810/bin/shutdown.sh
./810/bin/startup.sh
/etc/init.d/tomcat7 restart

To get manager sites to work
cp /etc/tomcat7/Catalina/localhost/* /etc/tomcat7inst/810/conf/Catalina/localhost/
Restart tomcat:

./810/bin/shutdown.sh
./810/bin/startup.sh
/etc/init.d/tomcat7 restart


When doing a deploy, be sure to cleanup…
rm -rf /etc/tomcat7inst/810/work/Catalina/
rm –rf /etc/tomcat7inst/810/temp/

apache2: Could not reliably determine the server’s fully qualified domain

Issue:

# /etc/init.d/apache2 restart
* Restarting web server apache2

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
… waiting ..apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

To fix that problem, you need to edit the httpd.conf file.

  • vi /etc/apache2/httpd.conf

Set content to:

ServerName localhost

  • /etc/init.d/apache2 restart

NFS issues

2013/02/14 19:52:14 [1102] rsync: chown "/mnt/nfs/fs-01.sdb1/backup/database-01/etc/wpa_supplicant/action_wpa.sh" failed: Invalid argument (22)

I have found 2 causes for this:

1)

First check your hostfile.
So my hostfile looked like:

/etc/hosts:
127.0.0.1 localhost.localdomain localhost <real hostname>
::1 localhost.localdomainlocalhost.localdomain localhost6 localhost6.localdomain6 localhost <real hostname>

and the nfs mount mounted as nobody:nobody

but to make it work, your hostfile should look like this:

127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomainlocalhost.localdomain
192.168.x.x <realhost.name.cxm> realhost

this because rpcidmapd is looking at a domain:

rpc.idmapd[23262]: nss_getpwnam: name '<username>@name.cxm' does not map into domain 'localdomain'

once you have your <realhost.name.cxm> assigned to your external ip on your nic (eth0) in the /etc/hostfile, and rpcidmapd reloaded or restarted, things should be running fine….

2)

If the user or group ID is different between the boxes

Box #1

# cat /etc/group | grep apache
apache:x:1001:
# cat /etc/group | grep box
vboxusers:x:1002:

# cat /etc/group | grep apache
apache:x:1001:
# cat /etc/group | grep box
vboxusers:x:1002:

# cat /etc/passwd | grep apache
apache:x:1001:1001::/home/apache:/bin/sh

# cat /etc/passwd | grep box
virtuser:x:1002:1002::/mnt/local/sda1/virtualbox:/bin/sh

Box #2

# cat /etc/group | grep apache
apache:x:1002:
# cat /etc/group | grep box
vboxusers:x:1001:

# cat /etc/passwd | grep apache
apache:x:1002:1002::/home/apache:/bin/sh
# cat /etc/passwd | grep box
virtuser:x:1001:1001::/mnt/local/sda1/virtualbox:/bin/sh

VBoxHeadless – Running Virtual Machines With VirtualBox 4.1 On A Headless Ubuntu 12.04 Server

Reference from here.

VBoxHeadless – Running Virtual Machines With VirtualBox 4.1 On A Headless Ubuntu 12.04 Server

This guide explains how you can run virtual machines with VirtualBox 4.1 on a headless Ubuntu 12.04 server. Normally you use the VirtualBox GUI to manage your virtual machines, but a server does not have a desktop environment. Fortunately, VirtualBox comes with a tool called VBoxHeadless that allows you to connect to the virtual machines over a remote desktop connection, so there's no need for the VirtualBox GUI.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

I have tested this on an Ubuntu 12.04 server (host system) with the IP address 192.168.0.100 where I'm logged in as a normal user (user name virtuser in this example) instead of as root.

2 Installing VirtualBox

To install VirtualBox 4.1 on our Ubuntu 12.04 server, we open /etc/apt/sources.list

sudo vi /etc/apt/sources.list

… and add the following line to it:

																																																									[...]
			deb http://download.virtualbox.org/virtualbox/debian precise contrib
			

Then we download the VirtualBox public key…

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add –

… and update our package database:

sudo apt-get update

Afterwards, we install VirtualBox 4.2 as follows:

sudo apt-get install linux-headers-$(uname -r) build-essential virtualbox-4.2 dkms

(The dkms package ensures that the VirtualBox host kernel modules are properly updated if the Linux kernel version changes.)

Starting with version 4.0, VirtualBox has introduced so called "extension packs" and has outsourced some functionality like remote desktop connection support (VRDP) that was part of VirtualBox packages before version 4.0 into these extension packs. Because we need remote desktop connections to control our virtual machines, we need to install the appropriate extension pack now. Go to http://www.virtualbox.org/wiki/Downloads, and you will find a link to the following extension pack:

VirtualBox 4.2.6 Oracle VM VirtualBox Extension Pack
Support for USB 2.0 devices, VirtualBox RDP and PXE boot for Intel cards.

Download and install the extension pack as follows:

cd /tmp
wget http://download.virtualbox.org/virtualbox/4.2.6/Oracle_VM_VirtualBox_Extension_Pack-4.2.6-82870.vbox-extpack

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.6-82870.vbox-extpack

(Make sure you grab the latest version from the VirtualBox web site.)

(Make sure you run the last command with sudo – sudo VBoxManage extpack install … – because otherwise you will get an error like this:

administrator@server1:/tmp$ VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.6-82870.vbox-extpack
0%…
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to install "/tmp/Oracle_VM_VirtualBox_Extension_Pack-4.2.6-82870.vbox-extpac": The installer failed with exit code 127: Error creating textual authentication agent: Error opening current controlling terminal for the process (`/dev/tty'): No such device or address
administrator@server1:/tmp$

)

Now we must add the user that will run VirtualBox (virtuser in this example) to the vboxusers group:

groupadd vboxusers
mkdir -p /mnt/local/sda1/virtualbox
useradd -m -d /mnt/local/sda1/virtualbox virtuser -g vboxusers
passwd virtuser
chown virtuser:vboxusers /mnt/local/sda1/virtualbox

VirtualBox is now installed and ready to be used.

Do we need Guest Additions (Did not need this the first time on fileshares 001 and 999.

sudo apt-get install virtualbox-guest-additions

===================================================================
We won't be doing manual, go to phpvirtualbox (Web Admin)
===================================================================

3 Using VirtualBox On The Command Line

3.1 Creating A VM

To create a VM on the command line, we can use the VBoxManage command. See

VBoxManage –help

for a list of available switches and (highly recommended!) take a look at http://www.virtualbox.org/manual/ch08.html.

I will now create an Ubuntu 12.04 Server VM with 512MB memory and a 10GB hard drive from the Ubuntu 12.04 Server iso image (which I have stored in /home/ubuntu-12.04-server-amd64.iso):

VBoxManage createvm –name "Ubuntu 12.04 Server" –register
VBoxManage modifyvm "Ubuntu 12.04 Server" –memory 512 –acpi on –boot1 dvd –nic1 bridged –bridgeadapter1 eth0
VBoxManage createhd –filename Ubuntu_12_04_Server.vdi –size 10000
VBoxManage storagectl "Ubuntu 12.04 Server" –name "IDE Controller" –add ide
VBoxManage storageattach "Ubuntu 12.04 Server" –storagectl "IDE Controller" –port 0 –device 0 –type hdd –medium Ubuntu_12_04_Server.vdi
VBoxManage storageattach "Ubuntu 12.04 Server" –storagectl "IDE Controller" –port 1 –device 0 –type dvddrive –medium /home/ubuntu-12.04-server-amd64.iso

3.2 Importing An Existing VM

Let's assume you have a VM called examplevm that you want to reuse on this host. On the old host, you should have a directory Machines/examplevm in the VirtualBox directory; Machines/examplevm should contain the examplevm.xml file. Copy the examplevm directory (including the examplevm.xml file) to your new Machines directory (if your user name is administrator, this is /home/administrator/.VirtualBox/Machines – the result should be /home/administrator/.VirtualBox/Machines/examplevm/examplevm.xml).

In addition to that copy the examplevm.vdi file from the old VDI directory to the new one (e.g. /home/administrator/.VirtualBox/VDI/examplevm.vdi).

Afterwards, you must register the imported VM:

VBoxManage registervm Machines/examplevm/examplevm.xml

3.3 Starting A VM With VBoxHeadless

Regardless of if you create a new VM or import an old one, you can start it with the command:

VBoxHeadless –startvm "Ubuntu 12.04 Server"

(Replace Ubuntu 12.04 Server with the name of your VM.)

VBoxHeadless will start the VM and a VRDP (VirtualBox Remote Desktop Protocol) server which allows you to see the VM's output remotely on another machine.

To stop a VM, run

VBoxManage controlvm "Ubuntu 12.04 Server" poweroff

To pause a VM, run

VBoxManage controlvm "Ubuntu 12.04 Server" pause

To reset a VM, run

VBoxManage controlvm "Ubuntu 12.04 Server" reset

To learn more about VBoxHeadless, take a look at

VBoxHeadless –help

and at http://www.virtualbox.org/manual/ch07.html#vboxheadless.

Managing A Headless VirtualBox Installation With phpvirtualbox (Ubuntu 12.04)

Reverence from here.

Managing A Headless VirtualBox Installation With phpvirtualbox (Ubuntu 12.04)

phpvirtualbox is a web-based VirtualBox front-end written in PHP that allows you to access and control remote VirtualBox instances. It tries to resemble the VirtualBox GUI as much as possible to make work with it as easy as possible. It is a nice replacement for the VirtualBox GUI if you run VirtualBox in headless servers (like in the tutorial VBoxHeadless – Running Virtual Machines With VirtualBox 4.1 On A Headless Ubuntu 12.04 Server). This tutorial explains how to install phpvirtualbox on an Ubuntu 12.04 server to manage a locally installed, headless VirtualBox.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

I'm assuming that a headless VirtualBox is already installed on the local Ubuntu 12.04 server, e.g. as described in the tutorial VBoxHeadless – Running Virtual Machines With VirtualBox 4.1 On A Headless Ubuntu 12.04 Server.

I'm running all the steps in this tutorial with root privileges, so make sure you're logged in as root:

sudo su

2 Installing phpvirtualbox

Created on install side.

groupadd vboxusers
useradd -m -d /mnt/local/sda1/virtualbox virtuser -g vboxusers

First create a system user called virtuser and add it to the vboxusers group:

useradd -m virtuser -G vboxusers

Create a password for the virtuser user:

passwd virtuser

Create the file /etc/default/virtualbox and put the line VBOXWEB_USER=virtuser in it (so that the VirtualBox SOAP API which is called vboxwebsrv runs as the user virtuser ):

vi /etc/default/virtualbox

			VBOXWEB_USER=virtuser
			

Next create the system startup links for vboxwebsrv and start it:

update-rc.d vboxweb-service defaults
/etc/init.d/vboxweb-service start

We need a web server with PHP support to serve phpvirtualbox – I'm using Apache2 here. Install Apache2 and PHP5 as follows:

apt-get install apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common apache2 apache2-doc apache2-suexec libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libapr1 php5-common php5-mysql php5-suhosin php-pear wget

Restart Apache2:

/etc/init.d/apache2 restart

I want to serve phpvirtualbox from Apache's default virtual host with the document root /var/www (I will install it in /var/www/phpvirtualbox) – if you have a different document root, you must adjust the following steps:

cd /var/www
wget http://phpvirtualbox.googlecode.com/files/phpvirtualbox-4.2-4.zip

Unzip phpvirtualbox and rename the phpvirtualbox-4.1-7 to phpvirtualbox for ease of use:

unzip phpvirtualbox-4.2-4.zip
mv phpvirtualbox-4.2-4 /var/www/phpvirtualbox/

Next go to the /var/www/phpvirtualbox/ directory…

cd /var/www/phpvirtualbox/

… and create the file config.php by copying it from config.php-example:

cp config.php-example config.php

Open config.php and fill in the password you created earlier for the virtuser system user:

vi config.php

																														[...]
			/* Username / Password for system user that runs VirtualBox */
			var $username = 'virtuser';
			var $password = 'secret';
			[...]
			

That's it already – you can now open a browser and access phpvirtualbox as follows:

http://www.example.com/phpvirtualbox/

http://fileshare-01/phpvirtualbox/

http://fileshare-99/phpvirtualbox/

IF COPING/IMPORTING, NETWORK will not work. 2 options

1. make the MAC address exactly the same as original.

2. Comment out all lines:

vi /etc/udev/rules.d/70-persistent-net.rules

The default username is admin, the password is admin as well:

This is how phpvirtualbox looks – much like the native VirtualBox GUI:

The first thing you should do is change the admin password. Go to File > Change Password:

Type in the old password and specify a new one:

If you know the native VirtualBox GUI, it's now very easy to use phpvirtualbox. For example, if you want to create a new virtual machine, you have the same wizard as you have in the VirtualBox GUI:

(I'm leaving a few sceenshots out so you don't feel bored…)

In the end you have a new VM. Click on the Start button to run that VM:

Even though phpvirtualbox is a web front-end, you still get the VM console that you know from the VirtualBox GUI – pretty cool:

3 Links

Setting Up the NFS Server

About NFS (Network File System) Mounts


NFS mounts work to share a directory between several virtual servers. This has the advantage of saving disk space, as the home directory is only kept on one virtual private server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.

Setup


An NFS mount is set up between at least two virtual servers. The machine hosting the shared network is called the server, while the ones that connect to it are called ‘clients’.

This tutorial requires 2 servers: one acting as the server and one as the client. We will set up the server machine first, followed by the client. The following IP addresses will refer to each one:

Master: fileshare-01
Client: database-01

There are 3 ways to do this.

OPTION 1 (Public share, everything is owned by
OPTION 2 (User share, user has access to only there data)
OPTION 3 ()

The system should be set up as root. You can access the root user by typing
sudo su



Setting Up the NFS Server


Step One—Download the Required Software

Start off by using apt-get to install the nfs programs.
apt-get install nfs-kernel-server portmap


Step Two—Export the Shared Directory

The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.

Suppose we wanted to share two directories: /home and /var/nfs.

Because the /mnt/local/ does not exist, we need to do two things before we can export it.

First, we need to create the directory itself:
mkdir /mnt/local/

We will have 2 physical disks loaded at this location /sda1 and /sdb1
sudo chmod 755 sda1 sdb1
Second, we should change the ownership of the directory to the user, nobody and the group, no group. These represent the default user through which clients can access a directory shared through NFS.

Go ahead and chown the directory:
chown root:root /mnt/local

Option 1:
chown nobody:nogroup /mnt/local/sda1
chown nobody:nogroup /mnt/local/sdb1
Option 2:
chown uid:gui /mnt/local/sda1
chown uid:gui /mnt/local/sdb1

After completing those steps, it’s time to export the directories to the other VPS.
vi /etc/exports

Add the following lines to the bottom of the file, sharing both directories with the client:

Share with clients on subnet:  ->  192.168.1.0/24   (This is the one we will use) 
Share with specific server:      -> database-01 	

Option 1:

/mnt/local/sda1 192.168.1.0/24(rw,nohide,no_subtree_check,async,all_squash)
/mnt/local/sdb1 192.168.1.0/24(rw,nohide,no_subtree_check,async,all_squash)

Option 2:  Below is what QBW has

/mnt/local/sda1 192.168.1.0/24(rw,sync,no_root_squash,nohide,no_subtree_check)
/mnt/local/sdb1 192.168.1.0/24(rw,sync,no_root_squash,nohide,no_subtree_check)

/mnt/local/sdb1/test 192.168.1.0/24(rw,sync,root_squash,nohide,no_subtree_check)



These settings accomplish several tasks:

  • rw: This option allows the client server to both read and write within the shared directory

  • sync: Sync confirms requests to the shared directory only once the changes have been committed.

  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.

  • no_root_squash: This phrase allows root to connect to the designated directory

Once you have entered in the settings for each directory, run the following command to export them:
 /etc/init.d/nfs-kernel-server restart


to see your exports
exportfs -v

Now for the CLIENT.

Setting Up the NFS Client



Step One—Download the Required Software

Start off by using apt-get to install the nfs programs.
apt-get install nfs-common portmap


Step Two—Mount the Directories

Once the programs have been downloaded to the the client server, create the directories that will contain the NFS shared files
mkdir -p /mnt/nfs/fs-01.sda1

mkdir -p /mnt/nfs/fs-01.sdb1

prevent accedent writes:

sudo chmod 000 /mnt/nfs/fs-01.sda1

sudo chmod 000 /mnt/nfs/fs-01.sdb1

sudo mount fileshare-01:/mnt/local/sda1/ /mnt/nfs/fs-01.sda1/

You can use the df -h command to check that the directories have been mounted. You will see them last on the list.

df -h
Filesystem             Size  Used Avail Use% Mounted on/dev/sda                20G  948M   19G   5% /udev                   119M  4.0K  119M   1% /devtmpfs                   49M  208K   49M   1% /runnone                   5.0M     0  5.0M   0% /run/locknone                   122M     0  122M   0% /run/shmfileshare-01:/home      20G  948M   19G   5% /mnt/nfs/homefileshare-01:/var/nfs   20G  948M   19G   5% /mnt/nfs/var/nfs

Additionally, use the mount command to see the entire list of mounted file systems.
mount

Your list should look something like this:
/dev/sda on / type ext4 (rw,errors=remount-ro,barrier=0) [DOROOT]proc on /proc type proc (rw,noexec,nosuid,nodev)sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)none on /sys/fs/fuse/connections type fusectl (rw)none on /sys/kernel/debug type debugfs (rw)none on /sys/kernel/security type securityfs (rw)udev on /dev type devtmpfs (rw,mode=0755)devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)none on /run/shm type tmpfs (rw,nosuid,nodev)rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)fileshare-01:/home on /mnt/nfs/home type nfs (rw,vers=4,addr= fileshare-01,clientaddr=192.168.1.xxx)fileshare-01:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,vers=4,addr=12.34.56.78,clientaddr=192.168.1.xxx)


Testing the NFS Mount

Once you have successfully mounted your NFS directories, you can test that they work by creating files on the Client and checking their availability on the Server.

Create a file in each directory to try it out:
touch /mnt/nfs/fs-01.sda1/test.txt
touch /mnt/nfs/fs-01.sdb1/test.txt

You should then be able to find the files on the Server in the /home and /var/nfs directories.
ls /home

ls /mnt/nfs/


You can ensure that the mount is always active by adding the directories to the fstab file on the client. This will ensure that the mounts start up after the server reboots.
vi /etc/fstab

fileshare-01:/mnt/local/sda1/ /mnt/nfs/fs-01.sda1/ nfs4 _netdev,auto,retry=1,nolock,bg,intr 0 0
fileshare-01:/mnt/local/sdb1/ /mnt/nfs/fs-01.sdb1/ nfs4 _netdev,auto,retry=1,nolock,bg,intr 0 0
You can learn more about the fstab options by typing in:
man nfs

Any subsequent restarts will include the NFS mount—although the mount may take a minute to load after the reboot You can check the mounted directories with the two earlier commands:
df -h

mount


Removing the NFS Mount

Should you decide to remove a directory, you can unmount it using the umount command:

sudo umount /directory name


You can see that the mounts were removed by then looking at the filesystem again.
df -h


You should find your selected mounted directory gone.

Log user activity

  • ~/.bash_history will show the commands that was used by a user.
  • Install acct : sudo apt-get install acct in addition to login/logout. It provides logs of every single command run by every single user. Below mentioned commands are the features of acct

    • ac print statistics about connect time
    • accton turns accounting on or off
    • last list last logins of users and terms
    • lastcomm list last commands executed
    • sa print accounting statistics
    • dump-acct print accounting file in human-readable form

    ==========================================

    https://launchpad.net/ubuntu/precise/+source/activity-log-manager/0.9.4-0ubuntu3.2

    ==========================================

    ==========================================

    Rename Ubuntu Server

    So, you just screwed up the name of your Ubuntu server?

    Well that can be changed in no time and with no downtime

    Just follow the below steps;

    • Set a new hostname
    sudo hostname new.host.name
    • Edit the /etc/hosts file

    sudo vi /etc/hosts

    • Edit the /etc/hostname file

    sudo vi /etc/hostname

    In some circumstances you may also have to change the /etc/resolv.conf file.

    • prove that it works

    sudo reboot

    Simple, yes! But worth 90 seconds to write out ;P


    Tag Cloud