Linux Centos 6 Membangun Web Server
Web Server : Apache Tomcat
Language : JSP (Java Server Pages)
Database : PostgreSQL

Tools : PuTTY & WinSCP.

Cek System Operasi
# hostnamectl
SET TIMEZONE
# timedatectl set-timezone Asia/Jakarta
# timedatectl
Install WGET
# yum install wget
Uninstall Apache
# sudo yum erase httpd-tools apr apr-util
Install JDK
# yum -y install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64
Melihat versi java
# java -version
Konfigurasi Java Home Environment
# sudo update-alternatives --config java
# vim /etc/environment atau # vi /etc/environment
JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64"

Simpan dengan
:wq
Edit bash profile
# vim ~/.bash_profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
export PATH=$JAVA_HOME/bin:$PATH

Save & reload bash profile
# source ~/.bash_profile
Cek JAVA_HOME
# echo $JAVA_HOME
Install Apache Tomcat
# groupadd tomcat
# useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
# cd /opt
# wget http://mirror.wanxp.id/apache/tomcat/tomcat-8/v8.0.43/bin/apache-tomcat-8.0.43.tar.gz
# tar -xzvf apache-tomcat-8.0.43.tar.gz
# chown -hR tomcat:tomcat tomcat
# Edit /opt/tomcat/conf/server.xml
ganti connector port =80

Test Tomcat
# /opt/tomcat/bin/startup.sh
View Process
# ps aux
# yum provides */netstat
# yum install net-tools
# netstat -plntu
Firewall
# iptables -L
# iptables -F
# iptables -L
# service iptables save
Restart Tomcat
# /opt/tomcat/bin/shutdown.sh
# /opt/tomcat/bin/startup.sh
Install PostgreSQL
Install
(sebelumnya download postgresql-9.3.17-1-linux-x64.run dan copy ke /opt)
# chmod +x postgresql-9.3.17-1-linux-x64.run
# ./postgresql-9.3.17-1-linux-x64.run
# systemctl start postgresql-9.3
# su - postgres
Copy JDBC file

Restore Database
# /opt/PostgreSQL/9.3/bin/pg_restore -i -h localhost -p 5432 -U postgres -d xsatriya -v "/opt/xsatriya.backup"
Backup Database
# /opt/PostgreSQL/9.3/bin/pg_dump -i -h localhost -p 5432 -U postgres -F c -b -v -f "/opt/backupdb/xsatriya.backup" xsatriya
Create new file.pgpass.conf in /root/.pgpass for automatic password
# nano /root/.pgpass
# chmod 600 /root/.pgpass
# vi /root/.pgpass
	localhost:5432:*:postgres:password_db
CRONJOB
# sudo yum update
# sudo rpm -q cronie
# sudo yum install cronie
Create Command
# sudo crontab -e
1 6 * * * /opt/xxx.sh    (tiap jam 6 lebih 1 menit)
Press i (for "insert") to begin editing the file.
Pres esc to exit editing mode
Type :wq to save the file.
Automatically backup to Google Drive
# cd /opt
# wget -O gdrive https://drive.google.com/uc?id=0B3X9GlR6EmbnMHBMVWtKaEZXdDg
# mv gdrive /usr/sbin/gdrive
# chmod 755 /usr/sbin/gdrive
# sudo bash /usr/sbin/gdrive

After your first attempt to upload or do anything with gdrive, you will be asked to link your Linux box with your Google Drive account. You will get a message like this:

Go to the following link in your browser..
https://accounts.google.com/o/oauth2/approval/v2/approvalnativeapp?auto=false&response=state%3Dstate%26code%3D4%2FgwAsj1pRbw3BMUeXbHFr8YrA7Rt5HhkJndBHNmWW9Dq8cXQbOEvFmGc%26scope%3Dhttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&hl=id&approvalCode=4%2FgwAsj1pRbw3BMUeXbHFr8YrA7Rt5HhkJndBHNmWW9Dq8cXQbOEvFmGc

Enter verification code: 4/9*****
Create Command
# /usr/sbin/gdrive upload -f "/opt/XXX/XXX.backup" -p "1RLXXXXXX" (nama folder di google drive)
atau
# /root/gdrive/gdrive upload -p 1RLXXXXXX "/opt/XXX/XXX.backup"
Server Maintenance
Cek Penggunaan Memory
# free -m
Restart PostgreSQL
# /etc/rc.d/init.d/postgresql-9.3 restart
Restart Server
# /sbin/shutdown -r now
# /opt/tomcat/bin/startup.sh
# iptables -L
# iptables -F
# iptables -L
# service iptables save
Memory TuneUp Java
Cek Max Memory
java -XX:+PrintFlagsFinal -version | grep HeapSize
Setting Max Memory to 2048m (2048000000)
export _JAVA_OPTIONS="-Xms64m -Xmx2048m"
Memory TuneUp Apache Tomcat
add this script to Catalina.sh
if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
  . "$CATALINA_BASE/bin/setenv.sh"
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
  . "$CATALINA_HOME/bin/setenv.sh"
fi
Create a setenv.sh manually, and put it into the tomcat-folder\bin\ folder.
export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=2048m"
Restart Tomcat
  • https://www.howtoforge.com/tutorial/how-to-install-tomcat-on-centos/
  • http://jurnalinux.blogspot.co.id/2016/04/install-database-postgresql-95-di.html
  • https://www.linode.com/docs/databases/postgresql/securely-manage-remote-postgresql-servers-with-pgadmin-on-windows
  • https://www.pradha.id/read/setting-postgresql-agar-dapat-diakses-dari-luar
  • https://linuxandryan.wordpress.com/2013/03/07/creating-and-using-a-pgpass-file/
  • https://serverfault.com/questions/579233/permission-denied-on-owned-file
  • https://www.rosehosting.com/blog/automate-system-tasks-using-cron-on-centos-7/
  • http://www.pixelstech.net/article/1339424625-Create-cron-job-on-CentOS
  • https://albennet.com/automaticallybackupdatatogoogledrive.php
  • https://www.mynotepaper.com/mount-google-drive-using-gdrive-on-linux-server-with-own-oauth-credentials
  • https://timothy-quinn.com/backing-up-a-directory-to-google-drive-on-centos-7/
  • https://dzhorov.com/2017/04/creating-backups-from-linux-to-google-drive
  • https://www.cyberciti.biz/faq/centos-memory-info-usage-command/
  • https://mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/
  • https://stackoverflow.com/questions/12797560/how-can-i-find-java-heap-size-and-memory-used-linux