Monday, May 11, 2020

Automate Installation - Ubuntu with JDK and Tomcat

Update OS and Install required packages


apt-get update -y;
apt-get install gdebi -y;
apt-get install vim -y;
apt-get install nano -y;
apt-get install htop -y;
apt-get install unzip -y;
apt-get install python -y;

Install JDK

apt-get install default-jdk -y;
add-apt-repository ppa:webupd8team/java -y;
apt-get update -y;

Install Mysql | Kindly update password


sudo debconf-set-selections <<< 'mysql-server-5.7 mysql-server/root_password password password' 
sudo debconf-set-selections <<< 'mysql-server-5.7 mysql-server/root_password_again password password' 
apt-get -y install mysql-server-core-5.7 mysql-server-5.7 mysql-client-5.7;
service mysql start;

Install AWS CLI on Linux


curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Tomcat Installation

#Update the Version which is required by your application


groupadd tomcat
useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
cd /tmp/
curl -O http://redrockdigimark.com/apachemirror/tomcat/tomcat-8/v8.5.30/bin/apache-tomcat-8.5.30.tar.gz 
mkdir /opt/tomcat
tar xzvf apache-tomcat-8.5.30.tar.gz -C /opt/tomcat --strip-components=1
cd /opt/tomcat 
chgrp -R tomcat /opt/tomcat
chmod -R g+r conf
chmod g+x conf
chown -R tomcat webapps/ work/ temp/ logs/
update-java-alternatives -l

Create Service for Tomcat


touch /etc/systemd/system/tomcat.service
cd /etc/systemd/system/

Service File Update (File - /etc/systemd/system/tomcat.service)


cat <> tomcat.service;
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
EOF

Start Service


systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcat

Add User for Tomcat Manager (Change your Username and Password as per your needs)


sed -i '22i\' /opt/tomcat/conf/tomcat-users.xml

Allow IP Address for Accessing Tomcat Manager App


cp /opt/tomcat/webapps/manager/META-INF/context.xml /opt/tomcat/webapps/manager/META-INF/context.orignal.xml
cp /opt/tomcat/webapps/host-manager/META-INF/context.xml /opt/tomcat/webapps/host-manager/META-INF/context.original.xml

Delete line number 19 to 21 (File - /opt/tomcat/webapps/manager/META-INF/context.xml)


sed -i '18,20d' /opt/tomcat/webapps/manager/META-INF/context.xml

Add below lines in between i.e 19,20 and 21 number. (File - /opt/tomcat/webapps/manager/META-INF/context.xml)


sed -i '18i\' /opt/tomcat/webapps/manager/META-INF/context.xml
sed -i '19i\'  /opt/tomcat/webapps/manager/META-INF/context.xml #kindly update IP Address

Delete line number 19 to 21 (File - /opt/tomcat/webapps/host-manager/META-INF/context.xml)


sed -i '18,20d' /opt/tomcat/webapps/host-manager/META-INF/context.xml

Add below lines in between i.e 18,19 and 20 number. (File - /opt/tomcat/webapps/host-manager/META-INF/context.xml)


sed -i '18i\' /opt/tomcat/webapps/host-manager/META-INF/context.xml
sed -i '19i\'  /opt/tomcat/webapps/host-manager/META-INF/context.xml #kindly update IP Address

Remove version string from HTTP error messages


cd /opt/tomcat/lib
jar xf catalina.jar /opt/tomcat/lib/org/apache/catalina/util/ServerInfo.properties
sed -i '16,17d' /opt/tomcat/lib/org/apache/catalina/util/ServerInfo.properties
sed -i '16i\server.info=Apache Tomcat' /opt/tomcat/lib/org/apache/catalina/util/ServerInfo.properties
jar uf catalina.jar org/apache/catalina/util/ServerInfo.properties
rm -rf /opt/tomcat/lib/org

Move unwanted Folders from WebApps Folder to Tmp


mv /opt/tomcat/webapps/examples /tmp
mv /opt/tomcat/webapps/docs /tmp
For More videos go to - https://www.youtube.com/channel/UCIUmpO3KBHPMtgzMA6p0IhA

0 comments:

Post a Comment