windows11使用

升级专业版

先断网,再使用官方密钥升级,重启后自行激活。

VK7JG-NPHTM-C97JM-9MPGT-3V66T

安装 Windows Terminal

Windows Store 更新 terminal 到最新版。
配置忽略“是否关闭全部”提示,放在help同级。

    "confirmCloseAllTabs": false,

最新版可在设置中关闭。设置-交互-关闭多个选项卡时发出警告

安装wsl2

官方文档

# 管理员打开powershell
# 默认是Ubuntu20,现在可能是ubuntu22
wsl --install -d Ubuntu

更新apt源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# Aliyun
sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.aliyun.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.aliyun.com@g" /etc/apt/sources.list

中文化

# ubuntu22 无需配置。
sudo apt install language-pack-zh-hans manpages-zh translate-shell
# 更改系统语言 选zh_CN.UTF-8
sudo dpkg-reconfigure locales

启用systemd

官方文档
启用后空载内存由0.8G变成1.1G,且会自动停掉。比如docker等服务不能后台。(待解决)

sudo vim /etc/wsl.conf
[boot]
systemd=true
# docker安装后已由systemd自启,无需配置。
# command = service docker start

禁用IPV6

# 禁用IPV6
sudo vim /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

wsl2 开机自启

# 创建启动脚本(linux下执行)
echo \
"#! /bin/sh
service docker start
" | sudo tee /etc/init.wsl

# 添加可执行权限
sudo chmod +x /etc/init.wsl

然后在Win启动目录添加启动脚本。(参考 #设置程序开机自启

git 配置

# 格式化git log时间
git config --global log.date iso8601
# 忽略文件权限 wsl下的git可配置
git config --global core.filemode false
# 忽略文件行结尾 wsl下的git可配置
git config --global core.autocrlf true

配置git commit模板

touch ~/git_template.md
git config --global commit.template ~/git_template.md

ssh配置

避免ssh自动断开

# 添加一行 (Win下需管理员权限才可以保存)
# C:\Program Files\Git\etc\ssh\ssh_config
# ~/.ssh/config
ServerAliveInterval 30

.bashrc

alias需要用单引号括起来,此时命令中遇到单引号,可以使用多段'不含单引号的字符串'\'拼在一起,中间不能出现空格。

export HOST_IP=$(awk '/^nameserver/ {print $2}' /etc/resolv.conf)

alias 80='sudo python3 -m http.server 80'
alias ip-public='curl https://www.trackip.net/ip'
alias ip-local='hostname -I | awk '\''{print $1}'\'
alias u='sudo apt update && sudo apt upgrade -y'
alias reboot='echo please use sudo'
alias cls='printf "\033c"'
alias uuid='uuid_ori=$(uuidgen);echo ${uuid_ori//-/}'
alias cnpm="npm --registry=https://registry.npmmirror.com \ --cache=$HOME/.npm/.cache/cnpm \ --disturl=https://npmmirror.com/mirrors/node \ --userconfig=$HOME/.cnpmrc"
alias redis-cli='docker exec -it redis redis-cli'
alias dup='docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -c -R'
alias dpsa='docker ps -a --format "table{{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Size}}"'
alias dps='docker ps --format "table{{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Size}}"'
alias dpp='docker ps --format "table{{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}\t{{.Size}}"'
alias dss='docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}"'
alias dlog='docker logs --tail 200 -f '
alias dit='docker exec -it '
alias nginxt='docker exec nginx nginx -t'
alias nginxr='docker exec nginx nginx -t && docker exec nginx nginx -s reload'
alias mkbak='mkdir $(date "+%m%d_%H%M")'
alias to='cd /mnt/d/Documents/java/demos/'
alias r='/home/ubuntu/docker/ready.sh'

gitclone(){
    source=$1
    mirror="gitclone.com/github.com"
    target=$(echo ${source} | sed "s#github.com#${mirror}#")
    echo -e "mirror: \033[1;32;40m ${mirror} \033[0m"
    echo ${target}
    git clone ${target}
}
dockerpull(){
    source=$1
    mirror="dockerproxy.com"
    echo -e "mirror: \033[1;32;40m ${mirror} \033[0m"
    if [[ ! ${source} =~ "/" ]]; then mirror="${mirror}/library";fi
    target="${mirror}/${source}"
    echo ${target}
    docker pull ${target}
    docker tag ${target} ${source} >/dev/null
    docker rmi ${target} >/dev/null
}
update_git(){
    target=.
    if [ $# -ne 0 ];then target=$1;fi
    for dir in $(ls -d ${target}/*/)
    do
      cd $dir
      echo "into $dir"
      if [ -d ".git" ]; then
         git fetch
      fi
      cd ..
    done
}
clean_target(){
    target=.
    if [ $# -ne 0 ];then target=$1;fi
    find ${target} -name target | xargs rm -rf
    #find ${target} -name .idea | xargs rm -rf
    #find ${target} -name *.iml | xargs rm -rf
    echo "Done clean."
}

wsl开启远程登录

没必要设置wsl远程登录,使用Terminal+自带文件管理器\\wsl.localhost即可。
wsl网络默认本机可访问,局域网其他设备访问还需要Win的防火墙放行。

sudo vim /etc/ssh/sshd_config
# 注释掉 PasswordAuthentication no
Port 23 # 端口号 默认22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
PasswordAuthentication yes # 是否允许使用密码登录

设置程序开机自启

一般设置用户启动即可,可在文件管理器地址栏输入,回车跳转。
用户启动项目录(也可输入启动

shell:startup

系统启动项目录

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

有一些程序会占用终端,使用这个脚本可隐藏终端。
bootstrap.vbs

Set ws = WScript.CreateObject("WScript.Shell")
ws.run "wsl -d ubuntu -u root /etc/init.wsl",0
ws.run "D:\Tools\syncthing\syncthing.exe -no-console -no-browser",0

获取win10锁屏壁纸的缓存

C:\Users\%USERNAME%\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets

win10 HEVC解码支持,浏览器打开,自动跳转应用商店。

ms-windows-store://pdp/?ProductId=9N4WGH0Z6VHQ

火狐浏览器开启按钮 列出全部标签页

about:config
# browser.tabs.tabmanager.enabled

idea连接 wsl下的docker

sudo vim /lib/systemd/system/docker.service
# 添加一行
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
# 重启docker生效
sudo service docker restart
# 未启用CA认证,任何人都可以访问该接口
# https://blog.csdn.net/wdq875667601/article/details/119942822

IDEA使用 wsl 中的 Git

设置--Version Control--Git--路径为 \\wsl$\Ubuntu\usr\bin\git
不建议使用wsl下的mvn,jdk等,兼容性不佳。

IDEA内置maven提示0.0.0.0

# 2021.3后内置Maven的版本提升到了3.8.1
# 在setting.xml会增加一个默认镜像maven-default-http-blocker来阻止从HTTP链接下载不安全的依赖库。
# 注释以使用http的私有源
    <!-- <mirror> -->
      <!-- <id>maven-default-http-blocker</id> -->
      <!-- <mirrorOf>external:http:*</mirrorOf> -->
      <!-- <name>Pseudo repository to mirror external repositories initially using HTTP.</name> -->
      <!-- <url>http://0.0.0.0/</url> -->
      <!-- <blocked>true</blocked> -->
    <!-- </mirror> -->

修改RDP端口

运行以下 PowerShell 命令来更改 RDP 端口

$portvalue = 3399

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber" -Value $portvalue

New-NetFirewallRule -DisplayName 'RDPPORTLatest-TCP-In' -Profile 'Public' -Direction Inbound -Action Allow -Protocol TCP -LocalPort $portvalue
New-NetFirewallRule -DisplayName 'RDPPORTLatest-UDP-In' -Profile 'Public' -Direction Inbound -Action Allow -Protocol UDP -LocalPort $portvalue

从Git中清除某个文件的记录 未测试

# path_to_file 要删除的文件
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch path_to_file' HEAD
# 强推
git push -f
# 教程2
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch [敏感文件]' --prune-empty --tag-name-filter cat -- --all
# 示例
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch src/main/resources/application-dev.properties' --prune-empty --tag-name-filter cat -- --all
git push origin master --force
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

End

posted @ 2021-08-19 11:22  一年`  阅读(240)  评论(0编辑  收藏  举报