Ubuntu14.04 Tomcat 安装过程记录

时间:2022-01-11 16:44:42

Ubuntu14.04 Tomcat 安装过程记录

检查java的版本

zhousp@ubuntu:~$
sudo java -version

[sudo] password for
zhousp:

java version
"1.7.0_95"

OpenJDK Runtime
Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.2)

OpenJDK 64-Bit
Server VM (build 24.95-b01, mixed mode)

zhousp@ubuntu:~$

查找java目录

zhousp@ubuntu:~$
whereis java

java: /usr/bin/java
/etc/java /usr/lib/java /usr/bin/X11/java /usr/share/java
/usr/share/man/man1/java.1.gz

zhousp@ubuntu:~$
which java

/usr/bin/java

设置环境变量

zhousp@ubuntu:~$
echo $JAVA_HOME

空行-表示没有设定该环境变量

zhousp@ubuntu:~$
echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

zhousp@ubuntu:~$
JAVA_HOME=/usr/bin/java;export JAVA_HOME

zhousp@ubuntu:~$
echo $JAVA_HOME

/usr/bin/java

zhousp@ubuntu:~$

安装Tomcat并设置环境变量

zhousp@ubuntu:~/Downloads$
sudo cp -r apache-tomcat-8.0.33 /home/tomcat

zhousp@ubuntu:~/Downloads$
cd /home/

zhousp@ubuntu:/home$
ls

tomcat zhousp

zhousp@ubuntu:/home$
cd tomcat

zhousp@ubuntu:/home/tomcat$

zhousp@ubuntu:/home/tomcat$
ls

bin conf lib
LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps
work

zhousp@ubuntu:/home/tomcat$
cd ~

zhousp@ubuntu:~$
CATALINA_HOME=/home/tomcat;export CATALINA_HOME

zhousp@ubuntu:~$
echo $CATALINA_HOME

/home/tomcat

zhousp@ubuntu:~$

解决conf文件夹访问权限不够的问题

zhousp@ubuntu:/home$
sudo chmod -R 755 tomcat

zhousp@ubuntu:/home$
ll

total 16

drwxr-xr-x 4 root
root 4096 4月
22 12:03 ./

drwxr-xr-x 23 root
root 4096 4月
23 11:32 ../

drwxr-xr-x 9 root
root 4096 4月
22 12:03 tomcat/

drwxr-xr-x 31 zhousp
zhousp 4096 4月
23 21:30 zhousp/

zhousp@ubuntu:/home$
cd ./tomcat

zhousp@ubuntu:/home/tomcat$
ls

bin lib logs
RELEASE-NOTES temp work

conf LICENSE
NOTICE RUNNING.txt webapps

zhousp@ubuntu:/home/tomcat$
ll

total 120

drwxr-xr-x 9 root
root 4096 4月
22 12:03 ./

drwxr-xr-x 4 root
root 4096 4月
22 12:03 ../

drwxr-xr-x 2 root
root 4096 4月
23 11:48 bin/

drwxr-xr-x 3 root
root 4096 4月
22 12:14 conf/

drwxr-xr-x 2 root
root 4096 4月
22 12:03 lib/

-rwxr-xr-x 1 root
root 57011 4月
22 12:03 LICENSE*

drwxr-xr-x 2 root
root 4096 4月
23 10:39 logs/

-rwxr-xr-x 1 root
root 1444 4月
22 12:03 NOTICE*

-rwxr-xr-x 1 root
root 6739 4月
22 12:03 RELEASE-NOTES*

-rwxr-xr-x 1 root
root 16195 4月
22 12:03 RUNNING.txt*

drwxr-xr-x 2 root
root 4096 4月
22 12:03 temp/

drwxr-xr-x 7 root
root 4096 4月
22 12:03 webapps/

drwxr-xr-x 3 root
root 4096 4月
22 12:14 work/

zhousp@ubuntu:/home/tomcat$

启动Tomcat

(使用eclipse
搭建java
web编程环境时,不需要启动Tomcat,eclipse运行程序时,会自己启动Tomcat。所以,作为系统服务启动Tomcat是为了讲系统作为web服务器,对外提供web服务,而不是启动之后,eclipse才能够链接到服务器。这一点和程序链接mysql服务器的概念截然不同。)

zhousp@ubuntu:/home/tomcat/bin$
sudo su

root@ubuntu:/home/tomcat/bin#
sh startup.sh

Using CATALINA_BASE:
/home/tomcat

Using CATALINA_HOME:
/home/tomcat

Using
CATALINA_TMPDIR: /home/tomcat/temp

Using JRE_HOME:
/usr

Using CLASSPATH:
/home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar

Tomcat started.

root@ubuntu:/home/tomcat/bin#

Ubuntu14.04 Tomcat 安装过程记录

ubuntu下设置Tomcat服务自动启动

root@ubuntu:/home/tomcat/bin# cp catalina.sh /etc/init.d/

root@ubuntu:/home/tomcat/bin# cd /etc/init.d/

root@ubuntu:/etc/init.d# mv catalina.sh tomcat

rroot@ubuntu:/etc/init.d# ls tomcat

tomcat

root@ubuntu:/etc/init.d# vim tomcat

添加环境变量:

JAVA_HOME=/home/tomcat

CATALINA_HOME=/usr/bin/java

Ubuntu14.04 Tomcat 安装过程记录

root@ubuntu:/etc/init.d# service tomcat start

Using CATALINA_BASE: /home/tomcat

Using CATALINA_HOME: /home/tomcat

Using CATALINA_TMPDIR: /home/tomcat/temp

Using JRE_HOME: /usr/bin/java

Using CLASSPATH:
/home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar

Tomcat started.

自动启动命令:

root@ubuntu:/# chmod 755 /etc/init.d/tomcat

root@ubuntu:/# update-rc.d -f tomcat defaults

update-rc.d: warning: /etc/init.d/tomcat missing LSB information

update-rc.d: see <http://wiki.debian.org/LSBInitScripts>

Adding system startup for /etc/init.d/tomcat ...

/etc/rc0.d/K20tomcat -> ../init.d/tomcat

/etc/rc1.d/K20tomcat -> ../init.d/tomcat

/etc/rc6.d/K20tomcat -> ../init.d/tomcat

/etc/rc2.d/S20tomcat -> ../init.d/tomcat

/etc/rc3.d/S20tomcat -> ../init.d/tomcat

/etc/rc4.d/S20tomcat -> ../init.d/tomcat

/etc/rc5.d/S20tomcat -> ../init.d/tomcat

root@ubuntu:/#

(删除自动启动)

zhousp@ubuntu:~$ update-rc.d -f tomcat remove

Removing any system startup links for /etc/init.d/tomcat ...

/etc/rc0.d/K20tomcat

update-rc.d: unlink: Permission denied

zhousp@ubuntu:~$ sudo update-rc.d -f tomcat remove

[sudo] password for zhousp:

Removing any system startup links for /etc/init.d/tomcat ...

/etc/rc0.d/K20tomcat

/etc/rc1.d/K20tomcat

/etc/rc2.d/S20tomcat

/etc/rc3.d/S20tomcat

/etc/rc4.d/S20tomcat

/etc/rc5.d/S20tomcat

/etc/rc6.d/K20tomcat

zhousp@ubuntu:~$

安装MySQL

  终端输入命令:
.$ sudo apt-get
install mysql-server
  这种方法安装完mysql需要修改root密码,不然会出现这么一种情况.'Access
denied for user 'root'@'localhost' (using password:
YES)'或者其他致使无法登录mysql的情况。可以按如下步骤解决:

  1.打开/etc/mysql/debian.cnf文件,里面存储了相关的密码

  sudo
gedit /etc/mysql/debian.cnf

  在[client]段有user=以及password=这两行,此即我们需要的东西

  2.输入命令:mysql
-udebian-sys-maint -p
  debian-sys-maint即debian.cnf中user=后面的内容

  回车后会提示输入密码,此时把password=后面的内容复制粘贴后回车即可进行mysql控制台(一般不要照打,容易出错,复制即可)

  3.进入控制台后.按以下步骤进行:

  use
mysql;
  update
user set password=PASSWORD('新密码')
where user='root';
  FLUSH
PRIVILEGES;
  此时可以输入quit;退出后用root帐号登录,也可以继续其他操作。

  MySQL编码设置

  启动和停止服务器:.$
/etc/init.d/mysql start(stop)
  主要配置文件所在位置:/etc/mysql/my.cnf

  放置数据库表文件夹,相当于windows下mysql的date文件夹:/var/lib/mysql/

  登录mysql后执行:>show
variables like 'character%';
  修改/etc/mysql/my.cnf文件:

  在[client]下面添加:

  default-character-set=utf8

  在[mysqld]下慢添加:

  default-character-set=utf8

  init_connect='SET
NAMES utf8'
  修改好后,重启mysql即可,查询一下:>show
variables like 'character%';
  重新启动mysql服务:.$
/etc/init.d/mysql start(stop)