一个 Java 小白维护一套没有文档的,代码凌乱的 Java 后台系统,遇到一些新手问题这里记录。
一、更新jar包 在更新 Java 后端程序时,需要修改一个 JAR 包里面的文件,替换里面的部分内容。
使用 jar -xvf xxx.jar
解压到当前文件夹,文件夹包含 META-INF/MANIFEST.MF 和其它要打包的文件。
替换要修改的文件后,使用 jar -cvfm xxx.jar META-INF/MANIFEST.MF xx
打包,其中 xx 表示其它要打包的文件。
MANIFEST.MF
1 2 3 4 5 6 7 8 9 10 11 Manifest-Version : 1.0 Ant-Version : Apache Ant 1.6.1 Specification-Title : DCWLW Class-Path : conn.jar commons-codec-1.3.jar commons-dbcp-1.2.2.jar comm ons-lang-2.4.jar commons-lang3-3.2.jar commons-logging-1.0.4.jar comm ons-pool-1.3.jar dom4j.jar httpclient-4.5.6.jar httpcore-4.4.11.jar j dom-1.0.jar jtds-1.2.jar log4j-1.2.14.jar ojdbc14.jar msutil.jar slf4 j-api-1.6.6.jar slf4j-log4j12-1.6.6.jar sqljdbc4.jar Created-By : xinli.zhangxlei Specification-Version : 1.0 Main-Class : com.servs.main.ServiceInit
更新: 在Linux下更简单的方法是,复制更改的文件,连同其路径,使用命令jar uf
命令进行更新。
例如:
1 jar uf WLWServ.jar com/servs/main/HandlerTest.class
二、查看数据库配置 在迁移服务后,需要修改数据库配置文件到当前使用的数据库,因此要改变其 IP 地址,为此找了好一会,最后仔细观察 log,才发现配置文件所在位置在 conn.jar 文件中,将其修改后重新打包。
db.properties
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 user =xx password =yyyyy drivers =com.microsoft.sqlserver.jdbc.SQLServerDriver url =jdbc:sqlserver://xx.xx.xxx.xx;database=DCWLW; MaxConnectionCount =60 MaxIdleCount =3 MaxWait =1000
三、防火墙 早前在搬迁一些云服务器文件时,突然发现网站无法访问,最后查清是防火墙的问题,关闭防火墙后服务恢复正常。在搬迁服务器文件过程中,唯一有过的可疑操作是打开过网络共享 ,并共享了一个文件夹(该操作没有成功,可能阿里云服务器禁止网络共享),尚未清楚该操作是否与防火墙的策略有何关联。
四、tomcat添加SSL认证 之前的网站未经过 SSL 认证,没有 HTTPS 加密,微信小程序是不支持没有 HTTPS 加密的地址的,因此需要进行 SSL 认证。因为使用的阿里云服务器,阿里云有该服务。阿里云提供免费证书,申请配置完域名后,放到 tomcat 根目录 cert 文件夹下。
证书目录:
修改 conf/server.xml 文件,配置 https 所用端口 443
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 <?xml version='1.0' encoding='utf-8'?> <Server port ="8005" shutdown ="SHUTDOWN" > <Listener className ="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className ="org.apache.catalina.core.AprLifecycleListener" SSLEngine ="on" /> <Listener className ="org.apache.catalina.core.JasperListener" /> <Listener className ="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className ="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className ="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources > <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 > <Service name ="Catalina" > <Connector port ="80" protocol ="HTTP/1.1" maxHttpHeaderSize ="8192" maxThreads ="150" minSpareThreads ="25" maxSpareThreads ="75" enableLookups ="false" acceptCount ="100" connectionTimeout ="20000" disableUploadTimeout ="true" redirectPort ="8443" URIEncoding ="UTF-8" /> <Connector port ="8443" protocol ="org.apache.coyote.http11.Http11Protocol" maxThreads ="150" SSLEnabled ="true" scheme ="https" secure ="true" clientAuth ="false" sslProtocol ="TLS" /> <Connector port ="443" protocol ="HTTP/1.1" SSLEnabled ="true" scheme ="https" secure ="true" keystoreFile ="D:\apache-tomcat-7.0.65\cert\5568913_liyunlong.xdt-iot.com.pfx" keystoreType ="PKCS12" keystorePass ="r0ftyhrF" clientAuth ="false" SSLProtocol ="TLSv1+TLSv1.1+TLSv1.2" ciphers ="TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256" /> <Connector port ="8009" protocol ="AJP/1.3" redirectPort ="8443" /> <Engine name ="Catalina" defaultHost ="localhost" > <Realm className ="org.apache.catalina.realm.LockOutRealm" > <Realm className ="org.apache.catalina.realm.UserDatabaseRealm" resourceName ="UserDatabase" /> </Realm > <Host name ="localhost" appBase ="webapps" unpackWARs ="true" autoDeploy ="true" > <Valve className ="org.apache.catalina.valves.AccessLogValve" directory ="logs" prefix ="localhost_access_log." suffix =".txt" pattern ="%h %l %u %t " %r" %s %b" /> </Host > <Host name ="liyunlong.xdt-iot.com" appBase ="" unpackWARs ="true" autoDeploy ="true" > <Context path ="" docBase ="D:\apache-tomcat-7.0.65\webapps_xassp\DCWLW" reloadable ="true" > </Context > <Context path ="/upload" docBase ="D:\uploads" reloadable ="true" > </Context > <Context path ="/download" docBase ="D:\apache-tomcat-7.0.65\webapps_xassp\download" reloadable ="true" > </Context > <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 >
五、java程序未释放临时文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 root@lyl-linux:WLWpack$ ps -ef | grep WLWServ root 27719 1 5 14:10 ? 00:00:54 java -jar -Xms1536m -Xmx2046m -XX:PermSize=128M -XX:MaxPermSize=256M /opt/Xassp/DCServer/WLWServ.jar root 30118 28413 0 14:26 pts/2 00:00:00 grep --color=auto WLWServ root@lyl-linux:WLWpack$ ls -l /proc/27719/fd total 0 lr-x------ 1 root root 64 May 11 14:10 0 -> /dev/null l-wx------ 1 root root 64 May 11 14:10 1 -> /opt/Xassp/DCServer/DC.log lr-x------ 1 root root 64 May 11 14:10 10 -> /dev/urandom lr-x------ 1 root root 64 May 11 14:10 100 -> /usr/java/jdk1.8.0_151/jre/lib/jce.jar lrwx------ 1 root root 64 May 11 14:10 101 -> socket:[65960083] lrwx------ 1 root root 64 May 11 14:10 102 -> socket:[65958648] lrwx------ 1 root root 64 May 11 14:10 103 -> socket:[65958649] * * * lrwx------ 1 root root 64 May 11 14:11 849 -> socket:[65962399] lr-x------ 1 root root 64 May 11 14:10 85 -> /tmp/jar_cache1697996469127696081.tmp (deleted) lrwx------ 1 root root 64 May 11 14:11 850 -> socket:[65956493] lrwx------ 1 root root 64 May 11 14:11 851 -> socket:[65956497] lrwx------ 1 root root 64 May 11 14:11 852 -> socket:[65956667] lrwx------ 1 root root 64 May 11 14:11 853 -> socket:[65962423] lrwx------ 1 root root 64 May 11 14:11 855 -> socket:[65962615] lr-x------ 1 root root 64 May 11 14:10 86 -> /tmp/jar_cache7396855417572440361.tmp (deleted) lrwx------ 1 root root 64 May 11 14:11 860 -> socket:[65967045] lrwx------ 1 root root 64 May 11 14:11 861 -> socket:[65966819] lr-x------ 1 root root 64 May 11 14:10 87 -> /tmp/jar_cache5532799349897305199.tmp (deleted) lrwx------ 1 root root 64 May 11 14:20 871 -> socket:[65968386] lr-x------ 1 root root 64 May 11 14:10 88 -> /tmp/jar_cache3266479730475853680.tmp (deleted) lrwx------ 1 root root 64 May 11 14:20 880 -> socket:[65968209] lrwx------ 1 root root 64 May 11 14:20 884 -> socket:[65967056] lr-x------ 1 root root 64 May 11 14:10 89 -> /tmp/jar_cache8112640596215738372.tmp (deleted) lrwx------ 1 root root 64 May 11 14:20 894 -> socket:[65972740] lrwx------ 1 root root 64 May 11 14:20 895 -> socket:[65972730] lr-x------ 1 root root 64 May 11 14:10 9 -> /dev/random lr-x------ 1 root root 64 May 11 14:10 90 -> /tmp/jar_cache5110604533158166258.tmp (deleted) lrwx------ 1 root root 64 May 11 14:20 900 -> socket:[65972734] lr-x------ 1 root root 64 May 11 14:10 91 -> /tmp/jar_cache7000421609336413492.tmp (deleted) lrwx------ 1 root root 64 May 11 14:20 915 -> socket:[65969067] lrwx------ 1 root root 64 May 11 14:20 917 -> socket:[65966968] lr-x------ 1 root root 64 May 11 14:10 92 -> /tmp/jar_cache6363263715093382132.tmp (deleted) lrwx------ 1 root root 64 May 11 14:22 920 -> socket:[65972778] lrwx------ 1 root root 64 May 11 14:22 922 -> socket:[65972339] lrwx------ 1 root root 64 May 11 14:22 923 -> socket:[65968715] lrwx------ 1 root root 64 May 11 14:22 924 -> socket:[65967706] lr-x------ 1 root root 64 May 11 14:10 93 -> /tmp/jar_cache733013011657608974.tmp (deleted) lrwx------ 1 root root 64 May 11 14:24 931 -> socket:[65972801] lrwx------ 1 root root 64 May 11 14:24 932 -> socket:[65972824] lrwx------ 1 root root 64 May 11 14:24 933 -> socket:[65969142] lrwx------ 1 root root 64 May 11 14:25 934 -> socket:[65972838] lrwx------ 1 root root 64 May 11 14:25 935 -> socket:[65974276] lrwx------ 1 root root 64 May 11 14:25 936 -> socket:[65974298] lrwx------ 1 root root 64 May 11 14:25 937 -> socket:[65974306] lrwx------ 1 root root 64 May 11 14:25 938 -> socket:[65972881] lrwx------ 1 root root 64 May 11 14:25 939 -> socket:[65972882] lr-x------ 1 root root 64 May 11 14:10 94 -> /tmp/jar_cache4426843942519086123.tmp (deleted) lrwx------ 1 root root 64 May 11 14:25 940 -> socket:[65972885] lrwx------ 1 root root 64 May 11 14:25 941 -> socket:[65974317] lrwx------ 1 root root 64 May 11 14:25 942 -> socket:[65972914] lrwx------ 1 root root 64 May 11 14:25 943 -> socket:[65974398] lrwx------ 1 root root 64 May 11 14:25 944 -> socket:[65972940] lrwx------ 1 root root 64 May 11 14:25 945 -> socket:[65974409] lrwx------ 1 root root 64 May 11 14:25 946 -> socket:[65972959] lrwx------ 1 root root 64 May 11 14:25 947 -> socket:[65973448] lrwx------ 1 root root 64 May 11 14:25 948 -> socket:[65974430] lrwx------ 1 root root 64 May 11 14:25 949 -> socket:[65974440] lr-x------ 1 root root 64 May 11 14:10 95 -> /tmp/jar_cache6962183311593254185.tmp (deleted) lrwx------ 1 root root 64 May 11 14:25 950 -> socket:[65974476] lrwx------ 1 root root 64 May 11 14:25 951 -> socket:[65974480] lrwx------ 1 root root 64 May 11 14:25 952 -> socket:[65974506] lrwx------ 1 root root 64 May 11 14:25 953 -> socket:[65974524] lrwx------ 1 root root 64 May 11 14:25 954 -> socket:[65973053] lrwx------ 1 root root 64 May 11 14:25 955 -> socket:[65974549] lr-x------ 1 root root 64 May 11 14:10 96 -> /tmp/jar_cache3916538713653732339.tmp (deleted) lr-x------ 1 root root 64 May 11 14:10 97 -> /usr/java/jdk1.8.0_151/jre/lib/resources.jar l-wx------ 1 root root 64 May 11 14:10 98 -> /root/keep/DC_400.log lrwx------ 1 root root 64 May 11 14:10 99 -> socket:[65958644]
以上,使用ps -ef | grep WLWServ
查看WLWServ程序的进程号,然后用ls -l /proc/27719/fd
查看进程占用的文件,发现很多线程使用deleted的文件。