题记:写这篇博客要主是加深自己对javaapplication的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢。

Now there are many hosting server for people to choose to host their own apps or website. And sometimes normal web hosting can not exactly fulfil your requirements. So VPS is a good option, with VPS you can setup anything you want just like you are working in your own server.

Next I will share my experience of my java based apps/website setup, it will contains below several sections:

1. Find a good VPS;

2. Setup JDK;

3. Setup Tomcat;

4. Setup Database;

5. Setup your application;

6. Setup cron jobs;

1. Find a good VPS

Obviously, you need to choose one VPS with a reasonable price and can provide good service e.g. bandwidth this is very important for your apps/website. What you can do is find the information from internet see the feedback of those existing user. The time i chooses Atlantic.Net, as they offer $10 for the new new user, with this $10 you can almost run your apps as a trial for 2 months, and during the 2 months definitely you can see how is the service provider.

2. My website is java based, so first thing first, setup JDK

Ubuntu install and configure JDK

Ubuntu 12.04
steps:
a. download and install jdk
$sudo apt-get install openjdk-6-jdk
b. check the system JVM
$sudo update-alternatives --display java
c. install JVM
$sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-1.6.0-openjdk-i386/bin/java 60
d. update system JVM
$sudo update-alternatives –config java
e. configure environment variables
$vim /etc/profile
add below lines in the end:    
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-i386
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
export PATH
export CLASSPATH
save and reboot ubuntu
f. validate the installation
$echo $JAVA_HOME
$java -version

Note: Vi command

You need to use this for editing the configuration file

Comand mode:control the cursor move
Insert mode:only in this Insert mode you can do the editing, press Esc can go back to Comand mode
Last line mode:will save the file and leave the editing

i - insert
a - add, input from the next words
o - insert a new line and start to input

:w filename (save the file with this filename)
:wq (save and exit)
:q! (discard changes and exit)

3. Setup Tomcat

a. download apache-tomcat6,
http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.28/bin/
选择Ubuntu Linux实用版本,即apache-tomcat-6.0.28.tar.gz文件,

b. 复制安装文件到/usr/local/目录下面,在控制台console输入命令, 
sudo tar -zxvf apache-tomcat-6.0.28.tar.gz,
将安装包解压至apache-tomcat-6.0.28目录下,

配置tomcat的启动环境,在/etc/environment目录下添加
CATALINA_HOME="/usr/local/apache-tomcat-6.0.28"

c. console输入命令:sudo gedit /usr/local/apache-tomcat-6.0.28/bin/startup.sh, 
配置startup.sh文件,添加入以下配置项,
JAVA_HOME=/usr/lib/sunJVM/JDK/jdk1.6.0_20
JRE_HOME=/usr/lib/java/jdk1.6.0_20/jre  
PATH=$JAVA_HOME/bin:$JRE_HOME:$PATH  
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
TOMCAT_HOME=/usr/local/apache-tomcat-6.0.28

其中的JAVA_HOME等如同上文Sun JDK安装一文所示。 
保存退出。

d. 进入/usr/local/apache-tomcat-6.0.28/bin/目录, 
输入命令:
cd /usr/local/apache-tomcat-6.0.28/bin,
sudo ./startup.sh

启动tomcat服务器, 
若涌现:
Using CATALINA_BASE:   /usr/local/apache-tomcat-6.0.28
Using CATALINA_HOME:   /usr/local/apache-tomcat-6.0.28
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.28/temp
Using JRE_HOME:        /usr/lib/sunJVM/JDK/jdk1.6.0_20
Using CLASSPATH:       /usr/local/apache-tomcat-6.0.28/bin/bootstrap.jar
代码,则基本上畸形启动了,输入http://localhost:8080/查看,看看是否涌现熟悉的tomcat欢送界面。

可以用系统自带的文字浏览器w3m,
w3m的一般应用方法就是:$w3m http://localhost:8080/
C-c 停止 
C-z 挂起(退出) 
q 退出(需确认) 
Q 退出而不确认

    每日一道理
自己把自己说服了,是一种理智的胜利;自己被自己感动了,是一种心灵的升华;自己把自己征服了,是一种人生的成功。

4. Setup database - Mysql


#apt-get install mysql-server

issue you may encounter - mysql“Access denied for user 'root'@'localhost'”

直接应用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码:
# mysql -udebian-sys-maint -p
Enter password: <输入[client]节的密码>
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

# mysql -uroot -p
Enter password: <输入新设的密码newpassword>

mysql> source \usr\local\test.sql;

5. setup application

put your war file to tomcat webapps directory and run tomcat

Note: jar -cvf test.war *

Issue you may encounter - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'xyz' doesn't exist

this normally because the name is case sensitive on linux


6. Setup cron job

This will be used when there is a requirement that you need to run some cron job, e.g. update something daily to your database or sent out your application daily report

Installing Crontab From a Cron File

Instead of directly editing the crontab file, you can also add all the entries to a cron-file first. Once you have all thoese entries in the file, you can upload or install them to the cron as shown below.

ramesh@dev-db$ crontab -l
no crontab for ramesh

$ cat cron-file.txt
@yearly /home/ramesh/annual-maintenance
*/10 * * * * /home/ramesh/check-disk-space

ramesh@dev-db$ crontab cron-file.txt

ramesh@dev-db$ crontab -l
@yearly /home/ramesh/annual-maintenance
*/10 * * * * /home/ramesh/check-disk-space
Note: This will install the cron-file.txt to your crontab, which will also remove your old cron entries. So, please be careful while uploading cron entries from a cron-file.txt.

/usr/lib/jvm/java-6-openjdk/bin/javac tes.java

0 */2 * * * script.sh
#! /bin/sh
java -jar <your jar file>

@daily java -jar /usr/local/custom/cron/application.jar > /usr/local/log.log 2>&1 
@daily java -jar /usr/local/custom/cron/application.jar | mail -s "cron output" youemail@gmail.com

Note: You can use the IDE tools (e.g. IntelliJ IDEA, eclipse) to package the jar file.

and this executable .jar file must contains a MANIFEST.MF file to indicate the related classpath

文章结束给大家分享下程序员的一些笑话语录:

程序员打油诗   
  写字楼里写字间,写字间里程序员;
  程序人员写程序,又拿程序换酒钱。
  酒醒只在网上坐,酒醉还来网下眠;
  酒醉酒醒日复日,网上网下年复年。
  但愿老死电脑间,不愿鞠躬老板前;
  奔驰宝马贵者趣,公交自行程序员。
  别人笑我忒疯癫,我笑自己命太贱;
  不见满街漂亮妹,哪个归得程序员。

---------------------------------
原创文章 By
java和application
---------------------------------

javaapplicationWeb application setup on Ubuntu VPS的更多相关文章

  1. ubuntu vps折腾记

    买了burgetVM的vps,512M内存/1024M交换内存,40G硬盘,2TB流量/月,cpu xeon E5-2620 操作系统选择了ubuntu 12,开始折腾. 第一步,配置vpn 找了很多 ...

  2. How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS

    Introduction The Apache web server can be configured to give the server administrator important info ...

  3. ubuntu vps 安装 jdk

    Introduction Java is a programming technology originally developed by Sun Microsystems and later acq ...

  4. ubuntu vps 安装java

    Introduction Java is a programming technology originally developed by Sun Microsystems and later acq ...

  5. 【转】How to build and install PHP 5.6.9 from source on Ubuntu 14.04 VPS

    原文 https://vpsineu.com/blog/how-to-build-and-install-php-5-6-9-from-source-on-ubuntu-14-04-vps/ In t ...

  6. How To Install Tinc and Set Up a Basic VPN on Ubuntu 14.04

    Introduction In this tutorial, we will go over how to use Tinc, an open source Virtual Private Netwo ...

  7. How To Install Nginx on Ubuntu 16.04 zz

    Introduction Nginx is one of the most popular web servers in the world and is responsible for hostin ...

  8. How To Secure Nginx with Let's Encrypt on Ubuntu 14.04

    https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14 ...

  9. How To Configure a Redis Cluster on Ubuntu 14.04

    原文:https://www.digitalocean.com/community/tutorials/how-to-configure-a-redis-cluster-on-ubuntu-14-04 ...

随机推荐

  1. 第3章3节《MonkeyRunner源码剖析》脚本编写示例: MonkeyImage API使用示例(原创)

    天地会珠海分舵注:本来这一系列是准备出一本书的,详情请见早前博文“寻求合作伙伴编写<深入理解 MonkeyRunner>书籍“.但因为诸多原因,没有如愿.所以这里把草稿分享出来,所以错误在 ...

  2. 国内首篇介绍JanOS物联网操作系统的文章 - 如何把你的手机主板打造成物联网平台

    天地会珠海分舵注:如无意外,您现在正在看的将是国内首篇且是唯一一篇介绍炙手可热的物联网的操作系统JanOS的文章!不信你去百度!希望大家能喜欢.但本文只是引言,更多信息请还是访问JanOS的官网:ht ...

  3. erlang mnesia数据库简单应用

    mnesia是erlang自带的分布式数据库,基于ets和dets实现的.mnesia兼顾了dets的持久性和ets的高性能,可以自动在多个erlang节点间同步数据库.最关键的是,mnesia实现了 ...

  4. HBuilder js 自定义代码块

    =begin 本文档是HBuilder预置的js代码块的文件.注意不要把其他语言的设置放到js里来. 如果用户修改此文档,HBuilder升级后会覆盖用户的修改,建议进入菜单 工具→扩展代码块 扩展相 ...

  5. linuxsocket通信recv研究缓存机制

        曾有过这样一个小疑问.当一个进程注册的插座后,,假设插座没有被调用recv函数接受包.能接受到数据包吗? 或者这样说,假设我的程序注冊了一个套接字去接受数据包,可是每收到一个数据包都须要非常长 ...

  6. javascript保留两位

    原文:javascript保留两位 //保留两位小数 //功能:将浮点数四舍五入,取小数点后2位 function toDecimal(x) { var f = parseFloat(x); if ( ...

  7. HAProxy+apache实现web服务动静分离

    HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支 ...

  8. MD5算法-爬虫学习(五)

    在实现爬虫的时候,我们使用Hash结构去存储我们用过的URL的时候,有些URL可能长度很长,为了更加节省空间,我们就要对URL进行压缩,帮它减减肥,这个我们介绍这个MD5算法,可以对URL进行有效的压 ...

  9. 基于Stm32的MP3播放器设计与实现

    原创博文,转载请注明出处 这是我高级电子技术试验课做的作业,拿来共享一下.项目在安福莱例程基础之上进行的功能完善,里面的部分内容可参考安福莱mp3例程.当然用的板子也是安福莱的板子,因为算起来总共做了 ...

  10. 【IOS开发】如何画1像素的线

    最近在项目中画了一根1像素的线,我是通过直接花一个但是通过PS查看,画了不止1个像素. 原代码语句: label1 = [[UILabel alloc] initWithFrame:CGRectMak ...