Win10安装wls2 Ubuntu22.04及开发环境配置

1️⃣ 安装Ubuntu22.04

  1. 启动或关闭Windows功能中,打开

    • 适用于Linux白的Windows子系统
    • 虚拟机平台
  2. microsoft store安装Ubuntu22.04

  3. 设置wls2 更多wls操作的官方原文

# 查看wsl版本
wsl -l -v

# 设置wls2 
wsl --set-version Ubuntu-22.04 2

2️⃣ 初始化设置

  1. 修改root密码
# powershell下
ubuntu2204 config --default-user root

# ubuntu下
passwd root
  1. 换源
    如果你不熟悉或不想用vim可以直接在此电脑中打开source.list,路径为:\\wsl.localhost\Ubuntu-22.04\etc\apt

  1. 更新Ubuntu系统
# 更新本地包数据库
sudo apt update
# 更新所有已安装的包(也可以使用 full-upgrade)
sudo apt upgrade
# 自动移除不需要的包
sudo apt autoremove
  1. SSH设置
# 安装ssh
sudo apt-get install openssh-server

配置SSH

sudo vim /etc/ssh/sshd_config

# 需要修改增加的配置如下
Port 2222  #默认的是22,但是windows有自己的ssh服务,也是监听的22端口,所以这里要改一下
PasswordAuthentication yes
AllowUsers yourname

# 启动SSH
sudo service ssh --full-restart

请添加图片描述

  1. 安装终端主题(⚠️不建议折腾)

这不得体验一下好看的终端

# 安装zsh
sudo apt install zsh
git clone https://github.com/robbyrussell/oh-my-zsh
cd ~/oh-my-zsh/tools && sh install.sh
git clone https://github.com/zsh-users/zsh-autosuggestions.git ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
# 配置自己喜欢的样式
vim ~/.zshrc
plugins=(git zsh-autosuggestions)

请添加图片描述

有乱码,没有原生Linux下的好看,看其他说改字体JetBrainsMonoNerdFont-Bold,我尝试了没有效果…

3️⃣ 开发环境

9. Go

# 下载安装
wget https://go.dev/dl/go1.20.13.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && tar -C /usr/local -xzf go1.20.13.linux-amd64.tar.gz
# 配置
export PATH=$PATH:/usr/local/go/bin
source /etc/profile
# 查看
go version
# 设置
go env -w  GOPROXY=https://goproxy.cn,direct
# 清除安装包
rm go1.20.13.linux-amd64.tar.gz
# 卸载(!这是补充)
sudo rm -rf /usr/local/go

10. Redis

# 安装
sudo apt install redis-server -y
# 查看
systemctl status redis-server
# 设置密码认证
sudo vim /etc/redis/redis.conf
# requirepass footbared
requirepass admin.123

11. Mysql

# 安装
sudo apt install mysql-server -y
# 检查
sudo systemctl status mysql
# 设置密码
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';
FLUSH PRIVILEGES;
EXIT

设置远程连接

use mysql;
update user set Host='%' where User='root';
flush privileges;

12. Docker

必须要先安装Docker Desktop,尝试了直接安装,没有成功,官方也建议要先下载桌面版再连接到Ubuntu,(PS: 咋感觉有点多此一举😅)
可能会有所变动,建议直接看官方安装教程

  1. 下载Docker桌面版

  2. 在Docker中Resources -> WSL INTEGRATION,勾选Ubuntu22.04

13. Nacos

之前用的老版本多了写安全的配置

  1. 创建日志文件夹和配置文件
mkdir /home/nacos/logs
vim /home/nacos/conf/application.properties

配置文件如下(在官方配置文件下修改的)
需要修改的3处已经标出

# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
server.tomcat.accesslog.max-days=30
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.error.include-message=ALWAYS
# default current work dir
server.tomcat.basedir=file:.
#*************** Config Module Related Configurations ***************#
### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
#spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:}
spring.sql.init.platform=${SPRING_DATASOURCE_PLATFORM:}
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db.num=${MYSQL_DATABASE_NUM:1}
# 1. 这里需要修改
db.url.0=jdbc:mysql://mysql:xxx.xxx.xxx.xxx:xxxx/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
db.user.0=xxx
db.password.0=xxx
## DB connection pool settings
db.pool.config.connectionTimeout=${DB_POOL_CONNECTION_TIMEOUT:30000}
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}
### The default token:
# 2. 这里需要修改 xxx需要base64编码且长度大于等于32
nacos.core.auth.plugin.nacos.token.secret.key="SecretKeyxxx"
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=false
# 3. 这里需要修改 
nacos.core.auth.server.identity.key=xxx
nacos.core.auth.server.identity.value=xxx
## spring security config
### turn off security
nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
nacos.console.ui.enabled=true
nacos.core.param.check.enabled=true
  1. 启动
sudo docker run \
--name nacos -d \
-p 8848:8848 -p 9848:9848 -p 9555:9555 \
--privileged=true \
--restart=always \
-e JVM_XMS=512m \
-e JVM_XMX=512m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-v /home/nacos/logs:/home/nacos/logs \
-v /home/nacos/conf/application.properties:/home/nacos/conf/application.properties \
nacos/nacos-server

14. Consul

docker pull consul:1.15.4
docker run -d -p 8500:8500 -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8600:8600/udp consul:1.15.4 agent -dev -client=0.0.0.0

15. Yapi

  1. 安装mongoDB
# 安装mongoDB
docker pull mongo
# 启动
docker run \
-d \
--name mongo \
--restart=always \
--privileged=true \
-p 27017:27017 \
-v /home//mongodb/data:/data/db \
mongo --auth
# 配置
docker exec -it mongo /bin/bash
mongo admin
db.createUser({ user:'root',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
  1. 安装yapi
# 老版本
docker pull jayfong/yapi
# 启动,主要替换xxx
docker run \
-d \
--name yapi \
--restart=always \
--privileged=true \
-p 3000:3000 \
-e YAPI_ADMIN_ACCOUNT=xxx@xxx.com \
-e YAPI_ADMIN_PASSWORD=xxx\
-e YAPI_CLOSE_REGISTER=true \
-e YAPI_DB_SERVERNAME=xxx.xxx.xxx.xxx \
-e YAPI_DB_PORT=27017 \
-e YAPI_DB_DATABASE=yapi \
-e YAPI_DB_USER=root \
-e YAPI_DB_PASS=123456 \
-e YAPI_DB_AUTH_SOURCE=admin \
-e YAPI_MAIL_ENABLE=false \
-e YAPI_PLUGINS=[] \
jayfong/yapi

✅ 后面有再补充,安装这些还是建议先看官方的安装步骤

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值