(运维)--应用服务器部署

╰+攻爆jí腚メ 2023-02-24 07:49 156阅读 0赞

在现有的tomcat+nginx 配置

– add by yx
15.6环境下
目前已经存在了 应用test2已经搭建完成

配置服务器

我们以新建一个test为例

  1. ## 进入目录
  2. cd /home/tomcat/servers
  3. ## copy一份 test 服务器
  4. cp -R test2 test3
  5. cd test3
  6. ## 查看目录
  7. ll ./
  8. ## war包存放位置 webapps
  9. ## 日志文件存放 logs
  10. ## 配置文件存放 conf
  11. ## 修改对应的端口
  12. cd conf
  13. ## 修改数据源 <Resource 标签,具体可以参考其他项目搭建
  14. vim context.xml

查看context.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- The contents of this file will be loaded for each web application -->
  17. <Context>
  18. <!-- Default set of monitored resources. If one of these changes, the -->
  19. <!-- web application will be reloaded. -->
  20. <WatchedResource>WEB-INF/web.xml</WatchedResource>
  21. <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
  22. <!-- Uncomment this to disable session persistence across Tomcat restarts -->
  23. <!--
  24. <Manager pathname="" />
  25. -->
  26. <Resource name="jdbc/service"
  27. type="com.mchange.v2.c3p0.ComboPooledDataSource"
  28. maxPoolSize="30" minPoolSize="1" acquireIncrement="1" maxIdleTime="120" initialPoolSize="1"
  29. factory="org.apache.naming.factory.BeanFactory"
  30. user="inno_bdsp_dev2" password="inno_bdsp_dev2"
  31. driverClass="com.mysql.jdbc.Driver"
  32. jdbcUrl="jdbc:mysql://192.168.15.12:3306/inno_bdsp_dev2?characterEncoding=utf8"
  33. />
  34. </Context>

查看server.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- Note: A "Server" is not itself a "Container", so you may not
  17. define subcomponents such as "Valves" at this level.
  18. Documentation at /docs/config/server.html
  19. -->
  20. <Server port="6080" shutdown="SHUTDOWN">
  21. <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  22. <!-- Security listener. Documentation at /docs/config/listeners.html
  23. <Listener className="org.apache.catalina.security.SecurityListener" />
  24. -->
  25. <!--APR library loader. Documentation at /docs/apr.html -->
  26. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  27. <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  28. <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  29. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  30. <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  31. <!-- Global JNDI resources
  32. Documentation at /docs/jndi-resources-howto.html
  33. -->
  34. <GlobalNamingResources>
  35. <!-- Editable user database that can also be used by
  36. UserDatabaseRealm to authenticate users
  37. -->
  38. <Resource name="UserDatabase" auth="Container"
  39. type="org.apache.catalina.UserDatabase"
  40. description="User database that can be updated and saved"
  41. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  42. pathname="conf/tomcat-users.xml" />
  43. </GlobalNamingResources>
  44. <!-- A "Service" is a collection of one or more "Connectors" that share
  45. a single "Container" Note: A "Service" is not itself a "Container",
  46. so you may not define subcomponents such as "Valves" at this level.
  47. Documentation at /docs/config/service.html
  48. -->
  49. <Service name="Catalina">
  50. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  51. <!--
  52. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  53. maxThreads="150" minSpareThreads="4"/>
  54. -->
  55. <!-- A "Connector" represents an endpoint by which requests are received
  56. and responses are returned. Documentation at :
  57. Java HTTP Connector: /docs/config/http.html
  58. Java AJP Connector: /docs/config/ajp.html
  59. APR (HTTP/AJP) Connector: /docs/apr.html
  60. Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
  61. -->
  62. <Connector URIEncoding="UTF-8" port="6099" protocol="org.apache.coyote.http11.Http11AprProtocol"
  63. connectionTimeout="20000"
  64. redirectPort="8443"
  65. emptySessionPath="true" />
  66. <!-- A "Connector" using the shared thread pool-->
  67. <!--
  68. <Connector executor="tomcatThreadPool"
  69. port="8080" protocol="HTTP/1.1"
  70. connectionTimeout="20000"
  71. redirectPort="8443" />
  72. -->
  73. <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
  74. This connector uses the NIO implementation with the JSSE engine. When
  75. using the JSSE engine, the JSSE configuration attributes must be used.
  76. -->
  77. <!--
  78. <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
  79. maxThreads="150" SSLEnabled="true">
  80. <SSLHostConfig>
  81. <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
  82. type="RSA" />
  83. </SSLHostConfig>
  84. </Connector>
  85. -->
  86. <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
  87. This connector uses the APR/native implementation. When using the
  88. APR/native implementation or the OpenSSL engine with NIO or NIO2 then
  89. the OpenSSL configuration attributes must be used.
  90. -->
  91. <!--
  92. <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
  93. maxThreads="150" SSLEnabled="true" >
  94. <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
  95. <SSLHostConfig>
  96. <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
  97. certificateFile="conf/localhost-rsa-cert.pem"
  98. certificateChainFile="conf/localhost-rsa-chain.pem"
  99. type="RSA" />
  100. </SSLHostConfig>
  101. </Connector>
  102. -->
  103. <!-- Define an AJP 1.3 Connector on port 8009 -->
  104. <!--Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /-->
  105. <!-- An Engine represents the entry point (within Catalina) that processes
  106. every request. The Engine implementation for Tomcat stand alone
  107. analyzes the HTTP headers included with the request, and passes them
  108. on to the appropriate Host (virtual host).
  109. Documentation at /docs/config/engine.html -->
  110. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  111. <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  112. -->
  113. <Engine name="Catalina" defaultHost="localhost">
  114. <!--For clustering, please take a look at documentation at:
  115. /docs/cluster-howto.html (simple how to)
  116. /docs/config/cluster.html (reference documentation) -->
  117. <!--
  118. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  119. -->
  120. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  121. via a brute-force attack -->
  122. <Realm className="org.apache.catalina.realm.LockOutRealm">
  123. <!-- This Realm uses the UserDatabase configured in the global JNDI
  124. resources under the key "UserDatabase". Any edits
  125. that are performed against this UserDatabase are immediately
  126. available for use by the Realm. -->
  127. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  128. resourceName="UserDatabase"/>
  129. </Realm>
  130. <Host name="localhost" appBase="webapps"
  131. unpackWARs="true" autoDeploy="true">
  132. <!-- SingleSignOn valve, share authentication between web applications
  133. Documentation at: /docs/config/valve.html -->
  134. <!--
  135. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  136. -->
  137. <!-- Access log processes all example.
  138. Documentation at: /docs/config/valve.html
  139. Note: The pattern used is equivalent to using pattern="common" -->
  140. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  141. prefix="localhost_access_log" suffix=".txt"
  142. pattern="%h %l %u %t "%r" %s %b" />
  143. </Host>
  144. </Engine>
  145. </Service>
  146. </Server>

**查看对应的配置文件 server.conf **

  1. #tomcat实例目录
  2. #export CATALINA_BASE=/home/alpha/servers/"$NAME"
  3. #设置JVM内存大小
  4. export JAVA_OPTS="-Xms2048m -Xmx2048m"
  5. #这里指定的是项目所独有的环境变量
  6. #export RUN_ENV="test"
  7. export JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=test"
  8. #远程调试
  9. export JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=46900,server=y,suspend=n"
  10. #jmx
  11. export JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=45660 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -DrestTable=false "

  1. ## 修改对应的端口 因为服务器中部署了多台,所以端口需要不一样 ,修改点2处 Server port + Http prot端口 我这里是 http-->6099
  2. vim server.xml
  3. ## 配置启动参数、远程调用等端口,如果不需要可以注释
  4. vim server.xml
  5. ## webapps 因为之前的war 在里面,就没有添加,如果是其他项目,直接更换就好了
  6. ## 启动项目--发现没有bin目录 因为数据被bin隐藏了。建立一个软连接即可
  7. ln -s /etc/init.d/tomcat8 test3
  8. ## 查看日志
  9. cd /home/tomcat/servers/test3/logs
  10. ## 清理之前的日志
  11. rm -rf *
  12. ## 启动项目
  13. service test3 status
  14. service test3 start
  15. ## 查看日志
  16. tail -f catalina.out
  17. ## 没报错表示成功启动


##配置nginx

  1. ## 配置nginx 进入主目录 root 权限
  2. cd /usr/local/nginx
  3. ## 开始配置nginx
  4. cd conf
  5. ## 复制配置文件
  6. cp test2.conf test3.conf
  7. ## 编辑test3.conf
  8. vim test3.conf

test3.conf 具体如下

  1. #test2
  2. server {
  3. listen 80; # 默认监听80端口
  4. server_name yx.test3.service.cn; ## yx 这个表示配置的域名访问
  5. charset utf-8;
  6. #access_log logs/host.access.log main;
  7. error_page 405 = $uri;
  8. location / {
  9. root html/test;
  10. index index.html index.html;
  11. }
  12. location /test/ {
  13. proxy_redirect off;
  14. proxy_set_header Host $host;
  15. proxy_set_header X-Real-IP $remote_addr;
  16. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  17. client_max_body_size 55m;
  18. proxy_read_timeout 120;
  19. proxy_pass http://test3; ## yx 这个与 nginx.config 的upstream配合使用
  20. }
  21. location /test_res {
  22. expires 3d; ## 静态资源缓存时间
  23. alias /data2/test2 ;## 因为这里是和test2共用的,所以就直接使用即可,其他的直接修改即可 。动静分离
  24. autoindex on;
  25. }
  26. #error_page 404 /404.html;
  27. error_page 500 502 503 504 /50x.html;
  28. location = /50x.html {
  29. root html;
  30. }
  31. }
  32. ##配置nginx 并且引入test3.conf
  33. vim nginx.conf
  34. upstream test3{
  35. server 192.168.15.6:6099;
  36. }
  37. include test3.conf;
  38. ## 重启nginx
  39. ## nginx 平滑重启
  40. /usr/local/nginx/sbin/nginx -s reload

通知运维将我们配置的域名统一
yx.test3.service.cn 配置进入dns 即可。
如果本地想要看效果,直接配置hosts 也可以

ip yx.test3.service.cn
就可以直接访问了。

发表评论

表情:
评论列表 (有 0 条评论,156人围观)

还没有评论,来说两句吧...

相关阅读

    相关 OpenStack 部署实战

    OpenStack 部署运维实战 本文为您介绍了网易公司基于 OpenStack 开发的一套云计算管理平台,以及在开发、运营、维护过程中遇到的问题和经验分享。网易作为大型

    相关 服务器基础指南

    \服务器运维基础指南 作为一个开发人员,对于服务器的操作不可避免。最常用的操作就是部署应用到服务器,及在生产,测试环境通过查看日志排查问题。 一般服务器都是linux操作系