Nginx配置

各版本下载地址:

http://nginx.org/en/download.html

http://nginx.org/download/

中文参考网站(下载、安装、模块配置等):

http://www.nginx.cn/doc/

http://www.nginx.cn/install

https://www.cnblogs.com/siqi/p/3572695.html

https://www.cnblogs.com/lixuwu/p/6567793.html

Ubuntu普通用户无法启动Nginx问题:

非root用户无法启动低于1024端口号的服务,可使用root启动,或将nginx启动端口改为>1024

另:没配置nginx命令到环境变量的情况下,即使使用root,也要到nginx安装目录(这里是usr/local/nginx),使用sudo ./nginx来启动!这样可以正确识别nginx可执行文件,并加载默认配置文件,不能在任意目录使用sudo nginx!

https://blog.csdn.net/frankcreen/article/details/77460374

https://blog.csdn.net/runsnail2018/article/details/81185138

Ubuntu上Nginx安装问题:各种依赖(pcre不要用pcre2,openssl用1.0.1不要用1.1.1等)要使用合适版本,不要搞错安装路径,使用sudo提升到root权限

https://blog.csdn.net/qq_29461259/article/details/52609775

注意:nginx安装是需要依赖pcre,zlib和openssl的,源码安装完后三者后安装nginx,如果不按下面配置选项直接指定三者的源码路径而只以默认方式安装nginx,发现启动报错,缺乏依赖库,所以这里安装nginx直接指定三者的源码路径(自己下载解压的三者源码,自定义的路径),才安装,启动成功:

./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/home/baigang/softwares/pcre-8.39 \
--with-zlib=/home/baigang/softwares/zlib-1.2.11 \
--with-openssl=/home/baigang/softwares/openssl-1.0.1t

make
make install

注意这里的安装指定了nginx配置文件是/usr/local/nginx/nginx.conf,而不是conf/目录里那个!查看配置文件的命令:

检测配置文件  

/usr/local/nginx/nginx -t

baigang@baigang-virtual-machine:/usr/local/nginx$ sudo /usr/local/nginx/nginx -t
[sudo] password for baigang:
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful

以特定配置文件启动:

启动nginx

 /usr/local/nginx/nginx #不指定配置文件地址

/usr/local/nginx/nginx -c /usr/local/nginx/nginx.conf #指定配置文件地址

 

成功安装后的nginx目录在这里指定的/usr/local/nginx,目录结构如下:

baigang@baigang-virtual-machine:~/softwares/nginx-1.14.1$ cd /usr/local/nginx
baigang@baigang-virtual-machine:/usr/local/nginx$ ll
total 8392
drwxr-xr-x 6 root root 4096 12月 1 08:55 ./
drwxr-xr-x 13 root root 4096 12月 1 08:36 ../
drwxr-xr-x 2 root root 4096 12月 1 08:36 conf/
-rw-r--r-- 1 root root 1077 12月 1 08:55 fastcgi.conf
-rw-r--r-- 1 root root 1077 12月 1 08:55 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 12月 1 08:55 fastcgi_params
-rw-r--r-- 1 root root 1007 12月 1 08:55 fastcgi_params.default
drwxr-xr-x 2 root root 4096 12月 1 08:36 html/
-rw-r--r-- 1 root root 2837 12月 1 08:55 koi-utf
-rw-r--r-- 1 root root 2223 12月 1 08:55 koi-win
drwxr-xr-x 2 root root 4096 12月 1 08:36 logs/
-rw-r--r-- 1 root root 5170 12月 1 08:55 mime.types
-rw-r--r-- 1 root root 5170 12月 1 08:55 mime.types.default
-rwxr-xr-x 1 root root 8497480 12月 1 08:55 nginx*
-rw-r--r-- 1 root root 2656 12月 1 08:55 nginx.conf
-rw-r--r-- 1 root root 2656 12月 1 08:55 nginx.conf.default
drwxr-xr-x 2 root root 4096 12月 1 08:36 sbin/
-rw-r--r-- 1 root root 636 12月 1 08:55 scgi_params
-rw-r--r-- 1 root root 636 12月 1 08:55 scgi_params.default
-rw-r--r-- 1 root root 664 12月 1 08:55 uwsgi_params
-rw-r--r-- 1 root root 664 12月 1 08:55 uwsgi_params.default
-rw-r--r-- 1 root root 3610 12月 1 08:55 win-utf

错误安装的目录结构与此不同,少很多东西。

正常安装后sudo ./nginx可以正常启动,浏览器访问local默认80端口可看到nginx欢迎页面。

 

Nginx在rhel7/centos上的安装:

https://www.cnblogs.com/wyd168/p/6636529.html

rhel7上默认安装软件,软件命令一般被安装在/usr/local/bin目录(PATH路径),lib库相关一般在/usr/local/lib目录,库头文件一般在/usr/local/include目录

ubuntu上默认安装软件,软件命令一般在/usr/bin目录(PATH路径),lib库一般在/usr/lib目录,头文件一般在/usr/include目录

有些软件、库等安装需要添加软件命令、头文件位置的软连接到PATH路径,并在ld.so.conf中添加lib位置,刷新配置

rhel7上按上面安装:

安装到了/usrl/local/nginx,是没有问题的。nginx命令在其中的sbin目录,配置在其中的conf目录。使用./nginx就能用root启动默认80端口的nginx,如果出现:

[root@localhost sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

端口冲突是因为此前安装了apache(httpd服务),默认80端口启动,停止apache,nginx即启动成功!

[root@localhost sbin]# systemctl stop httpd.service
[root@localhost sbin]# ./nginx &
[1] 46747
[root@localhost sbin]# ps aux|grep nginx
root 46748 0.0 0.0 20760 576 ? Ss 04:47 0:00 nginx: master process ./nginx
nobody 46749 0.0 0.0 23240 1328 ? S 04:47 0:00 nginx: worker process
root 46759 0.0 0.0 112640 980 pts/0 S+ 04:47 0:00 grep --color=auto nginx
[1]+ Done ./nginx

 

如果要禁止httpd服务开机启动,需要使用systemctl disable httpd.service,实际是删除到开机启动服务目录的的链接,详见rhel7开启启动服务的一篇。

 

Nginx配置负载均衡:

修改了nginx.conf后可以使用sudo ./nginx -s reload在不重启nginx的情况下重新加载配置!

Nginx反向代理和负载均衡:

http://www.cnblogs.com/wang-meng/p/5861174.html

https://www.cnblogs.com/youzhibing/p/7327342.html

https://blog.csdn.net/liboyang71/article/details/77371595

https://blog.csdn.net/daybreak1209/article/details/51549031

http://www.cnblogs.com/edisonchou/p/4126742.html

https://blog.csdn.net/u012373815/article/details/54911332

http://blog.51cto.com/13178102/2063271

https://blog.csdn.net/itkingone/article/details/80365212

https://blog.csdn.net/qq_28602957/article/details/61615876

https://www.cnblogs.com/microtiger/p/7623858.html

高可用负载均衡策略:
https://blog.csdn.net/hxehuang/article/details/52576293

KeepAlived+Nginx:

https://blog.csdn.net/l1028386804/article/details/72801492

https://blog.csdn.net/xyang81/article/details/52556886

https://blog.csdn.net/e421083458/article/details/30092795

https://blog.csdn.net/yelllowcong/article/details/78764780

https://blog.csdn.net/lijian12388806/article/details/51882333

https://blog.csdn.net/l192168134/article/details/51801483 

Nginx集群:

https://blog.csdn.net/e421083458/article/details/30086413

Nginx+Tomcat:

https://blog.csdn.net/zht666/article/details/38515147

Nginx配置proxy_pass错误导致访问Tomcat报错:

proxy_pass的主机名不允许有下划线,否则可以转发,但转发的主页为空页面,且Tomcat服务端日志报错:

06-Dec-2018 08:21:08.410 INFO [http-nio-8080-exec-2] org.apache.coyote.AbstractProcessor.parseHost The host [tomcat_server] is not valid
Note: further occurrences of request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: The character [_] is never valid in a domain name.
at org.apache.tomcat.util.http.parser.HttpParser$DomainParseState.next(HttpParser.java:946)
at org.apache.tomcat.util.http.parser.HttpParser.readHostDomainName(HttpParser.java:842)
at org.apache.tomcat.util.http.parser.Host.parse(Host.java:66)
at org.apache.tomcat.util.http.parser.Host.parse(Host.java:40)
at org.apache.coyote.AbstractProcessor.parseHost(AbstractProcessor.java:223)
at org.apache.coyote.http11.AbstractHttp11Processor.prepareRequest(AbstractHttp11Processor.java:1542)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1127)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

 

安装Nginx所需环境相关:

源码安装zlib和openssl,解决无法找到相关库问题:一定要源码安装,之后配置链接库位置,尽量到官网选择新版本,稳定版本,openssl不要选择fips版本!!

https://www.cnblogs.com/felixzh/p/7084675.html

https://jingyan.baidu.com/article/c74d6000cf991d0f6a595de6.html

安装openssl无法替换老版本问题:

https://www.cnblogs.com/kyoung/p/6801143.html

https://my.oschina.net/liuguangqiang/blog/2243639

 

安装Keepalived:需要先安装openssl和openssl-devel

安装Keepalived缺少openssl相关lib或MD5相关lib问题:缺少openssl-devel也就是libssl-dev

解决:慎用!!经实验,Ubuntu系统安装libssl-dev,接受降级方案(比当前系统版本低的相关依赖)后,会导致系统一些重要软件被卸载,系统崩溃,无法再使用!!

https://blog.csdn.net/guyongqiangx/article/details/73574851

https://blog.csdn.net/xalijianjun/article/details/75577084

降级方案+附带apt相关命令的:

http://www.cnblogs.com/liushui-sky/p/9304495.html

 

安装测试负载均衡的相关环境和软件相关:

Ubuntu卸载软件:

https://blog.csdn.net/dzjian_/article/details/79768813

https://blog.csdn.net/wsygdxg1989/article/details/79138144

/etc/profile和~/.bashrc配置环境变量的区别:

https://www.cnblogs.com/cwp-bg/p/8257843.html

https://www.jianshu.com/p/6e503a8177ea

https://blog.csdn.net/jirryzhang/article/details/70833544

Linux安装JDK:

https://www.cnblogs.com/yuanbo123/p/5819564.html

https://www.cnblogs.com/lamp01/p/8932740.html

http://www.cnblogs.com/zs-notes/p/8535275.html

https://www.cnblogs.com/zhoading/p/8042729.html

Linux安装Tomcat:

https://blog.csdn.net/a_18397219871/article/details/79466392

https://blog.csdn.net/lcyaiym/article/details/76696192

https://www.cnblogs.com/xdp-gacl/p/4097608.html

注意:Tomcat 8.5.x版本有文件权限问题,无法在Ubuntu以任何用户正常启动!!目前需要使用Tomcat8.0.x.

Ubuntu普通用户安装Tomcat的权限问题:

关键不在于软件在什么目录,软件属于哪个用户,而要看普通用户(一般也和root不同组,属于other,所以要看文件的最后一部分的读写执行权限)对该软件的每个文件有什么权限,每个子目录有什么权限,比如下面涉及的对可执行文件的可执行权限,对配置文件的读权限,对logs等目录则要有写权限,因为要产生新的日志文件

baigang@baigang-virtual-machine:~$ sudo tar -zxvf Downloads/apache-tomcat-8.0.53.tar.gz -C /usr/local

创建符号链接:

baigang@baigang-virtual-machine:/usr/local$ sudo ln -s apache-tomcat-8.0.53/ tomcat8

对conf/中配置文件没有读权限:

baigang@baigang-virtual-machine:/usr/local/tomcat8/bin$ ./catalina.sh run
Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/local/jdk1.8/jre
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Nov 27, 2018 11:26:36 AM org.apache.catalina.startup.Catalina load
WARNING: Unable to load server configuration from [/usr/local/apache-tomcat-8.0.53/conf/server.xml]
Nov 27, 2018 11:26:36 AM org.apache.catalina.startup.Catalina load
WARNING: Permissions incorrect, read permission is not allowed on the file.
Nov 27, 2018 11:26:36 AM org.apache.catalina.startup.Catalina start
SEVERE: Cannot start server. Server instance is not configured.

baigang@baigang-virtual-machine:/usr/local/tomcat8$ cd conf
baigang@baigang-virtual-machine:/usr/local/tomcat8/conf$ ll
total 224
drwxr-xr-x 2 root root   4096 6月  29 22:44 ./
drwxr-xr-x 9 root root   4096 11月 27 11:24 ../
-rw------- 1 root root  13852 6月  29 22:44 catalina.policy
-rw------- 1 root root   7499 6月  29 22:44 catalina.properties
-rw------- 1 root root   1577 6月  29 22:44 context.xml
-rw------- 1 root root   3387 6月  29 22:44 logging.properties
-rw------- 1 root root   6458 6月  29 22:44 server.xml
-rw------- 1 root root   2164 6月  29 22:44 tomcat-users.xml
-rw------- 1 root root   2634 6月  29 22:44 tomcat-users.xsd
-rw------- 1 root root 169566 6月  29 22:44 web.xml
baigang@baigang-virtual-machine:/usr/local/tomcat8/conf$ chmod a+r server.xml
chmod: changing permissions of 'server.xml': Operation not permitted
baigang@baigang-virtual-machine:/usr/local/tomcat8/conf$ sudo chmod a+r server.xml
baigang@baigang-virtual-machine:/usr/local/tomcat8/conf$ ll
total 224
drwxr-xr-x 2 root root   4096 6月  29 22:44 ./
drwxr-xr-x 9 root root   4096 11月 27 11:24 ../
-rw------- 1 root root  13852 6月  29 22:44 catalina.policy
-rw------- 1 root root   7499 6月  29 22:44 catalina.properties
-rw------- 1 root root   1577 6月  29 22:44 context.xml
-rw------- 1 root root   3387 6月  29 22:44 logging.properties
-rw-r--r-- 1 root root   6458 6月  29 22:44 server.xml
-rw------- 1 root root   2164 6月  29 22:44 tomcat-users.xml
-rw------- 1 root root   2634 6月  29 22:44 tomcat-users.xsd
-rw------- 1 root root 169566 6月  29 22:44 web.xml

 

对所有配置文件针对所有用户添加读权限:


baigang@baigang-virtual-machine:/usr/local/tomcat8/conf$ sudo chmod a+r ./*
baigang@baigang-virtual-machine:/usr/local/tomcat8/conf$ ll
total 224
drwxr-xr-x 2 root root   4096 6月  29 22:44 ./
drwxr-xr-x 9 root root   4096 11月 27 11:24 ../
-rw-r--r-- 1 root root  13852 6月  29 22:44 catalina.policy
-rw-r--r-- 1 root root   7499 6月  29 22:44 catalina.properties
-rw-r--r-- 1 root root   1577 6月  29 22:44 context.xml
-rw-r--r-- 1 root root   3387 6月  29 22:44 logging.properties
-rw-r--r-- 1 root root   6458 6月  29 22:44 server.xml
-rw-r--r-- 1 root root   2164 6月  29 22:44 tomcat-users.xml
-rw-r--r-- 1 root root   2634 6月  29 22:44 tomcat-users.xsd
-rw-r--r-- 1 root root 169566 6月  29 22:44 web.xml

对logs/目录没有写权限:

baigang@baigang-virtual-machine:/usr/local/tomcat8/bin$ ./catalina.sh run
Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/local/jdk1.8/jre
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
java.util.logging.ErrorManager: 4
java.io.FileNotFoundException: /usr/local/tomcat8/logs/catalina.2018-11-27.log (Permission denied)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)

baigang@baigang-virtual-machine:/usr/local/tomcat8$ chmod a+w logs/ webapps/ temp/ work/
chmod: changing permissions of 'logs/': Operation not permitted
chmod: changing permissions of 'webapps/': Operation not permitted
chmod: changing permissions of 'temp/': Operation not permitted
chmod: changing permissions of 'work/': Operation not permitted

 

对logs/等目录添加所有用户的写权限:


baigang@baigang-virtual-machine:/usr/local/tomcat8$ sudo chmod a+w logs/ webapps/ temp/ work/
baigang@baigang-virtual-machine:/usr/local/tomcat8$ ll
total 120
drwxr-xr-x  9 root root  4096 11月 27 11:24 ./
drwxr-xr-x 14 root root  4096 11月 27 11:25 ../
drwxr-xr-x  2 root root  4096 11月 27 11:24 bin/
drwxr-xr-x  2 root root  4096 6月  29 22:44 conf/
drwxr-xr-x  2 root root  4096 11月 27 11:24 lib/
-rw-r--r--  1 root root 57011 6月  29 22:44 LICENSE
drwxrwxrwx  2 root root  4096 6月  29 22:42 logs/
-rw-r--r--  1 root root  1446 6月  29 22:44 NOTICE
-rw-r--r--  1 root root  6794 6月  29 22:44 RELEASE-NOTES
-rw-r--r--  1 root root 16258 6月  29 22:44 RUNNING.txt
drwxrwxrwx  2 root root  4096 11月 27 11:24 temp/
drwxrwxrwx  7 root root  4096 6月  29 22:44 webapps/
drwxrwxrwx  2 root root  4096 6月  29 22:42 work/

启动成功:

 

baigang@baigang-virtual-machine:/usr/local/tomcat8/bin$ ./catalina.sh run &
[1] 5157
baigang@baigang-virtual-machine:/usr/local/tomcat8/bin$ Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/local/jdk1.8/jre
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
27-Nov-2018 11:35:15.776 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.53
27-Nov-2018 11:35:15.779 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 29 2018 14:42:45 UTC
27-Nov-2018 11:35:15.779 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.53.0
27-Nov-2018 11:35:15.779 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
27-Nov-2018 11:35:15.780 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.15.0-29-generic
27-Nov-2018 11:35:15.780 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
27-Nov-2018 11:35:15.780 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/local/jdk1.8.0_191/jre
27-Nov-2018 11:35:15.780 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_191-b12
27-Nov-2018 11:35:15.780 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
27-Nov-2018 11:35:15.781 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/apache-tomcat-8.0.53
27-Nov-2018 11:35:15.781 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/apache-tomcat-8.0.53
27-Nov-2018 11:35:15.781 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.properties
27-Nov-2018 11:35:15.782 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
27-Nov-2018 11:35:15.782 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
27-Nov-2018 11:35:15.782 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
27-Nov-2018 11:35:15.782 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
27-Nov-2018 11:35:15.782 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat8
27-Nov-2018 11:35:15.783 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat8
27-Nov-2018 11:35:15.783 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat8/temp
27-Nov-2018 11:35:15.783 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
27-Nov-2018 11:35:15.970 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
27-Nov-2018 11:35:15.993 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
27-Nov-2018 11:35:16.006 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
27-Nov-2018 11:35:16.009 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
27-Nov-2018 11:35:16.016 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 777 ms
27-Nov-2018 11:35:16.062 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
27-Nov-2018 11:35:16.063 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.53
27-Nov-2018 11:35:16.070 SEVERE [Catalina-startStop-1] org.apache.catalina.startup.HostConfig.beforeStart Unable to create directory for deployment: /usr/local/apache-tomcat-8.0.53/conf/Catalina/localhost
27-Nov-2018 11:35:16.080 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53/webapps/examples
27-Nov-2018 11:35:16.872 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53/webapps/examples has finished in 791 ms
27-Nov-2018 11:35:16.873 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53/webapps/docs
27-Nov-2018 11:35:16.911 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53/webapps/docs has finished in 37 ms
27-Nov-2018 11:35:16.919 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53/webapps/manager
27-Nov-2018 11:35:16.970 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53/webapps/manager has finished in 51 ms
27-Nov-2018 11:35:16.970 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53/webapps/host-manager
27-Nov-2018 11:35:17.021 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53/webapps/host-manager has finished in 51 ms
27-Nov-2018 11:35:17.022 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53/webapps/ROOT
27-Nov-2018 11:35:17.071 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53/webapps/ROOT has finished in 48 ms
27-Nov-2018 11:35:17.076 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
27-Nov-2018 11:35:17.088 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
27-Nov-2018 11:35:17.099 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1082 ms

baigang@baigang-virtual-machine:/usr/local/tomcat8/bin$
baigang@baigang-virtual-machine:/usr/local/tomcat8/bin$
baigang@baigang-virtual-machine:/usr/local/tomcat8/bin$ ps -ef|grep java
baigang    5157   4378 34 11:35 pts/1    00:00:07 /usr/local/jdk1.8/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8 -Dcatalina.home=/usr/local/tomcat8 -Djava.io.tmpdir=/usr/local/tomcat8/temp org.apache.catalina.startup.Bootstrap start
baigang    5227   4378  0 11:35 pts/1    00:00:00 grep --color=auto java

拷贝一份做第二个:

 

baigang@baigang-virtual-machine:/usr/local$ sudo cp -R apache-tomcat-8.0.53/ apache-tomcat-8.0.53-8081

baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081$ sudo chmod a+w logs/ temp/ webapps/ work/

 

但此前启动过的Tomcat遗留了日志文件,拥有者是root,造成普通用户没有文件写权限,无权继续写入这些存在的日志,启动报错:

 

baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081$ cd logs
baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/logs$ ll
total 32
drwxrwxrwx 2 root root  4096 11月 27 14:59 ./
drwxr-xr-x 9 root root  4096 11月 27 14:59 ../
-rw-r--r-- 1 root root 14010 11月 27 14:59 catalina.2018-11-27.log
-rw-r--r-- 1 root root     0 11月 27 14:59 host-manager.2018-11-27.log
-rw-r--r-- 1 root root  1194 11月 27 14:59 localhost.2018-11-27.log
-rw-r--r-- 1 root root  3208 11月 27 14:59 localhost_access_log.2018-11-27.txt
-rw-r--r-- 1 root root     0 11月 27 14:59 manager.2018-11-27.log

 

删除这些冗余日志:


baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/logs$ rm -f *
baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/logs$ ll
total 8
drwxrwxrwx 2 root root 4096 11月 27 15:01 ./
drwxr-xr-x 9 root root 4096 11月 27 14:59 ../

改端口避免冲突:

 

baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/conf$ sudo vim server.xml
baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/conf$ cd ../bin

 

启动第二个Tomcat成功,端口8081:


baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/bin$ ./catalina.sh run &
[2] 7321
baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/bin$ Using CATALINA_BASE:   /usr/local/apache-tomcat-8.0.53-8081
Using CATALINA_HOME:   /usr/local/apache-tomcat-8.0.53-8081
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-8.0.53-8081/temp
Using JRE_HOME:        /usr/local/jdk1.8/jre
Using CLASSPATH:       /usr/local/apache-tomcat-8.0.53-8081/bin/bootstrap.jar:/usr/local/apache-tomcat-8.0.53-8081/bin/tomcat-juli.jar
27-Nov-2018 15:03:50.686 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.53
27-Nov-2018 15:03:50.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 29 2018 14:42:45 UTC
27-Nov-2018 15:03:50.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.53.0
27-Nov-2018 15:03:50.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
27-Nov-2018 15:03:50.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.15.0-29-generic
27-Nov-2018 15:03:50.690 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
27-Nov-2018 15:03:50.690 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/local/jdk1.8.0_191/jre
27-Nov-2018 15:03:50.690 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_191-b12
27-Nov-2018 15:03:50.690 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
27-Nov-2018 15:03:50.691 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/apache-tomcat-8.0.53-8081
27-Nov-2018 15:03:50.691 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/apache-tomcat-8.0.53-8081
27-Nov-2018 15:03:50.692 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.0.53-8081/conf/logging.properties
27-Nov-2018 15:03:50.692 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
27-Nov-2018 15:03:50.692 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
27-Nov-2018 15:03:50.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
27-Nov-2018 15:03:50.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
27-Nov-2018 15:03:50.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/apache-tomcat-8.0.53-8081
27-Nov-2018 15:03:50.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/apache-tomcat-8.0.53-8081
27-Nov-2018 15:03:50.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/apache-tomcat-8.0.53-8081/temp
27-Nov-2018 15:03:50.694 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
27-Nov-2018 15:03:50.886 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8081"]
27-Nov-2018 15:03:50.898 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
27-Nov-2018 15:03:50.903 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8010"]
27-Nov-2018 15:03:50.930 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
27-Nov-2018 15:03:50.931 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 773 ms
27-Nov-2018 15:03:50.973 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
27-Nov-2018 15:03:50.974 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.53
27-Nov-2018 15:03:50.979 SEVERE [Catalina-startStop-1] org.apache.catalina.startup.HostConfig.beforeStart Unable to create directory for deployment: /usr/local/apache-tomcat-8.0.53-8081/conf/Catalina/localhost
27-Nov-2018 15:03:50.984 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/examples
27-Nov-2018 15:03:51.734 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/examples is unusable.
27-Nov-2018 15:03:51.743 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/examples has finished in 758 ms
27-Nov-2018 15:03:51.744 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/docs
27-Nov-2018 15:03:51.793 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/docs is unusable.
27-Nov-2018 15:03:51.794 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/docs has finished in 50 ms
27-Nov-2018 15:03:51.795 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/manager
27-Nov-2018 15:03:51.866 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/manager is unusable.
27-Nov-2018 15:03:51.867 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/manager has finished in 72 ms
27-Nov-2018 15:03:51.868 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/host-manager
27-Nov-2018 15:03:51.904 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/host-manager is unusable.
27-Nov-2018 15:03:51.905 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/host-manager has finished in 37 ms
27-Nov-2018 15:03:51.906 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/ROOT
27-Nov-2018 15:03:51.938 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/ROOT is unusable.
27-Nov-2018 15:03:51.939 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/ROOT has finished in 33 ms
27-Nov-2018 15:03:51.944 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8081"]
27-Nov-2018 15:03:51.986 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8010"]
27-Nov-2018 15:03:51.991 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1060 ms

baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/bin$
baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/bin$ ps aux|grep java
baigang    5157  0.1  6.9 4058096 141152 pts/1  Sl   11:35   0:20 /usr/local/jdk1.8/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8 -Dcatalina.home=/usr/local/tomcat8 -Djava.io.tmpdir=/usr/local/tomcat8/temp org.apache.catalina.startup.Bootstrap start
baigang    7321 18.8  5.4 4056048 109260 pts/1  Sl   15:03   0:05 /usr/local/jdk1.8/jre/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.0.53-8081/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/apache-tomcat-8.0.53-8081/bin/bootstrap.jar:/usr/local/apache-tomcat-8.0.53-8081/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-8.0.53-8081 -Dcatalina.home=/usr/local/apache-tomcat-8.0.53-8081 -Djava.io.tmpdir=/usr/local/apache-tomcat-8.0.53-8081/temp org.apache.catalina.startup.Bootstrap start
baigang    7385  0.0  0.0  21292  1020 pts/1    S+   15:04   0:00 grep --color=auto java
baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/bin$ kill -9 7321
baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/bin$ cd ../../
[2]+  Killed                  ./catalina.sh run  (wd: /usr/local/apache-tomcat-8.0.53-8081/bin)
(wd now: /usr/local)

创建第二份软件目录的软连接,注意此前要拷贝的是真实软件目录,而不要拷贝软连接,拷贝的软连接只会连接到同一个真实软件目录:

baigang@baigang-virtual-machine:/usr/local$ sudo ln -s apache-tomcat-8.0.53-8081/ tomcat8_1

可以看到产生了属于普通用户的日志文件:

 

baigang@baigang-virtual-machine:/usr/local/tomcat8_1$ cd logs
baigang@baigang-virtual-machine:/usr/local/tomcat8_1/logs$ ll
total 40
drwxrwxrwx 2 root    root     4096 11月 27 15:02 ./
drwxr-xr-x 9 root    root     4096 11月 27 14:59 ../
-rw-rw-r-- 1 baigang baigang 24695 11月 27 15:03 catalina.2018-11-27.log
-rw-rw-r-- 1 baigang baigang     0 11月 27 15:02 host-manager.2018-11-27.log
-rw-rw-r-- 1 baigang baigang  1194 11月 27 15:03 localhost.2018-11-27.log
-rw-rw-r-- 1 baigang baigang     0 11月 27 15:02 localhost_access_log.2018-11-27.txt
-rw-rw-r-- 1 baigang baigang     0 11月 27 15:02 manager.2018-11-27.log

用软连接目录启动成功:

 

baigang@baigang-virtual-machine:/usr/local/tomcat8_1$ cd bin
baigang@baigang-virtual-machine:/usr/local/tomcat8_1/bin$ ./catalina.sh run &
[2] 7476
baigang@baigang-virtual-machine:/usr/local/tomcat8_1/bin$ Using CATALINA_BASE:   /usr/local/tomcat8_1
Using CATALINA_HOME:   /usr/local/tomcat8_1
Using CATALINA_TMPDIR: /usr/local/tomcat8_1/temp
Using JRE_HOME:        /usr/local/jdk1.8/jre
Using CLASSPATH:       /usr/local/tomcat8_1/bin/bootstrap.jar:/usr/local/tomcat8_1/bin/tomcat-juli.jar
27-Nov-2018 15:08:07.726 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.53
27-Nov-2018 15:08:07.729 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 29 2018 14:42:45 UTC
27-Nov-2018 15:08:07.730 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.53.0
27-Nov-2018 15:08:07.730 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
27-Nov-2018 15:08:07.730 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.15.0-29-generic
27-Nov-2018 15:08:07.730 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
27-Nov-2018 15:08:07.730 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/local/jdk1.8.0_191/jre
27-Nov-2018 15:08:07.730 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_191-b12
27-Nov-2018 15:08:07.731 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
27-Nov-2018 15:08:07.731 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/apache-tomcat-8.0.53-8081
27-Nov-2018 15:08:07.731 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/apache-tomcat-8.0.53-8081
27-Nov-2018 15:08:07.731 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat8_1/conf/logging.properties
27-Nov-2018 15:08:07.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
27-Nov-2018 15:08:07.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
27-Nov-2018 15:08:07.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
27-Nov-2018 15:08:07.732 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
27-Nov-2018 15:08:07.733 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat8_1
27-Nov-2018 15:08:07.733 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat8_1
27-Nov-2018 15:08:07.733 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat8_1/temp
27-Nov-2018 15:08:07.733 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
27-Nov-2018 15:08:07.923 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8081"]
27-Nov-2018 15:08:07.946 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
27-Nov-2018 15:08:07.951 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8010"]
27-Nov-2018 15:08:07.964 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
27-Nov-2018 15:08:07.965 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 764 ms
27-Nov-2018 15:08:08.014 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
27-Nov-2018 15:08:08.015 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.53
27-Nov-2018 15:08:08.023 SEVERE [Catalina-startStop-1] org.apache.catalina.startup.HostConfig.beforeStart Unable to create directory for deployment: /usr/local/apache-tomcat-8.0.53-8081/conf/Catalina/localhost
27-Nov-2018 15:08:08.030 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/examples
27-Nov-2018 15:08:08.811 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/examples is unusable.
27-Nov-2018 15:08:08.822 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/examples has finished in 791 ms
27-Nov-2018 15:08:08.822 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/docs
27-Nov-2018 15:08:08.865 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/docs is unusable.
27-Nov-2018 15:08:08.866 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/docs has finished in 44 ms
27-Nov-2018 15:08:08.867 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/manager
27-Nov-2018 15:08:08.922 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/manager is unusable.
27-Nov-2018 15:08:08.923 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/manager has finished in 56 ms
27-Nov-2018 15:08:08.924 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/host-manager
27-Nov-2018 15:08:08.967 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/host-manager is unusable.
27-Nov-2018 15:08:08.969 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/host-manager has finished in 44 ms
27-Nov-2018 15:08:08.969 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/ROOT
27-Nov-2018 15:08:08.999 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/ROOT is unusable.
27-Nov-2018 15:08:09.002 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/apache-tomcat-8.0.53-8081/webapps/ROOT has finished in 33 ms
27-Nov-2018 15:08:09.015 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8081"]
27-Nov-2018 15:08:09.041 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8010"]
27-Nov-2018 15:08:09.060 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1094 ms

 

运行中的两个Tomcat:


baigang@baigang-virtual-machine:/usr/local/tomcat8_1/bin$
baigang@baigang-virtual-machine:/usr/local/tomcat8_1/bin$
baigang@baigang-virtual-machine:/usr/local/tomcat8_1/bin$ ps aux|grep java
baigang    5157  0.1  6.9 4058096 141152 pts/1  Sl   11:35   0:20 /usr/local/jdk1.8/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8 -Dcatalina.home=/usr/local/tomcat8 -Djava.io.tmpdir=/usr/local/tomcat8/temp org.apache.catalina.startup.Bootstrap start
baigang    7476 26.2  5.3 4056048 107596 pts/1  Sl   15:08   0:05 /usr/local/jdk1.8/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8_1/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat8_1/bin/bootstrap.jar:/usr/local/tomcat8_1/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8_1 -Dcatalina.home=/usr/local/tomcat8_1 -Djava.io.tmpdir=/usr/local/tomcat8_1/temp org.apache.catalina.startup.Bootstrap start
baigang    7543  0.0  0.0  21292   896 pts/1    S+   15:08   0:00 grep --color=auto java

 

修改的JSP主页访问失败问题(404):

Tomcat日志实时提示错误:

baigang@baigang-virtual-machine:/usr/local/apache-tomcat-8.0.53-8081/bin$ 06-Dec-2018 08:35:55.366 WARNING [http-nio-8081-exec-1] org.apache.jasper.compiler.Compiler.removeGeneratedClassFiles Failed to delete generated class file [/usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.class]
06-Dec-2018 08:35:55.367 WARNING [http-nio-8081-exec-1] org.apache.jasper.compiler.Compiler.removeGeneratedFiles Failed to delete generated Java file [/usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java]
06-Dec-2018 08:35:55.728 WARNING [http-nio-8081-exec-1] org.apache.jasper.compiler.Compiler.generateJava Failed to delete generated Java file [/usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java]
06-Dec-2018 08:36:18.674 WARNING [http-nio-8081-exec-3] org.apache.jasper.compiler.Compiler.removeGeneratedClassFiles Failed to delete generated class file [/usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.class]
06-Dec-2018 08:36:18.675 WARNING [http-nio-8081-exec-3] org.apache.jasper.compiler.Compiler.removeGeneratedFiles Failed to delete generated Java file [/usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java]
06-Dec-2018 08:36:18.698 WARNING [http-nio-8081-exec-3] org.apache.jasper.compiler.Compiler.generateJava Failed to delete generated Java file [/usr/local/apache-tomcat-8.0.53-8081/work/Catalina/localhost/ROOT/org/apache/jsp/index_jsp.java]
这是新的JSP页面编译后无法删除旧编译文件进行替代,是启动用户权限问题!
这是由于此前使用root用户权限启动过Tomcat,在Tomcat的work目录产生了所有者为root的目录,这些目录对普通用户没有写入(w,创建、删除其中jsp文件)权限,所以需要完全删除这些root的目录、文件,且work目录需要有普通用户写权限,才能生效!

 

Nginx域名转发配置:

http://www.ttlsa.com/nginx/use-nginx-proxy/

https://www.cnblogs.com/Star-Haitian/p/7771677.html

https://blog.csdn.net/zzq900503/article/details/70049348

https://www.cnblogs.com/Star-Haitian/p/7771677.html

https://www.jb51.net/article/140826.htm

 

Nginx限流模块配置:

https://www.cnblogs.com/biglittleant/p/8979915.html

https://www.cnblogs.com/devinzhang/p/7735397.html

https://blog.csdn.net/qq_28710983/article/details/80923097

https://www.jianshu.com/p/f9888812e89c

https://www.jb51.net/article/140732.htm

源码原理:

https://blog.csdn.net/luoyu_/article/details/82857033

https://www.jianshu.com/p/2cf3d9609af3

 

posted @ 2018-11-06 09:57  free_wings  阅读(1325)  评论(0编辑  收藏  举报