歡迎您光臨本站 註冊首頁

如何使用​win10內置的linux系統啟動spring-boot項目

←手機掃碼閱讀     retouched @ 2020-07-06 , reply:0

1.安裝win10內置linux子系統

1.1.安裝linux子系統

1.1.1.升級或者重裝linux系統

1.系統要求

需要升級win10到一週年紀念版,或者 重裝系統

2.重裝系統

筆者結果測試發現下面的系統重裝後可以啟用linux子系統

cn_windows_10_enterprise_version_1607_updated_jul_2016_x64_dvd_9057083.iso
 cn_windows_10_multi-edition_vl_version_1709_updated_sept_2017_x64_dvd_100090774.iso

1.1.2.啟用linux子系統

step1.啟用開發人員模式
 

(16215版之後不再需要開發人員模式)

設置-->更新和安全-->針對開發人員

step2.啟用linux子系統

控制面板-->程序和功能-->啟用或關閉windows功能

1.1.3.在線安裝ubuntu系統

打開Microsoft Store安裝ubuntu系統

1.1.4.離線安裝ubuntu系統

下載安裝包,下載自己想要安裝的Linux系統。

參考鏈接:https://docs.microsoft.com/en...

下載Ubuntu 16.04.

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing

也可以使用curl下載,但是需要先安裝curl

curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604

安裝

Add-AppxPackage .app_name.appx

1.1.5.啟動ubuntu系統

啟動ubuntu系統

安裝完成後打開搜索菜單,輸入系統名字搜索啟動

輸出需要設置的用戶和密碼

你相信嗎,僅僅只有15.4MB

安裝目錄

C:UsersAdministratorAppDataLocalPackagesCanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc

home目錄

C:UsersAdministratorAppDataLocalPackagesCanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgscLocalState ootfshome

1.2.開啟ssh-server

1.2.1.相互複製文件

ubuntu的bash窗口窗與在xshell不同,通過shift+v無法黏貼,並且在輸入界面鼠標右鍵無法使用。粘貼文件的方法如下

右擊標題欄==> Edit(編輯) ==> Mark/Paste(標記並複製/粘貼)操作
 

這樣還是很麻煩,可以調整對話框,在彈出的菜單中有一個Properties對話框屬性菜單,點擊進入下圖

勾選快速編輯、快速插入模式,這兩種模式支持鼠標右鍵選中,左鍵黏貼操作。

最後,最好的方式是,在ubuntu上啟動ssh服務,通過xshell連接上操作會更好。

1.2.2.修改apt源

參考鏈接

https://developer.aliyun.com/...

用你熟悉的編輯器打開:

/etc/apt/sources.list

替換默認的archive.ubuntu.com為mirrors.aliyun.com

修改後的內容

ubuntu18.04

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

ubuntu 20.04(focal)

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
 deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

更新

apt-get update

1.2.3.啟用ssh

1.安裝ssh

apt-get -y install openssh-server

2.修改配置文件,一般不需要修改

  cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak  vi /etc/ssh/sshd_config

 

  # 修改端口號,避免和 Windows ssh 服務端口衝突  Port 2222  #StrictModes yes # 註釋  # 使用密碼登錄  PasswordAuthentication yes   # 允許使用 root 用戶登錄  PermitRootLogin yes

 

3.設置root賬號密碼

  sudo -s  passwd root

 

4.啟動ssh

service ssh start

5.如果提示“sshd error: could not load host key”,則用下面的命令重新生成

  rm /etc/ssh/ssh*key  dpkg-reconfigure openssh-server

 

使用xshell連接127.0.0.1輸入賬號和密碼即可

1.2.4.配置PS1變量

自行百度什麼事linux的PS1變量

export PS1="[e[1;32;40m][u@h W]$ [e[m]"

2.搭建開發環境

2.1.搭建java開發環境

2.1.1.安裝java和maven

  mkdir /usr/java  tar -xf jdk-8u211-linux-x64.tar.gz -C /usr/java/  mdkir /usr/maven  tar -xf litongjava-apache-maven-3.3.9.tar.gz -C /usr/maven/

 

配置環境變量

  export JAVA_HOME=/usr/java/jdk1.8.0_211  export M2_HOME=/usr/maven/apache-maven-3.3.9  export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH

 

配置maven使用windows的maven本地庫目錄,maven本地庫在linux中對應的目錄是/mnt/d/dev_mavenRepository/

settings.xml的內容如下

  cat /usr/maven/apache-maven-3.3.9/conf/settings.xml  /mnt/d/dev_mavenRepository/aliyunaliyun*https://maven.aliyun.com/repository/public

 

2.1.2.打包和啟動spring-boot項目

進行項目目錄執行下面的命令打包項目

mvn clean package -DskipTests

進入target目錄啟動項目

cd target/
 java -jar *.jar

可以明顯的看出,java程序使用了近1G的內存

 

   


[retouched ] 如何使用​win10內置的linux系統啟動spring-boot項目已經有629次圍觀

http://coctec.com/docs/linux/show-post-241370.html