阿里云服務器搭建及遠程自動化部署-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閱讀 228,345評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,494評論 3 416
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,283評論 0 374
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,953評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,714評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,186評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,255評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,410評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,940評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,776評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,976評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,518評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,210評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,642評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,878評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,654評論 3 391
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,958評論 2 373

推薦閱讀更多精彩內容