阿里云服务器搭建及远程自动化部署-java+tomcat+mysql+Alibaba Cloud(入门篇)

阿里云通用代金卷活动(土豪购买可忽略)

购买前领取幸运券,可能会有折上折优惠哦:领取幸运抵扣卷
购买地址

win10直接连接阿里云服务器(Linux):

【如果使用XShell可以跳过】

  1. 首先你得安装下telnet客户端,系统自带的。
    控制面板——程序与功能——启动或关闭windows功能
    QQ截图20191125143655.png

    2.将Telnet客户端勾上,点确定(等待安装完成即可)。
    QQ图片20191125144043.png

    3.win键+R键 然后输入CMD 回车打开CMD窗口
    输入 ssh 账号名@服务器ip地址:端口号
    例如: ssh root@111.222.1.2
    第一次可能需要输入yes,如果输了no就无法连接了
    然后再让你输入密码(输入密码时,你是看不出有任何变化的【因为Linux觉得“没有消息就是最好的消息😄”】)
    QQ截图20191125144557.png

XShell、XFtp的安装与使用

XShell和XFT下载地址

QQ截图20200114155839.png

QQ截图20200114160004.png

XShell使用(连接XFtp和连接XShell一样):
新建一个会话


QQ图片20191126104933.png

点击你新建的回话,弹出让你输入用户名(一般默认用户名为root)


QQ截图20191126105305.png

点击确认后就会让你输入密码(可以在阿里云官网重置修改)
QQ截图20191126105330.png

这样你就连接上服务器了。

Linux添加用户(可以根据不用用户给不同权限)

  1. 登录root账号后
    输入:useradd -d /usr/zxy -m zxy2019
    -d 是给新用户创建主目录
    -m 是用户名

  2. 修改新用户的密码(修改前我们先进到新用户的主目录)
    输入:cd /usr/zxy/
    输入:passwd zxy2019
    输入:你的新密码
    输入:确认新密码

    QQ图片20191125161154.png

  3. 给予权限
    输入: sudo vim /etc/sudoers

    QQ图片20191125161958.png

    输入:/root (可以快速定位root 位子,然后再添加自己新用户的权限,相匹配的会出现高亮)
    输入::noh(取消高亮)
    输入:i (即可写了)
    输入::wq! (强制保存)

JDK的安装与配置

这里需要注意下:

我们平常linux 下载jdk都会 wget http://xxxxxx 这种方式,现在由于oracle限制了,每次下载的安装包都是没用的,解压失败问题(既然下载不了,那我们就本地下载上传上去)
所以我们使用XShell和XFT来进行云服务器的控制和文件的传输(非商业用途的免费使用)

  1. 检查是否安装
    输入:rpm -qa| grep jdk(什么信息都没返回就说明没安装)

    QQ截图20191125174044.png

  2. 下载:java下载地址

  3. 下载对应版本的包(后缀为:.tar.gz)
    sudo mkdir java(一般会再根目录下新建一个文件夹)

  4. 上传到服务器(直接拖进去就行)


    QQ截图20191126112053.png
  5. 解压tar -zxvf jdk-8u181-linux-x64.tar.gz(没任何提示就说明成功了,或者你也可以打开XFT查看)

    QQ截图20191126113049.png

  6. 配置环境变量(配置之前,建议先给系统来个快照。不然你profile文件修改错误后你会头大😄各种指令失效)
    输入:vim /etc/profile(打开profile文件夹)
    输入:i(插入命令)
    输入:

export JAVA_HOME=/java/jdk1.8.0_231
export JRE_HOME=/java/jdk1.8.0_231/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin/$JAVA_HOME:$PATH

QQ截图20191126131905.png

(输入完成后,按下esc键退出输入)
输入::wq! (强制保存)
输入:source /etc/profile(使环境变量生效 )
输入:java –version命令和javac(检测是否配置成功)
使用javac命令,不会出现command not found错误
使用java -version,出现版本为java version "1.8.0_231"
QQ截图20191126171215.png

安装tomcat及配置环境

1.下载:Tomcat下载地址(这里我们还是和java一样去官网下载)

QQ截图20191126175226.png

  1. 上传到服务器(直接拖进去就行)
  2. 解压tar -zxvf apache-tomcat-9.0.29.tar.gz
  3. 重命名:mv apache-tomcat-9.0.29 tomcat9 (为方便记忆以及日后的使用,也可以不从命名)
  4. 配置字符集vim conf/server.xml(把端口改成80,或者其他你想要的端口)
    QQ截图20191126220630.png

    6.在tomcat/bin 目录下输入:./startup.sh(启动tomcat)
    QQ图片20191126221822.png

    6-1 在本地测试下是否开启成功
    输入:curl localhost:80 出现html网页源码就说明启动成功。
    QQ截图20200203231631.png
  1. 在浏览器输入公网ip:端口号 就可以看到tomcat的网址,证明配置成功(然而你可能还是访问不到😂看上去都很简单,但是自己一操作就各种问题😄。跑题了,咱们继续...)


    QQ截图20191128225435.png

    QQ截图20191128225627.png
  2. 确认你安全组里面允许了该端口(这里你允许了可能还是没用😂)
  3. 再次去设置tomcat vim conf/server.xml
    1.找到Engine标签defaultHost属性把值:localhost改成你自己的公网ip。(有两处)
    2.再找到Host标签的name属性也是一样。改成自己的公网ip
    3.然后wq!保存
    不出意外的话,你现在就可以愉快的访问到了!
  4. 如果你还是访问不了,那你可以看看防火墙了。
    1.首先我们看看防火墙是否开启。输入firewall-cmd --state 返回running说明开启了(如果没开启输入systemctl start firewalld 去开启)
    QQ截图20200203230548.png

2.查看防火墙是否开启80端口(这里的80改成你tomcat设置的端口)
输入firewall-cmd --permanent --zone=public --list-ports(如果返回里面看不到你tomcat的端口,说明没有开启。那么需要输入firewall-cmd --zone=public --add-port=80/tcp --permanent 去开启,里面的80端口改成你tomcat的端口)

QQ截图20200203230956.png

3.重启防火墙并查看8080端口是否开成功输入:firewall-cmd --reload,重启后通过方法2查看全部开启的端口,也可以输入firewall-cmd --zone=public --query-port=80/tcp 单独的这个端口
QQ截图20200203231513.png

这次不出意外,你真的可以访问了。

MySQL安装部署

上面已经用过官网下载软件上传解压安装的方式了,这次咱们换一种安装方式;使用的是yum来安装😉。

  1. 检查下是否安装过rpm -qa | grep mysql(还是像往常一样,没有任何提示就是没有安装;centos7中默认安装了数据库MariaDB,如果直接安装MySQL的话,会直接覆盖掉这个数据库,所以咱们就不管这个了。)
    QQ截图20191128102850.png

    PS:如果安装了, 普通删除模式 rpm -e mysql
  2. 安装MySQL官方的Yum Repositorywget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    QQ截图20191128142458.png
  3. 下载rpm包yum -y install mysql57-community-release-el7-10.noarch.rpm
    QQ截图20191128142952.png
  4. 安装MySQL服务yum -y install mysql-community-server
    QQ截图20191128143140.png
  5. 启动MySQL服务systemctl start mysqld.service(以Starting MySqL server.. started MysqlServer..结尾的就成功启动了【注意:是mysqld】)
  6. 如果启动后没有任何信息,咱们就在查询下看看是否启动成功。systemctl status mysqld.service(当然一般不提示就是成功了,Linux系统就是这样。你懂的😄)
    QQ截图20191128144731.png
  7. 设置 mysql 开机自启systemctl enable mysqld(每次重启服务器MySQL都会关闭的,所以设置这个还是可以省去很多事的)
  8. 刷新配置systemctl daemon-reload(让它生效)
  9. 设置mysql密码
    ①第一次启动MySQL后,就会有临时密码,这个默认的初始密码在/var/log/mysqld.log文件中,所以我们先把初始密码找出来:grep 'temporary password' /var/log/mysqld.log
    QQ截图20191128150442.png

②登录:mysql -uroot -pysAE6D%C-HM4(u后面是用户名(一般为root),p后面紧接着密码)

QQ截图20191128152428.png

③修改密码:alter user root@localhost identified by '你要修改成的密码';(不出意外,会提示你一个错误)

QQ截图20191128152712.png

他会告诉你:您的密码不符合当前的策略要求。
啥要求呢?
PS:mysql5.7以上默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误。
想看密码策略的可以输入:show variables like '%password%';自行去查看
QQ截图20191128153131.png

想修改策略的自行百度(有三种策略)。
你也可以省事的直接去除他这种策略 validate_password = off然后使其生效systemctl restart mysqld
下图是修改成功后的图:
QQ截图20191128153706.png

  1. 删除(因为安装了Yum Repository,采用Yum管理各种rpm包的依赖,以后每次操作yum都会自动更新,所以需要卸载它)
    ①查看安装的mysql版本rpm -aq | grep -i mysql(记得先退出MySQL 退出命令:\q)
    QQ截图20191128160131.png

    ②删除yum -y remove mysql57-community-release-el7-10.noarch
    QQ截图20191128164313.png
  2. 配置远程登录:(MySQL默认root用户只能本地登录,如果要远程连接,要简单设置下)
    ①首先登录数据库(上面有登录的命令)
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '当前用户的密码' WITH GRANT OPTION;.的意思是所有库的所有表;To后面跟的是用户名;@后面跟的是ip地址,%代表所有ip地址,identified by后面的是密码。)
    QQ截图20191128174052.png

    ③冲刷权限flush privileges;
    QQ截图20191128174336.png

    补充点:(我这里没用到就没设置,了解下就行)
    需要注意MySQL的配置文件中的bindaddress 的参数和skip-networking 配置
    bindaddress : 设定哪些ip地址被配置,使得mysql服务器只回应哪些ip地址的请求),最好注释掉该参数或设置成为127.0.0.1以外的值。
    skip-networking : 如果设置了该参数项,将导致所有TCP/IP端口没有被监听,也就是说除了本机,其他客户端都无法用网络连接到本mysql服务器,所以应该注释掉该参数。
  3. 添加3306端口firewall-cmd --zone=public --add-port=3306/tcp --permanent;(可能这个时候你防火墙还没开启。命令含义: --zone #作用域 --add-port=80/tcp #添加端口,格式为:端口/通讯协议 --permanent #永久生效,没有此参数重启后失效 )
  4. 开启防火墙systemctl start firewalld
  5. 再重新添加3306端口(使用上面添加2206端口命令命令)
  6. 重启防火墙firewall-cmd --reload
    QQ截图20191128223332.png
  7. MySQL设置utf8(进入ect目录下)vim my.cnf
    添加:character_set_server=utf8init_connect='SET NAMES utf8'
    QQ截图20191128224025.png

    PS:采用navicat新建数据库时,需要将编码方式设置为,字符集:utf8 -- UTF-8 Unicode ,排序规则:utf8_general_ci
  8. 再去检查下阿里云安全组端口是否允许了3306端口。没有的话开启就OK了(和上面tomcat允许安全组一样)

本地开发工具下载环境配置及远程部署项目

Maven 下载安装与配置

  1. Maven官网下载地址(Maven3.2.版本需要JDK1.6的支持,Maven3.3.以上需要JDK1.7以上的支持)
  2. 下载最新版本


    QQ截图20191203220024.png
  3. 解压


    QQ截图20191203225921.png
  4. 配置Maven环境变量(和配java环境一样)
    1.新建环境变量MAVEN_HOME和M2_HOME,分别填上你解压后的路径(我这里的路径:C:\zxy\maven\apache-maven-3.6.3)
    2.编辑环境变量Path,追加%MAVEN_HOME%\bin;


    QQ截图20191203230227.png
  5. 检查是否安装及配置成功
    cmd进入DOS命令输入:mvn -v
    QQ截图20191203224602.png
  6. 修改maven配置文件(settings.xml文件【在conf目录下】)
    主要修改:
    1、本地仓库位置
    <localRepository>C:\Users\59908\.m2\repository</localRepository>(C:\Users\59908.m2\repository:可以自行修改位子,随便创建一个文件夹做本地仓库)
    2、修改maven默认的JDK版本(修改成你本机的版本)
<profile>     
      <id>JDK-1.8</id>       
      <activation>       
        <activeByDefault>true</activeByDefault>       
        <jdk>1.8</jdk>       
      </activation>       
      <properties>       
        <maven.compiler.source>1.8</maven.compiler.source>       
        <maven.compiler.target>1.8</maven.compiler.target>       
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>       
      </properties>       
    </profile>
  </profiles>

3、添加国内镜像源

   <!-- 阿里云仓库 -->
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>

  </mirrors>

4、完整的Settings.xml文件(如果上面不会加的话就复制完整的文件去里面修改好了)

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
    <localRepository>C:\Users\59908\.m2\repository</localRepository>
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
        <!-- 阿里云仓库 -->
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>

  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
    <profile>     
      <id>JDK-1.8</id>       
      <activation>       
        <activeByDefault>true</activeByDefault>       
        <jdk>1.8</jdk>       
      </activation>       
      <properties>       
        <maven.compiler.source>1.8</maven.compiler.source>       
        <maven.compiler.target>1.8</maven.compiler.target>       
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>       
      </properties>       
    </profile>


  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>
  1. IDEA配置maven
    目前常用的开发工具如idea,eclipse都自身集成了一个版本的Maven。但是通常我们使用自己已经配置好的Maven


    QQ截图20191203232406.png

    最后记得勾选此处,当修改pom文件时,Maven就能帮我们自动导包了。


    QQ截图20191203232830.png

IntelliJ IDEA远程部署项目至阿里云服务器

Cloud Toolkit插件

阿里云提供了基于 Intellij IDEA 的插件,以方便开发人员能够高效的将本地 IDE 中编写的应用程序,极速部署到服务器中去。
Cloud Toolkit官方地址

  1. 我们这边直接在idea中下载File>>Setting>>Plugins


    QQ截图20200205105915.png

    下载完后,重启Idea编辑器即可。

  2. 配置Cloud Toolkit插件中的Accout信息(这一步很重要)
    这个Accout信息在阿里云的控制台中配置(如果是新用户,需要手动创建一个AccessKey)将鼠标放在右上角头像上,既可以看到AccessKey管理。
    QQ截图20200205111206.png

    官方配置文档
    我这里省事就不用子用户了。
    QQ截图20200205111924.png

创建完后你就可以获取到一个AccessKey ID与Access Key Secret


QQ截图20200205112326.png
  1. 账号准备好了,那我们就去配置吧(Tools>>Alibaba Cloud>>Preferences...)


    QQ截图20200205112448.png

    QQ截图20200205112834.png
  2. 配置服务器与本地关联(右击项目>>AlibabaCloud>>Deploy to ESC)
    QQ截图20200205125141.png

    QQ截图20200205130125.png

    QQ截图20200205130504.png

    Command官方文档
    1.创建restart-tomcat.sh文件,想创建在哪个目录就在哪个下执行vi restart-tomcat.sh (后面在Command地方记得改到这个文件目录下就行)
    2.然后按i 进入输入模式。复制下面的指令(LuckyJW这个换成你项目名称就行。/tomcat/tomcat9这个就是你tomcat的路径)
source /etc/profile
# (务必根据实际情况自行添加指令执行,如:jps   -ml. |grep  你要杀死的包名  |xargs. kill)
killall java
rm -rf /tomcat/tomcat9/webapps/LuckyJW  
sh /tomcat/tomcat9/bin/startup.sh

3.按esc键 输入 :wq! 回车
4.给restart-tomcat.sh文件赋予权限 执行命令:chmod +x restart-tomcat.sh 回车
5.在/etc/profile这个文件上添加

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# 这里换成自己jdk的目录(我之前已经设置过了,这个一般都已经设置过的了。)
#java 1.8
export JAVA_HOME=/java/jdk1.8.0_231
export JRE_HOME=/java/jdk1.8.0_231/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin/$JAVA_HOME:$PATH
QQ截图20200205133935.png

6.最后Apply>>Run


QQ截图20200205134315.png

7.最后运行程序等待部署


QQ截图20200205134538.png

运行成功后会出现下图
QQ截图20200205135527.png

你也可以用浏览器测试下

QQ截图20200205135430.png

补充下:linux下使用shutdown.sh 关闭时可能会出现SEVERE: Could not contact [localhost:8005] (base port [8005] and offset [0])错误。(这个问题是因为在tomcat没完全启动前就关闭tomcat)
QQ截图20200205140538.png

解决:进入你jdk目录(/java/jdk1.8.0_231/jre/lib/security)找到java.security文件。
使用命令vim java.security进行编辑
/securerandom 进行搜索并高亮
最后将

securerandom.source=file:/dev/random
改为:
securerandom.source=file:/dev/urandom
QQ截图20200204215949.png

这样就可解决这个问题。这样修改是提升为启动tomcat的运行速度。
现在你的项目是不是已经快乐的运行起来了?


  • 下面是扯犊子的屁话。可以忽略(我也是第一次自学后台,所以才会有这么多问题,这么多感慨😂)
    不不不,你可能还会像我一样遇到一些头疼的问题(对于新手,第一次玩后台一定会遇到各种奇怪的问题)。
    比如:本地运行完美,可已部署到服务器,mysql就连接不上了。
    再比如:本地运行完美,可已部署到服务器,就给你报静态类加载失败。
    等等,等等...
    这些问题你能发现那还算好的。毕竟发现问题就可以解决问题。
    但是对于很多新手来说,本地问题可以看idea上的log日志。可是云服务器上的日志在哪呢?怎么看呢?(网上很多东西,对于用过的人来说,人家一看就懂,但是对于萌新来说,真的不一定懂。)
    我当时按他们步骤操作,就是不行。最后冷静下来分析,问题出在哪里。对,遇到问题一定要自己理解,自己分析。很多东西别人觉得很简单,随便几个命令就可以了。但是这命令里面什么意思你懂吗?这命令里面那些地方需要换成自己本地的路径你懂吗?你都不知道。所以你就会出现,照着大神的命令敲,还是解决不了问题。
    好了,自我吐槽就到这里了。
  • 吐槽结束.............

如何查看云服务上的日志

方法1:(推荐用方法2😄)
使用Xftp工具,或者命令进入到你tomcat目录下的logs目录。里面就有记录你服务器的错误日志,然后根据你当时访问服务器的时间,找到对应时间的日志,然后导出来查看,分析。


QQ截图20200221112145.png

看上去很简单吧。但是你第一次接触后端。你可能和我一样还真不知道在哪里看。
方法1有些麻烦,对于开发来说,懒那都是通病。因为懒,才能创新出更多帮助你偷懒的工具😂。
方法2:实时查看服务器日志。
这也得感谢伟大的阿里大神们。让我们节省更多的时间去打游戏,不不不,说错了,是去学习😆
方法2也很简单。因为我们之前已经配置了Alibaba Cloud远程部署项目了。所以我们只需要在添加一部就可以了。(如果还不会用Alibaba Cloud远程部署的可以看看上面我写的《IntelliJ IDEA远程部署项目至阿里云服务器》)
①和上面一样:右击项目>>AlibabaCloud>>Deploy to ESC
②选择Advanced
③在Command中输入命令(命令中的/tomcat/tomcat9,换成你自己服务器tomcat的路径)
tail -f /tomcat/tomcat9/logs/catalina.out -n200
④勾选Automatic open after deploy
⑤运行 run
这样就大功告成了

QQ截图20200221113551.png

这样就可以看到实时错误日志啦。
QQ截图20200221113918.png

上一篇:Lint常见的问题及解决方案

下一篇:APK反编译工具使用教程

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容