当前位置:首页 > CN2资讯 > 正文内容

javaapplicationWeb application setup on Ubuntu VPS

2天前CN2资讯


题记:写这篇博客要主是加深自己对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@

    

    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

---------------------------------


    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/18388.html

    分享给朋友:

    “javaapplicationWeb application setup on Ubuntu VPS” 的相关文章

    中国电信CN2网络费用解析:高效稳定,助力全球互联

    在全球化快速发展的今天,企业对国际网络的需求日益增长。无论是跨国企业的数据传输、海外分支机构的互联,还是个人用户对高质量国际带宽的需求,中国电信CN2网络凭借其卓越的性能和稳定的连接,成为了用户的首选。随着需求的增加,用户对CN2网络的费用结构也愈发关注。本文将深入解析中国电信CN2网络的费用体系,...

    RackNerd VPS服务测评:性价比高、稳定性强的主机商推荐

    在当今的网络世界中,选择合适的主机商显得尤为重要。我最近体验了RackNerd这家提供VPS服务的主机商,想和大家分享一些我的观点。RackNerd因其性价比高而广受好评,这让我在决定购买前进行了详细的测评。我会从多个角度来探讨RackNerd的各方面表现。 RackNerd不仅在价格上拥有明显优势...

    服务器租赁指南:如何选择适合的云服务和价格

    对于很多企业和个人用户来说,服务器租赁是一个非常实用的选择。简单来说,服务器租赁就是用户向服务器提供商支付费用,然后获得在一定时间内使用服务器的权利。这样一来,用户就无需花费时间和金钱去购买和维护物理服务器,可以迅速开始在线业务。 当我第一次接触服务器租赁时,发现这一服务的便利性令我十分惊讶。传统的...

    Win10一键安装SQLite脚本:简化你的数据库配置过程

    在开始使用SQLite之前,首先需要确保它已经正确安装在你的Windows 10系统上。这个过程包括几个简单的步骤。我会逐步带你完成这些操作,让你能快速进入SQLite的世界。 访问SQLite官网 首先,前往SQLite的官方网站,网址是https://www.sqlite.org/downloa...

    全面了解Amazon CDN CloudFront:快速、安全的内容分发网络服务

    在互联网的快速发展中,内容分发网络(CDN)成为确保网站速度和性能的重要保证。CDN是通过在全球各地的多个服务器上缓存和分发内容,以最短的路径将数据传送给用户。这样做不仅加快了加载速度,还提高了用户体验。通过保存内容的副本在离用户更近的地点,CDN能够显著降低网络延迟。 而Amazon CloudF...

    2023年VPS评测:选择适合您的虚拟私人服务器的指南

    在网络世界中,VPS代表虚拟私人服务器。简单来说,它是一种虚拟化技术,允许用户在一台物理服务器上运行多个虚拟服务器。每个VPS都有独立的操作系统和资源,用户可以专属管理和配置,像对待自己的服务器一样。这种灵活性使得VPS成为开发者、企业和个体户等各种用户的热门选择。无论是网站托管,还是应用程序的开发...