zoukankan      html  css  js  c++  java
  • dubbo+zookeeper+ssm 分布式项目搭建随记

    1.配置主机的映射(默认为127.0.0.1  localhost)

    修改C:WindowsSystem32driversetc目录下的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 &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

    <Context crossContext="true" docBase="F:TestProject1 oolssdk-service-tools argetsdk-service-tools" path="sdk-service-tools" reloadable="false"/>
    <Context crossContext="true" docBase="F:TestProject1 oolssdk-service-base argetsdk-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 oolsweb-tools argetweb-tools" path="" reloadable="false"/>
    </Host>
    </Engine>
    </Service>
    </Server>

    3.运行zookeeper服务器

    F:TestProject1zookeeper-3.4.8in目录下的zkServer.cmd

    4.进入项目的目录下运行mavan install

    例如:F:TestProject1 oolsweb-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以及操作系统的一些参数,可以供程序判断等。

    1. <span style="font-size:18px">System.getProperty("java.vm.version");//java虚拟机版本  
    2. System.getProperty("java.vendor.url"); //java官方网站  
    3. System.getProperty("java.vm.nam"); //java虚拟机名称  
    4. System.getProperty("user.country"); //国家或地区  
    5. System.getProperty("user.dir"); //工程的路径  
    6. System.getProperty("java.runtime.version");//java运行环境版本  
    7. System.getProperty("os.arch"); //操作系统位数(32或64)  
    8. System.getProperty("os.name"); //操作系统名称  
    9. System.getProperty("sun.jnu.encoding"); //编码格式  
    10. System.getProperty("os.version"); //操纵系统版本  
    11. 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包

    
    
    当能力支撑不了野心时,就该静下心来学习!
  • 相关阅读:
    c#基础练习
    一款很厉害的死循环代码
    文字变色逐个出现的特效源码
    IOS开发之UILabel动态高度设置方法
    慎重选择容器类型
    Mac下显示隐藏文件 以及修改 hosts文件内容
    SharePoint 如何使自己的网页自动跳转
    位置和地图:地图的使用
    谈话Java在ThreadLocal理解类
    Android 滑动界面实现---Scroller类别 从源代码和开发文档了解(让你的移动布局)
  • 原文地址:https://www.cnblogs.com/1234cjq/p/7453795.html
Copyright © 2011-2022 走看看