Tomcat application and Deployment (ii)

Source: Internet
Author: User


(ii) Application deployment


1. Tomcat's directory structure

[[email protected] tomcat]# ls bin conf lib LICENSE logs NOTICE release-notes RUNNING.txt temp WebApps work

Bin: Scripts and classes used at startup
Conf: Configuration file
LIB: Class Library
Logs: Log file
Temp: Temp file directory
WebApps: Application Default Deployment Directory
Work: Working directory

Tomcat configuration file:

[[email protected] tomcat]# ls conf/catalina.properties logging.properties tomcat-users.xmlcatalina.policy contex T.xml Server.xml Web

Catalina.properties #java属性的定义文件, setting class loader path, and some tuning parameters related to JVM performance
Logging.properties #tomcat日志配置文件
Tomcat-users.xml:tomcat #用户认证的账号和密码配置文件
Catalina.policy # This configuration file is read when the Tomcat instance is launched with the-security option to implement its secure run policy
Context.xml #每个webapp都可以有专用的配置文件, these profiles are typically located in the Web-inf directory under the WebApp application directory to define the session manager, JDBC, and so on, conf/ Context.xml is providing a default configuration for a WebApp
Server.xml #用于定义tomcat体系结构, ports, clusters, Web applications, access logs, and more
Web. XML #每个为webapp "deployed" before it can be accessed, and this file is used to provide a default deployment-related configuration for all WebApp

Once you know the directories and profiles, manually add an application to test it:

1. Create a WebApp-specific directory structure
2. Provision of WebApp documents
3. Create JSP default home page

[Email protected] webapps]# pwd/usr/local/tomcat/webapps[[email protected] webapps]# MKDIR-PV myapp/{lib,classes, Web-inf,meta-inf} #创建文件mkdir: Created directory ' MyApp ' #存放webapp的主页文件mkdir: Created directory ' Myapp/lib ' #此webapp私有类, Packaged as JAR format Class mkdir:created directory ' myapp/classes ' #此webapp的私有类mkdir: Created directory ' Myapp/web-inf ' # Current WebApp Private Resource directory, storing web.xmlmkdir:created directory ' Myapp/meta-inf ' #同上, but storing the context.xml for personal use


[Email protected] webapps]# vim myapp/index.jsp #编辑jsp主页文件内容:
<body>
<center>
</center>

</body>

When the deployment is complete, the default Catalina engine is automatically deployed without requiring a manual restart to enter tests directly in the browser:

650) this.width=650; "Width=" 931 "height=" 285 "title=" image 068.png "style=" WIDTH:726PX;HEIGHT:286PX; "alt=" Wkiom1y4ylpwpdodaad5bto4mxq799.jpg "src=" http://s3.51cto.com/wyfs02/M02/75/68/ Wkiom1y4ylpwpdodaad5bto4mxq799.jpg "/> can see hello,word! , so a simple JSP web page is completed


2. Deploy the MySQL database:


The deployment application must have a database, the following is the source code compiled to install MySQL:

Download MySQL source package and CMake package:
Mysql-5.6.13.tar.gz cmake-2.8.12.2-4.el6.x86_64

First install the program development package:

[[email protected] ~]# yum groupinstall  " Development tools " " Server platform development "[[email protected] ~]  groupadd mysql   #创建mysql组 [[email protected] ~] useradd -r -g  mysql mysql  #创建mysql系统用户 [[email protected] ~] tar –zxvf mysql-5.6.13.tar.gz   #解压包 [[email protected] ~] cd mysql-5.6.13.tar.gz 
[[email protected] mysql-5.6.13.tar.gz] cmake . --dcmake_install_prefix=/usr/local/ mysql \  #安装路径-dmysql_datadir=/usr/local/mysql/data \   #数据存放目录-dsysconfdir=/etc \        #配置文件-dwith_myisam_storage_engine=1 \    # MyISAM Storage Engine-dwith_innobase_storage_engine=1 \    #innobase存储引擎-dwith_memory_storage_engine=1  \     #memory内存引擎-dwith_readline=1 -dmysql_unix_addr=/var/lib/mysql/mysql.sock  \   #sock文件路径-dmysql_tcp_port=3306 \          #指定端口-denabled_local_infile=1 \      #允许从本地导入数据-dwith_partition_storage_engine=1  \   #分区引擎-dextra_charsets=all \       #支持所有字符集-ddefault_ charset=utf8 \       #指定默认字符为utf8-ddefault_collation=utf8_general_ci     #校验字符
[[email protected] ~] chown –r mysql.mysql  /usr/local/mysql  Change directory owner [[email protected] mysql]# cd scripts/ [[email  protected] scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/  --datadir=/usr/local/mysql/data/    #初始化数据库 [[EMAIL&NBSP;PROTECTED]&NBSP;MYSQL]#&NBSP;CD  support-files/   #注册服务 [[Email protected] support-files]# cp mysql.server  /etc/rc.d/init.d/mysql[[email protected] support-files]# cp my-default.cnf /etc /my.cnf  #设置默认配置文件 [email protected] support-files]# chkconfig --add mysql [[ email protected] support-files]# chkconfig mysql on   #开机启动 
[Email protected] support-files]# vim/etc/my.cnf #修改编码文件, join [CLIENT]DEFAULT-CHARACTER-SET=UTF8[MYSQLD] Character-set-server=utf8[mysql]default-character-set=utf8

and comment out the last line:
#sql_mode =no_engine_substitution,strict_trans_tables
Save exit

[Email protected] support-files]# vim/etc/profile.d/mysql.sh #加入环境变量, the content is as follows: Eport Mysql_home=/usr/local/mysqleport Path= $MYSQL _home/bin: $PATH


Save exit

[Email protected] support-files]#. /etc/profile.d/mysql.sh #重新加载文件 [[email protected] ~]# mysql–uroot #以root身份登陆, default no password, enter settings mysql> set password = Passwo RD (' 123456 '); Set Password mysql> grant all privileges on * * ' root ' @ '% ' identified by ' 123456 ' with GRANT option; #授权任意地址通过root都可以登陆mysql > Exit #退出数据库

Note: Database rules are capitalized and are used here for ease of use lowercase

[[Email protected] ~]# service mysql start #启动服务Starting MySQL success! [[email protected] ~]# SS–TNL #3306端口已监听, service started successfully state Recv-q send-q Local address:port Peer address:portlist EN 0::: 3306:::*

The database deployment is complete.


In order for Tomcat to interact with MySQL, you need to use a jar package Mysql-connector-java-5.1.13-bin.jar, download it and put it under the Tomcat directory lib.

[[email protected] ~]# ls
Anaconda-ks.cfg Install.log.syslog mysql-5.6.13.tar.gz
apache-tomcat-7.0.65.tar.gz jdk-7u79-linux-x64.rpm Mysql-connector-java-5.1.13-bin.jar
Install.log mysql-5.6.13
[email protected] ~]# CP mysql-connector-java-5.1.13-bin.jar/usr/local/tomcat/lib/

This allows you to test whether Tomcat interacts with MySQL, as long as you write a connection page, as follows:

[Email protected] ~]# vim/usr/local/tomcat/webapps/myapp/test.mysql.jsp

   <%@ page language= "java"%>
   <%@ page import= "Com.mysql.jdbc.Driver"%>
   <%@ page import= "java.sql.*"%>
<%
String drivername= "Com.mysql.jdbc.Driver";
String username= "root";
String userpasswd= "hong123";
String dbname= "test";
String url= "jdbc:mysql://localhost/" +dbname+ "user=" +username+ "&password=" +USERPASSWD;
Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
Try
{
        Connection connection=drivermanager.getconnection (url );
        out.println ("Connection Mysql is OK!");
        connection.close ();
}
catch (Exception e)
{
        out.println ("connent mysql error:" + e);
}
%>
to restart Tomcat after the save is exited.

[[email protected] ~]# catalina.sh stop[[email protected] ~]# catalina.sh start

To a browser test for results:

650) this.width=650; "title=" Image 069.png "alt=" wkiol1y4zdqdmomyaac22tgfisa074.jpg "src=" http://s3.51cto.com/wyfs02/ M01/75/65/wkiol1y4zdqdmomyaac22tgfisa074.jpg "/>

You can see that Tomcat has no problem interacting with the database


3. Publishing a Web site


First upload the Web site defined folder (development of the job) to the server

[[email protected] ~]# unzip   shopxx-a5-beta.zip   #上传上来的web网站, unzip [[email protected] ~]# mv shopxx-v3.0-beta/  /usr/local/tomcat/webapps/#移动至webapps下 [[email protected] webapps]# ln -s  shopxx-v3.0-beta/ shopxx  #创建软链接 [[email protected] webapps]# ls shopxx/     #可以看到整合的文件admin           favicon.ico   install       meta-inf   robots.txt   uploadchangelog.txt  index.jsp    license.html  resources   Shopxx.txt  web-inf 
[[email protected] tomcat]# vim conf/server.xml #修改配置文件, add the following: Locate the%tomcathome%/conf/server.xml file, locate the 

Note: path: virtual path Docbase:web physical storage paths

Then restart the Tomcat service:

[[email protected] tomcat]# catalina.sh stop [[email protected] tomcat]# catalina.sh start

Then in the browser input Http://IP address: Port/virtual directory/install, you can execute:

650) this.width=650; "Width=" 1171 "height=" 702 "title=" image 070.png "style=" width:736px;height:455px; "alt=" Wkiol1y4zmoays4zaaxrloiigqq288.jpg "src=" Http://s3.51cto.com/wyfs02/M01/75/65/wKioL1Y4ZMOAys4zAAXrloiiGqQ288.jpg "/>

Next, start the deployment and choose Next:

650) this.width=650; "Width=" 1001 "height=" 636 "title=" image 071.png "style=" WIDTH:741PX;HEIGHT:546PX; "alt=" Wkiol1y4zwgj_-tuaaovjh7_0im175.jpg "src=" http://s3.51cto.com/wyfs02/M02/75/66/wKioL1Y4ZWGj_-TUAAOVjH7_ 0im175.jpg "/> Here to see the environmental monitoring database is not found, ignore it, directly next:


Note: The default server.tml character set is not specified, which is sometimes not detected and added to the server.tml character set:

<connector port= "8080" protocol= "http/1.1"
connectio,ntimeout= "20000"
Redirectport= "8443"
uriencoding= "Utf-8"/> #添加后就可以检测到了.


Next:

650) this.width=650; "Width=" "height=" 651 "title=" image 072.png "style=" WIDTH:743PX;HEIGHT:614PX; "alt=" Wkiol1y4zdoscm_oaalb8moc4og005.jpg "src=" Http://s3.51cto.com/wyfs02/M01/75/66/wKioL1Y4ZdOScM_OAALB8mOC4Og005.jpg "/>

Select the database, the database user name password, the name is the default, click Next to install:

650) this.width=650; "Width=" "height=" 551 "title=" image 073.png "style=" WIDTH:740PX;HEIGHT:527PX; "alt=" Wkiol1y4zhqgvghbaamn1b21j08743.jpg "src=" Http://s3.51cto.com/wyfs02/M01/75/66/wKioL1Y4ZhqgVghBAAMn1b21j08743.jpg "/>

Wait a moment so the Web is installed ...
Click Finish after installation. Prompting us to restart the Web service
Here we need to put the install CP in the Shopxx file to other places:

[[email protected] shopxx]# ls #看到已经生成了index. html file admin changelog.txt index.html license.html Product ROBOTS.T XT Sitemap web-infarticle Favicon.ico Install meta-inf resources shopxx.txt Upload[[email protected] Shop xx]# MV Install/back [[email protected] shopxx]# catalina.sh stop[[email protected] shopxx]# catalina.sh start

Browser Access after reboot
Http://192.168.0.100:8080/shop/index.html can

This completes the deployment:



This article is from the "Open Source Prosperity" blog, please be sure to keep this source http://zhaohongfei.blog.51cto.com/6258685/1709169

Tomcat application and Deployment (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.