失败一失败二  ※ 失败三 ※

1- 确认机型:

root@iZwz:~# lsb_release -a
LSB Version: core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch
Distributor ID: Debian
Description: Debian GNU/Linux 8.8 (jessie)
Release: 8.8
Codename: jessie

2- 确保安装了 tomcat 运行所需要的 JRE :

java -version

3- 确保安装了wget 和 unzip(辅助后续安装):

apt-get update && apt-get upgrade

apt-get install unzip wget

4- 创建一个单独的系统用户来跑 tomcat (网站建议),通过以下命令:

useradd -r tomcat --shell /bin/false
shell进程是执行其它进程的进程,但在执行一个命令时,shell进程会指示内核把指定的程序作为另一个进程分开执行,并将输出写到终端。
通过命令选项,我们可以修改命令执行的行为。命令行选项可以分为短命令行选项和长命令行选项两种。短命令行选项是由字母组成,长命令行选项是由单词组成。短命令行选项在选项前使用单横杠“-”,长命令行选项前使用双横杠“--”。如果选项后面需要输入选项的参数,短命令行选项和参数之间使用空格分隔,而长命令行选项使用等号“=”连接选项和参数。
通过在命令后面添加选项“--help”、“-h”或“-?”,我们可以获得一个命令的帮助信息。 --- by 洪军不怕远征难

What does “--” (double-dash) mean? (also known as “bare double dash”) <-- 不相关的笔记 :p

5- 从网站下载 tomcat 到 /opt 目录下,和 windows 其实是一样的。

wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.41/src/apache-tomcat-8.0.41-src.tar.gz -P /opt

 6- 下载好后解压缩(到这里感觉都装好了 = =)

cd /opt
tar -zxf apache-tomcat-8.0..tar.gz

 7- 创建汤姆猫的“符号链接”(?)并设置适当的所有权

ln -s /opt/apache-tomcat-8.0. /opt/tomcat-latest
chown -hR tomcat: /opt/tomcat-latest /opt/apache-tomcat-*

弄好后在 /opt 目录下是这个情况:

 8- 创建一个系统初始化文件以便  start/restart/stop 汤姆猫:

nano /etc/systemd/system/tomcat.service

copy 下面的内容:

[Unit]
Description=Tomcat8
After=network.target [Service]
Type=forking
User=tomcat
Group=tomcat Environment=CATALINA_PID=/opt/tomcat-latest/tomcat8.pid
Environment=TOMCAT_JAVA_HOME=/usr/bin/java
Environment=CATALINA_HOME=/opt/tomcat-latest
Environment=CATALINA_BASE=/opt/tomcat-latest
Environment=CATALINA_OPTS=
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m" ExecStart=/opt/tomcat-latest/bin/startup.sh
ExecStop=/bin/kill - $MAINPID [Install]
WantedBy=multi-user.target
linux下 nano 在编辑状态下退出请按Ctrl+X,会有两种情形: 如果文件未修改,直接退出; 如果修改了文件,下面会询问是否需要保存修改。输入Y确认保存,输入N不保存,按Ctrl+C取消返回。如果输入了Y,下一步会提示输入想要保存的文件名。如果不需要修改文件名直接回车就行;若想要保存成别的名字(也就是另存为)则 ... (来自百度知道 happygrid)

 9- 最后几个命令

systemctl daemon-reload # 重载所有修改过的配置文件
systemctl restart tomcat.service # 文章里是直接 restart tomcat 但是我用了报错。。后来发现其实效果是一样的
systemctl enable tomcat

------------------------------------------------------------------------------------------------------------------------------------------------------

出点差错。。抛点 bug 才比较有真实感。

按流程走下来,在 restart 和 enable 时都抛出了下面的提示(我的主机是这样 --- 囧):

Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.

tomcat 8 will not start after initial install

按照上面解决方案做抛出这个错误信息 Error message 'sudo: unable to resolve host <USER>' 我直接到阿里云控制台改HostName就解决了。

成功输入上面的命令 restart 还是没用,于是换教程 2 。

------------------------------------------------------------------------------------------------------------------------------------------------------

先决条件:

root@xkfx:/usr/lib/jvm/java-8-oracle# ls -lsh
total 26M
4.0K drwxr-xr-x 2 root root 4.0K Jan 14 00:53 bin
4.0K -r--r--r-- 1 root root 3.2K Jan 14 00:53 COPYRIGHT
4.0K drwxr-xr-x 4 root root 4.0K Jan 14 00:53 db
4.0K drwxr-xr-x 3 root root 4.0K Jan 14 00:53 include
5.0M -rwxr-xr-x 1 root root 5.0M Jan 14 00:53 javafx-src.zip
4.0K drwxr-xr-x 5 root root 4.0K Jan 14 00:53 jre
4.0K drwxr-xr-x 5 root root 4.0K Jan 14 00:53 lib
4.0K -r--r--r-- 1 root root 40 Jan 14 00:53 LICENSE
4.0K drwxr-xr-x 4 root root 4.0K Jan 14 00:53 man
4.0K -r--r--r-- 1 root root 159 Jan 14 00:53 README.html
4.0K -rw-r--r-- 1 root root 526 Jan 14 00:53 release
21M -rw-r--r-- 1 root root 21M Jan 14 00:53 src.zip
64K -rwxr-xr-x 1 root root 63K Jan 14 00:53 THIRDPARTYLICENSEREADME-JAVAFX.txt
144K -r--r--r-- 1 root root 142K Jan 14 00:53 THIRDPARTYLICENSEREADME.txt
root@xkfx:/usr/lib/jvm/java-8-oracle# echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle

先删除上面创建的用户:

root@xkfx:/# userdel tomcat
root@xkfx:/# who # 查看当前登陆用户
root pts/0 2018-02-23 10:13 (*******)

1

root@xkfx:/# cd /opt/
root@xkfx:/opt# ls -lsh
total 4.8M
4.0K drwxr-xr-x 9 999 999 4.0K Feb 22 21:16 apache-tomcat-8.0.41-src
4.8M -rw-r--r-- 1 999 999 4.8M Jan 19 2017 apache-tomcat-8.0.41-src.tar.gz
0 lrwxrwxrwx 1 999 999 25 Feb 22 21:19 tomcat-latest -> /opt/apache-tomcat-8.0.41
root@xkfx:/opt# mv apache-tomcat-8.0.-src tomcat8
root@xkfx:/opt# ls -lsh
total 4.8M
4.8M -rw-r--r-- 4.8M Jan apache-tomcat-8.0.-src.tar.gz
.0K drwxr-xr-x .0K Feb : tomcat8
lrwxrwxrwx Feb : tomcat-latest -> /opt/apache-tomcat-8.0.

2

root@xkfx:/opt# sudo useradd -s /sbin/nologin -d /opt/tomcat/temp tomcat
root@xkfx:/opt# sudo chown -R tomcat:tomcat /opt/
tomcat8
root@xkfx:/opt# pwd
/opt
root@xkfx:/opt# ls -lsh
total 4.8M
4.8M -rw-r--r-- 4.8M Jan apache-tomcat-8.0.-src.tar.gz
.0K drwxr-xr-x tomcat tomcat .0K Feb : tomcat8
lrwxrwxrwx Feb : tomcat-latest -> /opt/apache-tomcat-8.0.

3

sudo vim /etc/init.d/tomcat8
#!/bin/bash
#
#https://wiki.debian.org/LSBInitScripts
### BEGIN INIT INFO
# Provides: tomcat8
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start:
# Default-Stop:
# Short-Description: Start Tomcat.
# Description: Start the Tomcat servlet engine.
### END INIT INFO export CATALINA_HOME=/opt/tomcat8
export JAVA_HOME=/opt/jdk/jdk1..0_66
export PATH=$JAVA_HOME/bin:$PATH start() {
echo "Starting Tomcat 8..."
/bin/su -s /bin/bash tomcat -c $CATALINA_HOME/bin/startup.sh
}
stop() {
echo "Stopping Tomcat 8..."
/bin/su -s /bin/bash tomcat -c $CATALINA_HOME/bin/shutdown.sh
}
case $ in
start|stop) $;;
restart) stop; start;;
*) echo "Usage : $0 <start|stop|restart>"; exit ;;
esac exit

4

root@xkfx:/opt# sudo chmod  /etc/init.d/tomcat8
root@xkfx:/opt# ls -lsh /etc/init.d/tomcat8
.0K -rwxr-xr-x root root Feb : /etc/init.d/tomcat8
root@xkfx:/opt# sudo update-rc.d tomcat8 defaults # Install the script.

测试后没反应,想起 copy 来的脚本没有修改:

改好后还是没有反应!!!

试访问了一下也没有用。。。。。。。。。。

所以 估计 是 脚本根本没跑

How do services in Debian work, and how can I manage them?

换了种方式 有点反应了:

tomcat 用户是无法登陆的:

root@xkfx:~# su tomcat
Cannot execute /sbin/nologin: No such file or directory

(su = switch user)

认真看一下发现教程二其实是针对 debian 7 的

于是我干脆找了个debian 9 的教程应该和 8.8 更相近。

1

wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.0.M21/src/apache-tomcat-9.0.0.M21-src.tar.gz
root@xkfx:/opt# ls -lsh
total 9.5M
4.8M -rw-r--r-- 4.8M Jan apache-tomcat-8.0.-src.tar.gz
4.8M -rw-r--r-- root root 4.8M Jun apache-tomcat-9.0..M21-src.tar.gz
.0K drwxr-xr-x tomcat tomcat .0K Feb : tomcat8
useradd -rs /bin/false tomcat # 删除重新添加
root@xkfx:/opt# mkdir /opt/tomcat
root@xkfx:/opt# tar -C /opt/tomcat/ -zxf apache-tomcat-9.0..M21-src.tar.gz
root@xkfx:/opt# ln -s /opt/tomcat/apache-tomcat-9.0..M21-src/ /opt/tomcat/tomcat-latest # 可选的,当更新汤姆猫的时候让事情变得容易
root@xkfx:/opt# chown -R tomcat.tomcat /opt/tomcat/tomcat-latest /opt/tomcat/apache-tomcat-9.0..M21-src/ # Make our previously created user tomcat an owner of the entire directories
root@xkfx:/opt/tomcat# ls -lsh
total .0K
.0K drwxr-xr-x tomcat tomcat .0K Feb : apache-tomcat-9.0..M21-src
lrwxrwxrwx tomcat tomcat Feb : tomcat-latest -> /opt/tomcat/apache-tomcat-9.0..M21-src/

Note, when upgrading tomcat, simply unlink the current symbolic link and recreate new as shown in previous steps.

2

干脆重装一下 JDK

root@xkfx:/opt# ls
jdk-8u131-linux-x64.tar.gz tomcat
root@xkfx:/opt# mkdir /opt/java-jdk
root@xkfx:/opt# tar -C /opt/java-jdk -zxf jdk-8u131-linux-x64.tar.gz
root@xkfx:/opt# update-alternatives --install /usr/bin/java java /opt/java-jdk/jdk1..0_131/bin/java
root@xkfx:/opt# update-alternatives --install /usr/bin/javac javac /opt/java-jdk/jdk1..0_131/bin/javac
root@xkfx:/opt# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) -Bit Server VM (build 25.151-b12, mixed mode)

没改成,重新设置:

root@xkfx:/opt# sudo update-alternatives --config java
There are choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status
------------------------------------------------------------
/usr/lib/jvm/java--oracle/jre/bin/java auto mode
/opt/java-jdk/jdk1..0_131/bin/java manual mode
/usr/lib/jvm/java--openjdk-amd64/jre/bin/java manual mode
* /usr/lib/jvm/java--oracle/jre/bin/java manual mode Press enter to keep the current choice[*], or type selection number:
update-alternatives: using /opt/java-jdk/jdk1..0_131/bin/java to provide /usr/bin/java (java) in manual mode
root@xkfx:/opt# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) -Bit Server VM (build 25.131-b11, mixed mode)

同样的方式改 javac

3

root@xkfx:/opt# vim /etc/systemd/system/tomcat.service
[Unit]
Description=Tomcat9
After=network.target [Service]
Type=forking
User=tomcat
Group=tomcat Environment=CATALINA_PID=/opt/tomcat/tomcat-latest/tomcat8.pid
Environment=TOMCAT_JAVA_HOME=/usr/bin/java
Environment=CATALINA_HOME=/opt/tomcat/tomcat-latest
Environment=CATALINA_BASE=/opt/tomcat/tomcat-latest
Environment=CATALINA_OPTS=
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m" ExecStart=/opt/tomcat/tomcat-latest/bin/startup.sh
ExecStop=/bin/kill - $MAINPID [Install]
WantedBy=multi-user.target
root@xkfx:/# systemctl daemon-reload
root@xkfx:/# systemctl start tomcat
Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.
root@xkfx:/# systemctl enable tomcat
root@xkfx:/# systemctl status tomcat.service
tomcat.service - Tomcat9
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled)
Active: failed (Result: exit-code) since Mon -- :: CST; 12min ago Feb :: xkfx systemd[]: Starting Tomcat9...
Feb :: xkfx systemd[]: Failed at step EXEC spawning /opt/tomcat/tomcat-latest/b...nied
Feb :: xkfx systemd[]: tomcat.service: control process exited, code=exited status=
Feb :: xkfx systemd[]: Failed to start Tomcat9.
Feb :: xkfx systemd[]: Unit tomcat.service entered failed state. Warning: Unit file changed on disk, 'systemctl daemon-reload' recommended.
Hint: Some lines were ellipsized, use -l to show in full.
Feb  :: xkfx systemd[]: Failed at step EXEC spawning /opt/tomcat/tomcat-latest/bin/startup.sh: Permission denied
root@xkfx:/# ls -lsh /opt/tomcat/tomcat-latest/bin/startup.sh
.0K -rw-r--r-- tomcat tomcat .9K May /opt/tomcat/tomcat-latest/bin/startup.sh

持续 debug

root@xkfx:/# chmod -R u+x /opt/tomcat/tomcat-latest
root@xkfx:/# ls -lsh /opt/tomcat/tomcat-latest/bin/startup.sh
.0K -rwxr--r-- tomcat tomcat .9K May /opt/tomcat/tomcat-latest/bin/startup.sh
root@xkfx:/# systemctl start tomcat
Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.
root@xkfx:/# systemctl status tomcat.service -l
● tomcat.service - Tomcat9
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled)
Active: failed (Result: exit-code) since Mon -- :: CST; 27s ago
Process: ExecStart=/opt/tomcat/tomcat-latest/bin/startup.sh (code=exited, status=2)

Feb :: xkfx startup.sh[]: touch: cannot touch ‘/opt/tomcat/tomcat-latest/logs/catalina.out’: No such file or directory
Feb :: xkfx systemd[]: tomcat.service: control process exited, code=exited status=
Feb :: xkfx systemd[]: Failed to start Tomcat9.
Feb :: xkfx systemd[]: Unit tomcat.service entered failed state.
Feb :: xkfx startup.sh[]: /opt/tomcat/tomcat-latest/bin/catalina.sh: : /opt/tomcat/tomcat-latest/bin/catalina.sh: cannot create /opt/tomcat/tomcat-latest/logs/catalina.out: Directory nonexistent
root@xkfx:/opt/tomcat/tomcat-latest# mkdir logs
root@xkfx:/opt/tomcat/tomcat-latest# systemctl start tomcat
Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details. root@xkfx:/opt/tomcat/tomcat-latest# systemctl status tomcat.service -l
...
Feb :: xkfx startup.sh[]: touch: cannot touch ‘/opt/tomcat/tomcat-latest/logs/catalina.out’: Permission denied
Feb :: xkfx systemd[]: tomcat.service: control process exited, code=exited status=
Feb :: xkfx systemd[]: Failed to start Tomcat9.
Feb :: xkfx systemd[]: Unit tomcat.service entered failed state.
Feb :: xkfx startup.sh[]: /opt/tomcat/tomcat-latest/bin/catalina.sh: : /opt/tomcat/tomcat-latest/bin/catalina.sh: cannot create /opt/tomcat/tomcat-latest/logs/catalina.out: Permission denied

root@xkfx:/opt# chmod -R  tomcat/tomcat-latest

root@xkfx:/opt# systemctl daemon-reload

root@xkfx:/opt# systemctl start tomcat
root@xkfx:/opt# systemctl enable tomcat
root@xkfx:/opt# systemctl status tomcat.service -l
● tomcat.service - Tomcat9
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled)
Active: failed (Result: exit-code) since Wed -- :: CST; 18s ago
Main PID: (code=exited, status=/FAILURE) Feb :: xkfx startup.sh[]: Existing PID file found during start.
Feb :: xkfx startup.sh[]: Removing/clearing stale PID file.
Feb :: xkfx startup.sh[]: Tomcat started.
Feb :: xkfx systemd[]: Started Tomcat9.
Feb :: xkfx systemd[]: tomcat.service: main process exited, code=exited, status=/FAILURE
Feb :: xkfx systemd[]: Unit tomcat.service entered failed state.
root@xkfx:/opt# ss -ant | grep

感觉是相关问题:

Systemd tomcat.service failed with no errors

还是没有用。。。

不创建新用户跑 tomcat

root@xkfx:/opt/tomcat# ls -lsh
total .0K
.0K drwxr-xr-x root root .0K Feb : apache-tomcat-8.5.
lrwxrwxrwx root root Feb : tomcat-lastest -> apache-tomcat-8.5.
vim ~/.bashrc # export CATALINA_HOME=/path/to/tomcat
$CATALINA_HOME/bin/startup.sh
ss -ant | grep

无人访问:

有人访问:

完成。


参考资料:

How To Install and Configure Apache Tomcat on a Debian Server

How to Install Apache Tomcat 8 On Debian(教程二)

How to install Tomcat 8 on Debian 8(教程一)

Linux 笔记 #04# Installing Tomcat 8 on Debian的更多相关文章

  1. Linux 笔记 #02# Installing MySQL & Installing the Default JRE/JDK

    Environment: debian 8 Installing MySQL Reference material: https://linode.com/docs/databases/mysql/h ...

  2. Linux 笔记 #03# 在 Debian远程服务器上运行 Java socket程序

    我试图做什么:把我的破代码放到服务器上运行,并成功与客户端进行 socket通信. 预备环境:刚安装好 MySQL 和 JVM 的 Linux远程服务器(Debian 8)一台. 主要有如下几个步骤: ...

  3. authbind start tomcat services as user with less that 1024 ports. linux常规用户使用tomcat的80端口

    Start tomcat services using authbind this will allow user to start ports less than 1024 we do not ne ...

  4. Installing OwnCloud 9 on Debian 8

    原文:https://www.howtoforge.com/tutorial/owncloud_9-installation-on-debian_8/?utm_source=tuicool&u ...

  5. 【CAS单点登录视频教程】 第04集 -- tomcat下配置https环境

    目录 ----------------------------------------- [CAS单点登录视频教程] 第06集[完] -- Cas认证 学习 票据认证FormsAuthenticati ...

  6. linux笔记(一)——基本命令和快捷键

    linux笔记(一) 1.常用BASH快捷键 编辑命令 快捷键 作用 Ctrl + a 移到命令行首 Ctrl + e 移到命令行尾 Ctrl + xx 在命令行首和光标之间移动 Ctrl + u 从 ...

  7. Redis:学习笔记-04

    Redis:学习笔记-04 该部分内容,参考了 bilibili 上讲解 Redis 中,观看数最多的课程 Redis最新超详细版教程通俗易懂,来自 UP主 遇见狂神说 10. Redis主从复制 1 ...

  8. Java:并发笔记-04

    Java:并发笔记-04 说明:这是看了 bilibili 上 黑马程序员 的课程 java并发编程 后做的笔记 本章内容-3 线程状态转换 活跃性 Lock 3.10 重新理解线程状态转换 假设有线 ...

  9. 在Linux虚拟机下配置tomcat

    1.到Apache官网下载tomcat http://tomcat.apache.org/download-80.cgi 博主我下载的是tomcat8 博主的jdk是1.8 如果你们的jdk是1.7或 ...

随机推荐

  1. iOS-利用插件实时刷新模拟器(提高效率)

    解决办法: 1.需要给Xcode安装一个Alcatraz插件 安装完成后:点击window 下面的 package manager 安装我们今天的主角 2. ‘Injection Plugin for ...

  2. MUI 二维码扫描并跳转

    1 首页 index.html <li id="html/barcode.html" onclick="clicked(this.id)"> < ...

  3. ubuntu 信使(iptux) 创建桌面快捷方式

    $ sudo ln -s /usr/bin/iptux ~/桌面/iptux.ln

  4. Tomcat远程任意代码执行漏洞及其POC(CVE-2017-12617)

    一.原理分析: 只需参数readonly设置为false或者使用参数readonly设置启用WebDAV servlet false,则Tomcat可以不经任何身份验证的控制直接接收PUT方式上传的文 ...

  5. window自带字体

    一.在默认情况下, Windows 默认提供下列字体: Windows 95/98/98SE 宋体.黑体.楷体_GB2312.仿宋_GB2312 Windows XP/2000/2003/ME/NT ...

  6. img通过canvas转成base64编码

    <script type="text/javascript"> function getBase64Image(img) { var canvas = document ...

  7. [css]演示:纯CSS实现的右侧底部简洁悬浮效果

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name ...

  8. Oracle Database Memory Structures

    Oracle Database creates and uses memory structures for various purposes. For example, memory stores ...

  9. Composer 添加 Laravel-china 的国内源

    不知道由于什么原因,原来的 Composer 的国内镜像 https://pkg.phpcomposer.com/ 不能正常使用,经常连不上. 找了半天,发现还有一个 laravel-china 的国 ...

  10. 170724、springboot编程之完整demo

    综合之前学习,参考网上各大神博客,写了一个小demo,需要的朋友可以参考一下! 项目地址:https://github.com/zrbfree/spring-boot-anna.git