1.配置主機的映射(默認為127.0.0.1 localhost)
修改C:\Windows\System32\drivers\etc目錄下的hosts文件(默認為空,屬性為只讀)
取消只讀 在空白文件中加入127.0.0.1 www.cjq.com 映射
2.配置分布式的服務和web
修改當前tomcat服務器下的server.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
--><Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener"/>
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/> //服務器的端口號配置
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the BIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine defaultHost="localhost" name="Catalina">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- 實現tomcat熱部署和自定義ContextPath-->
<!--<Context docBase="myPrj " path="/demo1" reloadable="true"/>-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
<Context crossContext="true" docBase="F:\TestProject1\tools\sdk-service-tools\target\sdk-service-tools" path="sdk-service-tools" reloadable="false"/>
<Context crossContext="true" docBase="F:\TestProject1\tools\sdk-service-base\target\sdk-service-base" path="sdk-service-base" reloadable="false"/>
//部署分布式時新增兩行 配置服務
</Host>
//新增HOST標簽,配置web name是主機的映射
<Host appBase="tool" autoDeploy="true" name="www.cjq.com" unpackWARs="true">
<Context docBase="F:\TestProject1\tools\web-tools\target\web-tools" path="" reloadable="false"/>
</Host>
</Engine>
</Service>
</Server>
3.運行zookeeper服務器
F:\TestProject1\zookeeper-3.4.8\bin目錄下的zkServer.cmd
4.進入項目的目錄下運行mavan install
例如:F:\TestProject1\tools\web-tools目錄下開啟cmd命令窗口
運行mvn clean install -Dmaven.test.skip
5.服務器下新增數據庫配置文件dtools.properties
#jdbc setting
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/tools
username=root
password=root
initialSize=0
maxActive=20
maxIdle=20
minIdle=1
maxWait=60000
#dubbo setting
#img setting
imgPath=G:/workspace/upload/imgUpload/
imgTempPath=G:/workspace/upload/imgTempUpload/
imgDestPath=G:/workspace/upload/imgDestUpload/
#file setting
fileSavePath=G:/workspace/upload/fileUploadPath
fileDestSavePath=G:/workspace/upload/fileDestUploadPath
fileTmpSavePath=G:/workspace/upload/fileTmpUploadPath
#video setting
videoDesPath=G:/workspace/upload/fileVideoDesUploadPath
#dubbo setting
dubboRegister1=zookeeper://127.0.0.1:2181
dubboBasePortProvide=20880
dubboToolPortProvide=20881
dubboName=dubbo
#resource setting
resourcePath=/usr/local/program/resource
6.tomcat服務器主頁設置
配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
。。。。。。
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7./user/local路徑
Linux 的軟件安裝目錄是也是有講究的,理解這一點,在對系統管理是有益的
/usr
:系統級的目錄,可以理解為C:/Windows/
,/usr/lib
理解為C:/Windows/System32
。/usr/local
:用戶級的程序目錄,可以理解為C:/Progrem Files/
。用戶自己編譯的軟件默認會安裝到這個目錄下。/opt
:用戶級的程序目錄,可以理解為D:/Software
,opt有可選的意思,這里可以用於放置第三方大型軟件(或游戲),當你不需要時,直接rm -rf
掉即可。在硬盤容量不夠時,也可將/opt單獨掛載到其他磁盤上使用。
源碼放哪里?/usr/src
:系統級的源碼目錄。/usr/local/src
:用戶級的源碼目錄。
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8.java Properties類 讀取配置文件
它提供了幾個主要的方法:
1. getProperty ( String key),用指定的鍵在此屬性列表中搜索屬性。也就是通過參數 key ,得到 key 所對應的 value。
2. load ( InputStream inStream),從輸入流中讀取屬性列表(鍵和元素對)。通過對指定的文件(比如說上面的 test.properties 文件)進行裝載來獲取該文件中的所有鍵 - 值對。以供 getProperty ( String key) 來搜索。
3. setProperty ( String key, String value) ,調用 Hashtable 的方法 put 。他通過調用基類的put方法來設置 鍵 - 值對。
4. store ( OutputStream out, String comments),以適合使用 load 方法加載到 Properties 表中的格式,將此 Properties 表中的屬性列表(鍵和元素對)寫入輸出流。與 load 方法相反,該方法將鍵 - 值對寫入到指定的文件中去。
5. clear (),清除所有裝載的 鍵 - 值對。該方法在基類中提供。
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9.java中給我們提供了System.getProperty()這個函數,這個函數可以獲取到java JVM以及操作系統的一些參數,可以供程序判斷等。
- <span style="font-size:18px">System.getProperty("java.vm.version");//java虛擬機版本
- System.getProperty("java.vendor.url"); //java官方網站
- System.getProperty("java.vm.nam"); //java虛擬機名稱
- System.getProperty("user.country"); //國家或地區
- System.getProperty("user.dir"); //工程的路徑
- System.getProperty("java.runtime.version");//java運行環境版本
- System.getProperty("os.arch"); //操作系統位數(32或64)
- System.getProperty("os.name"); //操作系統名稱
- System.getProperty("sun.jnu.encoding"); //編碼格式
- System.getProperty("os.version"); //操縱系統版本
- System.getProperty("java.version"); //java版本版本</span>
System.getProperty("catalina.home") ,Tomcat 安裝目錄,一般是用來查找庫 jar 的。
System.getProperty("catalina.base"),服務器配置目錄,所有配置文件都在這里,你可以用一個catalina.home 來啟動兩個命令行來運行兩個不同的 catalina.base 配置(前提你已經修改了配置文件保證它們的端口不會沖突);
當在 eclipse 里面運行時,多數情況下 cataline.home 還是 tomcat 目錄,而 catalina.base 是 eclipse workspace 里面的一個目錄,你現在需要拿到的應該是工作時的配置目錄下的子目錄
,所以你應該用 catalina.base 當成根目錄;比如,我想讀取 tomcat user 文件,得到的結果相當於 ${cataline.base}/conf/tomcat-users.xml
------------------------------------------------------------------------------------------------------------------------------------------------------
項目部署到tomcat時WEB-INF目錄下缺少lib包
項目右鍵-Properties-Deployment Assembly-Add-java build path entries點擊進去添加mavan依賴的jar包