Ubuntu安装Tomcat以及Mysql(Javaweb项目发布)

一、服务器安装Tomcat

    1、更换国内源

sudo nano etc/apt/souces.list

       将下面的内容写入该文件 

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

       保存后更新源

sudo apt-get update

2、安装jdk 环境

sudo apt install default-jdk

3、创建Tomcat用户

sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

4、下载Tomcat

wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.34/bin/apache-tomcat-8.5.34.zip

5、解压Tomcat

unzip apache-tomcat-*.zip

6、将解压好的Tomcat文件移到tomcat目录下并创建符号链接

sudo mv apache-tomcat-*/ /opt/tomcat/
sudo ln -s /opt/tomcat/apache-tomcat-* /opt/tomcat/latest

7、更改tomcat目录拥有权限

sudo chown -R tomcat: /opt/tomcat

8、给tomcat/bin目录下的.sh文件可执行权限

sudo chmod +x /opt/tomcat/latest/bin/*.sh

 9、创建一个单元文件方便服务器开启

sudo nano  /etc/systemd/system/tomcat.service

10、将下面文本拷贝进去

[Unit]
Description=Tomcat 8.5 servlet container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh
[Install]
WantedBy=multi-user.target

11、通过下面文件打开tomcat并检查状态

sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl status tomcat

出现下面的提示就成功了

二、安装Mysql 5.6

  1、添加mysq了5.6的源并更新源

sudo apt-get install software-properties-common
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty universe'
sudo apt-get update

2、安装mysql

sudo apt install mysql-server-5.6
sudo apt install mysql-client-5.6

3、设置开机自启

update-rc.d mysql defaults

4、在etc/mysql/目录下创建或修改my.cnf文件

sudo nano /etc/mysql/my.cnf

   将下面内容复制到该文件里面

# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

!includedir /etc/mysql/conf.d/
# add here
[mysqld]
default-time_zone = '+8:00'
lower_case_table_names=1

5、重启mysql服务

sudo service mysql restart

三、将Javaweb项目打包成war包,上传到tomcat目录下的webapp里,重启tomcat就可以在外网访问了

 1、在菜单栏选择build-->build artifacts

2、在项目目录下找到该文件

3、将该文件夹压缩成.war

4、用xftp将war文件上传到tomcat的webapp目录下

5、重启tomcat服务器,服务器就会自动解压war包,就可以进行访问了路径就是http://<服务器ip>:8080/test/<网页>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章