Tomcat企業級應用

来源:https://www.cnblogs.com/caicairui/archive/2018/03/23/8630719.html
-Advertisement-
Play Games

簡介 Tomcat是Apache 軟體基金會(Apache Software Foundation)的Jakarta 項目中的一個核心項目,由Apache、Sun 和其他一些公司及個人共同開發而成。由於有了Sun 的參與和支持,最新的Servlet 和JSP 規範總是能在Tomcat 中得到體現,T ...


簡介

Tomcat是Apache 軟體基金會(Apache Software Foundation)的Jakarta 項目中的一個核心項目,由Apache、Sun 和其他一些公司及個人共同開發而成。由於有了Sun 的參與和支持,最新的Servlet 和JSP 規範總是能在Tomcat 中得到體現,Tomcat 5支持最新的Servlet 2.4 和JSP 2.0 規範。因為Tomcat 技術先進、性能穩定,而且免費,因而深受Java 愛好者的喜愛並得到了部分軟體開發商的認可,成為目前比較流行的Web 應用伺服器。 Tomcat 伺服器是一個免費的開放源代碼的Web 應用伺服器,屬於輕量級應用伺服器,在中小型系統和併發訪問用戶不是很多的場合下被普遍使用,是開發和調試JSP 程式的首選。對於一個初學者來說,可以這樣認為,當在一臺機器上配置好Apache 伺服器,可利用它響應HTML標準通用標記語言下的一個應用)頁面的訪問請求。實際上Tomcat是Apache 伺服器的擴展,但運行時它是獨立運行的,所以當你運行tomcat 時,它實際上作為一個與Apache 獨立的進程單獨運行的。 訣竅是,當配置正確時,Apache 為HTML頁面服務,而Tomcat 實際上運行JSP 頁面和Servlet。另外,Tomcat和IIS等Web伺服器一樣,具有處理HTML頁面的功能,另外它還是一個Servlet和JSP容器,獨立的Servlet容器是Tomcat的預設模式。不過,Tomcat處理靜態HTML的能力不如Apache伺服器。目前Tomcat最新版本為9.0。 類似於Apache,Nginx等web伺服器 nginx和httpd只能處理html等靜態文件(jpg),配合PHP就能夠處理動態的網頁(以.php結尾)、 但Tomcat處理靜態HTML的能力不如Nginx、Apache

軟體版本選擇

JDK下載:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html、

Tomcat下載:http://tomcat.apache.org/

說明:在生產環境下,使用Tomcat安裝版本需要同開發協商,Tomcat和JDK版本必須並行(tomcat8<=>jdk8)

Tomcat安裝

安裝JDK(以後所有涉及到java應用的都需要安裝)

JDK->JAVA虛擬機(jvm)>一處編譯,處處使用

[root@cairui software]# tar xf jdk-8u161-linux-x64.tar.gz
[root@cairui software]# ls
jdk1.8.0_161
jdk-8u161-linux-x64.tar.gz
[root@cairui software]# mv  jdk1.8.0_161/ /opt/jdk1.8
[root@cairui opt]# ln -s jdk1.8/ jdk
[root@cairui opt]# ll
total 4
lrwxrwxrwx 1 root root    7 Mar 23 12:14 jdk -> jdk1.8/
drwxr-xr-x 8 uucp  143 4096 Dec 20 08:24 jdk1.8
[root@cairui opt]# sed -i.ori '$a export JAVA_HOME=/opt/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile
[root@cairui opt]# source /etc/profile
[root@cairui opt]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
[root@cairui opt]# tail -4 /etc/profile
unset -f pathmunge
export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar

安裝Tomcat

[root@cairui software]# tar xf apache-tomcat-8.0.50.tar.gz 
[root@cairui software]# ls
apache-tomcat-8.0.50  apache-tomcat-8.0.50.tar.gz  jdk-8u161-linux-x64.tar.gz
[root@cairui software]# mv apache-tomcat-8.0.50 /opt/tomcat-8.0.50
[root@cairui opt]# ln -s tomcat-8.0.50/ tomcat
[root@cairui opt]# ll
total 8
lrwxrwxrwx 1 root root    7 Mar 23 12:14 jdk -> jdk1.8/
drwxr-xr-x 8 uucp  143 4096 Dec 20 08:24 jdk1.8
lrwxrwxrwx 1 root root   14 Mar 23 12:41 tomcat -> tomcat-8.0.50/
drwxr-xr-x 9 root root 4096 Mar 23 12:40 tomcat-8.0.50
[root@cairui opt]# echo 'export TOMCAT_HOME=/opt/tomcat'>>/etc/profile
[root@cairui opt]# source /etc/profile
[root@cairui opt]# useradd tomcat -s /sbin/nologin -M
[root@cairui opt]# chown -R tomcat.tomcat /opt/jdk /opt/tomcat
[root@cairui opt]# ll
total 8
lrwxrwxrwx 1 tomcat tomcat    7 Mar 23 12:14 jdk -> jdk1.8/
drwxr-xr-x 8 uucp      143 4096 Dec 20 08:24 jdk1.8
lrwxrwxrwx 1 tomcat tomcat   14 Mar 23 12:41 tomcat -> tomcat-8.0.50/
drwxr-xr-x 9 root   root   4096 Mar 23 12:40 tomcat-8.0.50

出現下述結果表明配置成功

[root@cairui opt]# /opt/tomcat/bin/version.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /opt/jdk
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.50
Server built:   Feb 7 2018 20:06:05 UTC
Server number:  8.0.50.0
OS Name:        Linux
OS Version:     2.6.32-696.6.3.el6.x86_64
Architecture:   amd64
JVM Version:    1.8.0_161-b12
JVM Vendor:     Oracle Corporation

Tomcat目錄結構

[root@cairui tomcat]# tree -L 2
.
├── bin  #用以啟動和關閉Tomcat或者其它功能腳本
│   ├── bootstrap.jar
│   ├── catalina.bat
│   ├── catalina.sh  #核心
│   ├── catalina-tasks.xml
│   ├── commons-daemon.jar
│   ├── commons-daemon-native.tar.gz
│   ├── configtest.bat
│   ├── configtest.sh
│   ├── daemon.sh
│   ├── digest.bat
│   ├── digest.sh
│   ├── setclasspath.bat
│   ├── setclasspath.sh
│   ├── shutdown.bat
│   ├── shutdown.sh  #關閉腳本
│   ├── startup.bat
│   ├── startup.sh  #啟動腳本
│   ├── tomcat-juli.jar
│   ├── tomcat-native.tar.gz
│   ├── tool-wrapper.bat
│   ├── tool-wrapper.sh
│   ├── version.bat
│   └── version.sh
├── conf  #用以配置Tomcat的XML文件
│   ├── catalina.policy
│   ├── catalina.properties
│   ├── context.xml
│   ├── logging.properties
│   ├── server.xml  #主配置文件
│   ├── tomcat-users.xml  #管理用戶配置文件
│   ├── tomcat-users.xsd
│   └── web.xml
├── lib
│   ├── annotations-api.jar
│   ├── catalina-ant.jar
│   ├── catalina-ha.jar
│   ├── catalina.jar
│   ├── catalina-storeconfig.jar
│   ├── catalina-tribes.jar
│   ├── ecj-4.6.3.jar
│   ├── el-api.jar
│   ├── jasper-el.jar
│   ├── jasper.jar
│   ├── jsp-api.jar
│   ├── servlet-api.jar
│   ├── tomcat-api.jar
│   ├── tomcat-coyote.jar
│   ├── tomcat-dbcp.jar
│   ├── tomcat-i18n-es.jar
│   ├── tomcat-i18n-fr.jar
│   ├── tomcat-i18n-ja.jar
│   ├── tomcat-jdbc.jar
│   ├── tomcat-jni.jar
│   ├── tomcat-util.jar
│   ├── tomcat-util-scan.jar
│   ├── tomcat-websocket.jar
│   └── websocket-api.jar
├── LICENSE
├── logs  #web應用程式的日誌文件
├── NOTICE
├── RELEASE-NOTES
├── RUNNING.txt
├── temp  #臨時目錄
│   └── safeToDelete.tmp
├── webapps  #web網頁應用程式根目錄
│   ├── docs  #Tomcat幫助文檔
│   ├── examples  #web應用實例
│   ├── host-manager  #管理
│   ├── manager  #管理
│   └── ROOT  #預設網站根目錄
└── work
[root@cairui tomcat]# /opt/tomcat/bin/startup.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /opt/jdk
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@cairui tomcat]# lsof -i:8080  #預設的是8080埠
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java    1955 root   48u  IPv4  15539      0t0  TCP *:webcache (LISTEN)

  

查看日誌文件

[root@cairui tomcat]# cd /opt/tomcat/logs/
[root@cairui logs]# ll
total 24
-rw-r--r-- 1 root root 6406 Mar 23 13:19 catalina.2018-03-23.log
-rw-r--r-- 1 root root 6406 Mar 23 13:19 catalina.out  #實時記錄Tomcat的運行信息(文件越來越大,需要定時清理)
-rw-r--r-- 1 root root    0 Mar 23 13:19 host-manager.2018-03-23.log
-rw-r--r-- 1 root root  459 Mar 23 13:19 localhost.2018-03-23.log
-rw-r--r-- 1 root root  755 Mar 23 13:21 localhost_access_log.2018-03-23.txt
-rw-r--r-- 1 root root    0 Mar 23 13:19 manager.2018-03-23.log
[root@cairui logs]# tail catalina.out 
23-Mar-2018 13:19:04.226 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.0.50/webapps/manager has finished in 100 ms
23-Mar-2018 13:19:04.226 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/tomcat-8.0.50/webapps/host-manager
23-Mar-2018 13:19:04.303 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.0.50/webapps/host-manager has finished in 77 ms
23-Mar-2018 13:19:04.308 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/tomcat-8.0.50/webapps/examples
23-Mar-2018 13:19:05.000 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.0.50/webapps/examples has finished in 692 ms
23-Mar-2018 13:19:05.000 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/tomcat-8.0.50/webapps/docs
23-Mar-2018 13:19:05.037 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.0.50/webapps/docs has finished in 37 ms
23-Mar-2018 13:19:05.048 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
23-Mar-2018 13:19:05.078 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
23-Mar-2018 13:19:05.098 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 2793 ms

通過web管理Tomcat

定義web頁面用戶名以及密碼

[root@cairui logs]# tail -4 /opt/tomcat/conf/tomcat-users.xml 
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
</tomcat-users>

重啟:
[root@cairui logs]# /opt/tomcat/bin/shutdown.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /opt/jdk
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
[root@cairui logs]# /opt/tomcat/bin/startup.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /opt/jdk
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.

[root@cairui logs]# lsof -i|grep java
java      7947 root   48u  IPv4  20525      0t0  TCP *:webcache (LISTEN)
java      7947 root   53u  IPv4  20529      0t0  TCP *:8009 (LISTEN)
java      7947 root   68u  IPv4  20540      0t0  TCP localhost:mxi (LISTEN)

Tomcat主配置文件

[root@cairui logs]# cat /opt/tomcat/conf/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 className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- 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 name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </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/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               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/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO 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.Http11NioProtocol"
               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 name="Catalina" defaultHost="localhost">

      <!--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 name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- 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"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>
[root@cairui logs]# cat /opt/tomcat/conf/server.xml | egrep -v "^$| <\!|<\!"
<?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.
-->
     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" />
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
       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服務組件> <Service name="Catalina"> <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="150" minSpareThreads="4"/> --> 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/TLS HTTP/1.1 Connector on port 8080 --> <Connector port="8080" protocol="HTTP/1.1"  #connector接收用戶請求,類似於httpd的listen配置監聽埠,port指定伺服器需要創建的埠 connectionTimeout="20000" redirectPort="8443" /> <Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> --> This connector uses the NIO 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.Http11NioProtocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> --> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 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 --> <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> --> <Engine name="Catalina" defaultHost="localhost"> /docs/cluster-howto.html (simple how to) /docs/config/cluster.html (reference documentation) --> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> --> via a brute-force attack --> <Realm className="org.apache.catalina.realm.LockOutRealm">  #realm表示存放用戶名,密碼以及role的資料庫 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表示一個虛擬機,name指定主機名,appbase應用程式目錄 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> Documentation at: /docs/config/valve.html --> <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> 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" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> </Server>

web站點部署

方法一:即直接將程式目錄放在webapps下

方法二:即用開發工具將程式打包成war包。然後上傳到webapps下

搭建Jpress->java版本的wordpress

下載地址:https://github.com/JpressProjects/jpres

安裝配置資料庫

[root@cairui opt]# rpm -qa | grep mysql*
[root@cairui opt]# yum install mysql -y    
[root@cairui opt]# yum install mysql-server -y
[root@cairui opt]# yum install mysql-devel -y
[root@cairui opt]# /etc/init.d/mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h cairui password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@cairui opt]# /usr/bin/mysqladmin -u root password '123456'
[root@cairui opt]# source /etc/profile
[root@cairui opt]# mysql -uroot -p123456

  

mysql> create database jpress default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on jpress.* to jpress@'localhost' identified by 'jpress';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

  

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 某個角度上說,kindle很類似android,同樣的Linux內核,同樣的Java用戶層。不過kindle更註重簡單、節能、穩定。Amazon一向認為,功能過多會分散人們閱讀時候的註意力。 Kindle底層的Linux比Android保持了更多的linux相容性,可以使用GTK或者QT編寫程式。Q ...
  • exit(0):正常運行程式並退出程式; exit(1):非正常運行導致退出程式; exit 0 可以告知你的程式的使用者:你的程式是正常結束的。如果 exit 非 0 值,那麼你的程式的使用者通常會認為你的程式產生了一個錯誤。在 shell 中調用完你的程式之後,用 echo $? 命令就可以看到 ...
  • "原文鏈接" 之所以轉載這篇文章,是因為例子舉的太好了,非常適合初學者理解。但是樣式有點亂 自己稍微整理了下。 正向代理 比如你現在缺錢,想找馬雲爸爸去借錢,可想而知人家可能鳥都不鳥你,到最後碰一鼻子灰借不到錢。不過你認識你家隔壁老王,而老王認識馬雲同志,而且關係還很好。這時候你托老王去找馬雲借錢, ...
  • Linux由於其眾多獨特的優勢(可參見Linux系統的優勢),而被很多人所喜愛。而要使用Linux那首先要做的工作就是安裝Linux系統了。這裡給出在 win10 下利用虛擬機 Hyper-v 安裝 Linux 的過程供大家交流學習。 由於 Linux 版本眾多,在選擇時很多人就犯難了,不知道該怎樣 ...
  • 一、shell和shell腳本 在linux系統下,以 #/bin/bash開頭的文本會被shell解釋器進行解釋。 shell是指一種應用程式,這個應用程式提供了一個界面,用戶通過這個界面訪問操作系統內核的服務。 shell腳本(shell script),是一種為shell編寫的腳本程式。業界所 ...
  • 熟悉電腦的人都知道,Linux 相比較於 Windows 有著眾多的優勢,所以現在越來越多的電腦用戶開始使用 Linux 進行辦公、學習。總體來講,Linux 的優勢主要有以下幾個方面。 一、開源、免費 眾所周知,不管是微軟的 Windows 還是蘋果的 macOS,都是需要付費的,而且是比較昂貴的 ...
  • 隨著深度學習、區塊鏈的發展,人類對計算量的需求越來越高,在傳統的計算模式下,壓榨GPU的計算能力一直是重點。 NV系列的顯卡在這方面走的比較快,CUDA框架已經普及到了高性能計算的各個方面,比如Google的TensorFlow深度學習框架,預設內置了支持CUDA的GPU計算。 AMD(ATI)及其 ...
  • 介紹 它是一套數據緩存系統或軟體 用於動態應用系統中緩存資料庫的數據,減少資料庫的訪問壓力,達到提升性能的效果,實際應用環境中多用於資料庫的cache的應用。它是通過預分配指定的記憶體空間來存儲數據 定義 它是一個開源的、高性能的,具有分散式記憶體對象的緩存系統,它一般用來存儲經常讀取的對象或數據,如同 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...