1.連接配接伺服器,準備環境
利用XShell連接配接遠端雲伺服器,準備Jdk、mysql、tomcat、redis的安裝
-
1.1設定伺服器防火牆
開放以下端口
Redis : 6379端口
Mysql : 3306端口
HTTP : 80端口
HTTPS : 443端口
SSH : 22端口
-
1.2去官網下載下傳安裝包,上傳到雲伺服器
Tomcat 8 :http://tomcat.apache.org/download-80.cgi#8.0.46
Mysql :https://dev.mysql.com/downloads/repo/yum/
Redis:https://redis.io/download
上傳至雲伺服器然後解壓
tar -xvzf redis-5.0.5.tar.gz
tar -xvzf apache-tomcat-8.5.43.tar.gz
-
1.3安裝JDK
[[email protected] ~]# yum list | grep jdk 檢視yum裡的JDK版本
[[email protected] ~]# yum install java-1.8.0-* 安裝JDK1.8
[[email protected] ~]# java -version 安裝成功
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
-
1.4安裝MySQL
[[email protected] ~]# rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
安裝用來配置Mysql的yum源的rpm包
[[email protected] ~]# yum install mysql-community-server
安裝Mysql
[[email protected] ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
啟動Mysql
[[email protected] ~]# ps -ef | grep mysqld
mysql 3131 1 9 01:57 ? 00:00:01 /usr/sbin/mysqld
root 3178 2353 0 01:57 pts/0 00:00:00 grep --color=auto mysqld
檢視Mysql程序
[[email protected] ~]# grep 'temporary password' /var/log/mysqld.log
2019-08-08T17:57:03.766499Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: fm;v-i#nj0oH
檢視Mysql自動生成的密碼
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.17
用初始密碼登入Mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Hr980526';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Hr980526!'
-> ;
Query OK, 0 rows affected (0.01 sec)
修改密碼 密碼需要大小寫字母數字以及特殊符号混合 否則提示密碼不符合政策
mysql> create user 'lzx'@'%' identified by 'Hr980526!';
Query OK, 0 rows affected (0.01 sec)
建立一個新使用者供用戶端連接配接
mysql> grant select,insert.update,delete on *.* to 'lzx'@'%';
Query OK, 0 rows affected (0.01 sec)
賦權限給新使用者
mysql> show grants for 'lzx'@'%';
+----------------------------------------------------------+
| Grants for lzx@% |
+----------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO `lzx`@`%` |
+----------------------------------------------------------+
1 row in set (0.00 sec)
檢視權限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
立即生效
雲伺服器安裝的8.0Mysql,本機5.6Mysql,由于加密方式問題,可能導緻本地連接配接雲伺服器Mysql失敗。
登入雲伺服器資料庫,執行以下指令即可:
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Hr980526!';
Query OK, 0 rows affected (0.01 sec)
-
1.5安裝Redis
[[email protected] ~]# ls
apache-tomcat-8.5.43 mysql80-community-release-el7-3.noarch.rpm redis-5.0.5
進入redis解壓後的目錄
[[email protected] ~]# cd redis-5.0.5
利用make指令将redis源代碼編譯
[[email protected] redis-5.0.5]# make
修改配置檔案
[[email protected] redis-5.0.5]# ls
00-RELEASENOTES CONTRIBUTING deps Makefile README.md runtest runtest-moduleapi sentinel.conf tests
BUGS COPYING INSTALL MANIFESTO redis.conf runtest-cluster runtest-sentinel src utils
[[email protected] redis-5.0.5]# vim redis.conf
将daemonize改為yes 背景啟動
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
将bind 127.0.0.1 注釋掉 開放遠端連接配接
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1
redis測試
[[email protected] redis-5.0.5]# src/redis-server redis.conf
8842:C 09 Aug 2019 03:31:59.408 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8842:C 09 Aug 2019 03:31:59.408 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=8842, just started
8842:C 09 Aug 2019 03:31:59.408 # Configuration loaded
[[email protected] redis-5.0.5]# src/redis-cli
127.0.0.1:6379> set 'name' 'lzx'
OK
127.0.0.1:6379> get 'name'
"lzx"
127.0.0.1:6379>
-
1.6安裝Tomcat8.5
[[email protected] bin]# ./startup.sh
Using CATALINA_BASE: /root/apache-tomcat-8.5.43
Using CATALINA_HOME: /root/apache-tomcat-8.5.43
Using CATALINA_TMPDIR: /root/apache-tomcat-8.5.43/temp
Using JRE_HOME: /usr
Using CLASSPATH: /root/apache-tomcat-8.5.43/bin/bootstrap.jar:/root/apache-tomcat-8.5.43/bin/tomcat-juli.jar
Tomcat started.
解壓後,進入tomcat的src的bin目錄下 startup指令即可啟動
2.項目的釋出
前面已經完成了伺服器和環境的配置,接下來就可以将自己的項目打包釋出了。
-
2.1項目打包
我的項目是IDEA開發的SpringBoot項目,打包過程如下:
- 添加tomcat依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--打包的時候可以不用包進去,别的設施會提供。事實上該依賴理論上可以參與編譯,測試,運作等周期。
相當于compile,但是打包階段做了exclude操作-->
<scope>provided</scope>
</dependency>
- 修改包類型,打成war包
<groupId>cn.lzx</groupId>
<artifactId>university_shop</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
- 修改啟動類,繼承SpringBootServletInitializer類,重寫config方法
@SpringBootApplication
@MapperScan("cn.lzx.university_shop.mapper")
@ImportResource(locations = {"classpath:kaptcha.xml"})
public class UniversityShopApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(UniversityShopApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(UniversityShopApplication.class);
}
}
- 設定打包之後包名(可選)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>o2o</warName>
</configuration>
</plugin>
完成以上設定後,利用maven打包,即可在項目目錄下生成target檔案夾,裡面存放了生成的war包。
如果之前打過包,需要先maven clean一下,然後maven package打包。
-
2.2項目釋出
- 啟動雲伺服器的tomcat,然後将war包放在tomcat/webapps目錄下
- 過幾秒鐘,tomcat會自動将該war包解壓,生成對應的檔案夾
- 然後本機浏覽器輸入雲伺服器IP/域名+項目路徑即可通路
至此,項目釋出完成,可以在公網進行通路,對雲伺服器也可以購買域名進行域名綁定。
3.注意事項
-
3.1項目釋出後,本機無法通路?請求逾時?
購買的雲伺服器配置較低,tomcat也沒有進行調優,啟動較慢,可以啟動tomcat後等待幾分鐘再去通路。