preface
My computer configuration is not high , Open the virtual machine and run linux Always think too laggy . Only recently learned windows Already wsl2—— A relatively lightweight virtual machine software . So this blog tends to focus on , Save records for multiple use .
Environmental Science
- The host machine windows11
- The goal is : The installation is based on WSL2 Of Ubuntu20.04 Virtual machines and some common software environments .
WSL2 install
You can refer directly to Microsoft Official website manual , Enter the command wsl --install The one-time default installation is completed . But my local configuration is not high , So I use step-by-step installation , To customize the location of virtual machines .
Enable windows function
Set up -> Applications and functions -> Procedures and functions -> Enable or close windows function
start-up windows Of linux Subsystem and virtual machine platform , Open as Administrator Powershell, Run the command
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartRestart the computer for the settings to take effect .
download linux Kernel update package and run update .
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
( Optional ) If you want to default to wsl2, Then set the command
wsl --set-default-version 2. If you want to use it at the same time wsl1 and wsl2, You can download different linux Release settingsversion.wsl --set-version Ubuntu-18.04 2 wsl --set-version Ubuntu-20.04 1download ubuntu20.04 https://aka.ms/wslubuntu2004.( Maybe it's a network problem. The download is very slow , I switched to the Microsoft Store to download it quickly )
Change the file suffix to .zip, Then decompress
double-click exe start-up , Set the account and password according to the prompt , installation is complete .

Configure alicloud image
- In order to improve the Linux Package manager download software speed , modify apt-get Mirror source . Open Alibaba cloud's ubuntu Mirror website https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11YfnocC
- According to the prompt, overwrite the configuration content to
/etc/apt/sources.listIn file ( Remember to back up first ). - And then run the command
sudo apt-get update
------------------------------------ The following installation contents are optional -----------------------------------------
install jdk
Directly in apt Find a download in the source .
sudo apt search jdk
udo apt install openjdk-11-jdk
java -v # Test after downloading
install maven
download : It can be used directly apt Source download maven3.6.3. But because I used to use 3.6.3 Various versions build bug, So I'd better be honest on and off the official website .( Get into maven Official website , Download suffix is bin.tar.gz Version of )
wget https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz # Download package tar -zxf apache-maven-3.8.5-bin.tar.gzConfigure environment variables
sudo vim /etc/profile export M2_HOME=/opt/apache-maven-3.8.5 M2_HOME = /opt/apache-maven-3.8.5 export PATH=${M2_HOME}/bin:$PATH # Add to end of file Run after exiting source /etc/profile Let variables take effect mvn -v # Printing the publication number indicates that the configuration is successfulTo configure maven Alibaba cloud image , Get... Here Mirror address
cd /opt/apache-maven-xxx/conf # Enter the conf Folder vim settings.xml Just paste the code at the specified location .
install mysql
download mysql 8.0 Install the configuration package -> decompression -> to update apt Source -> install mysql 8.0 server
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb # download sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb # Unzip and select configuration sudo apt update # to update sudo apt install mysql-server # download mysql 8.0Create user , Support remote connection
- function
sudo service mysql startStart database . - because mysql8 Of root By default, the account encryption plug-in adopts sock plug-in unit ( namely mysql root The account will only allow the external system user name to be the same name when logging in root The user logs in ). So install mysql It doesn't matter if there is an initialization password , direct
sudo mysqlOpen the can .
sudo mysql use mysql; create user '#userName'@'#host' identified by '#passWord'; # Create the role ,#host Set to %, Allow others on behalf of the account ip Address connection grant all on *.* to '#username'@'%'; # It's easy , Given all permissions . flush privileges; # Refresh Authorization- function
Modify the configuration file
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf take bind-address notes restart mysql The service can be
install python3
Because of my linux Environment comes with itself python, So for the time being, just use . Here also back up a method on the network ( Add source and download ).
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.6
install c and c++
sudo apt update
sudo apt install build-essential # One time installation gcc,g++ and make
install redis
- You can use it directly
sudo apt install redisDownload the version that comes with the warehouse , It's more convenient . Here's a demo of downloading the official website version . - Download and install
wget https://github.com/redis/redis/archive/7.0.0.tar.gz # Download installation package tar -zxf 7.0.0.tar.gz # decompression mv redis /opt/ # Move to custom location sudo make ; # install ( Optional ) sudo make install PREFIX=/opt/redis-7.0.0 # Customize the installation location and install ( Optional ) ./opt/redis-7.0.0/bin/redis-server # function redis-server, If the operation screen appears, it is successful - Create configuration files and service script files
cd /opt/redis-7.0.0 cp redis.conf ./bin/6379.conf# Copy a copy of the configuration file to the software directory , The port number is used as the name for convenience when registering script services later . cp /opt/redis-7.0.0/utils/redis_init_script /etc/init.d/redis # Copy script file , convenient service Command to start - Modify script file
The following parameters are modified according to your actual situation .sudo vim /etc/init.d/redis 14 REDISPORT=6379 15 EXEC=/opt/redis-7.0.0/bin/redis-server 16 CLIEXEC=/opt/redis-7.0.0/bin/redis-cli 17 18 PIDFILE=/var/run/redis_${REDISPORT}.pid 19 CONF="/opt/redis-7.0.0/bin/${REDISPORT}.conf" - Modify the configuration file
sudo vim /opt/redis-7.0.0/bin/6379.conf protected-mode no # Turn off protection mode , Allow writing and reading of remote connections . daemonize yes # Background operation # bind 127.0.0.1 -::1 # Comment on this trip , Allow remote connections - function sudo service redis start
Fix ip
I feel wsl2 At present, one of the more criticized points is wsl2 Of ip Is dynamic , Every time it is completely closed and then opened wsl2 Will update ip, Although... Can be used at present localhost visit wsl2 Server running in , But I still want to try to fix ip. Browse the Forum 、 Blogs and open source communities , Find a simpler way . Write a script on the host ( Can be modified by yourself linux Release name and ip)
wsl -d Ubuntu-20.04 -u root ip addr add 192.168.50.16/24 broadcast 192.168.50.255 dev eth0 label eth0:1 # Note that it must be root
netsh interface ip add address "vEthernet (WSL)" 192.168.50.88 255.255.255.0
Every time you restart wsl Then run the script with administrator privileges .
ps : You don't have to right-click the script every time to use the method of administrator privileges .
- Right click to create a shortcut
- Enter properties , Click Advanced... Under the shortcut

- Check the administrator to run .
Self starting script
wsl2 Not yet systemctl, Therefore, the software cannot start automatically , The open source community provides some of its own imitations Systemctl Software , But it is not perfect yet , So I use it Turn it on + Run scripts automatically To achieve a fool like self starting .
- Create a script on the host ( Or you can add it directly to fix it ip After the script )
- Input
wsl /home/allworldg/startup.sh - Create... In the same location within the virtual machine
/home/allworldg/startup.sh - Edit according to your own situation
startup.sh, for exampleecho '123123'| sudo -S service mysql start # Auto input sudo Password echo '123123'| sudo -S service redis start
Step on the pit
- Because of the modification
/etcFile permissions , Lead to sudo Can't use .- reason : Every time you edit
/etcAll documents have to be addedsudo, It's not good , The picture came directlysudo chown "myusername" -R /etc, The result was later used sudo Wrong orders .sudo: /etc/sudoers is owned by uid 1000, should be 0 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin - Solution : function
pkexec /usr/sbin/visudoCommand is enough . - Because this environment is in wsl2 Next , Using the above command cannot successfully execute , So there are other ways . After consulting, we know that , about WSL for , Can be in CMD perhaps Windows PowerShell Log in with the following command root account number :
wsl -u root. And then modifysudoersandsudoers.ethat will do .chown root:root /etc/sudoers chown -R root:root /etc/sudoers.d
- reason : Every time you edit

![[basic knowledge] ~ hard core / soft core / solid core, pwm/spwm, Fibonacci sequence, large end mode storage, Fourier transform, Nyquist sampling law, chip selection, Kirchhoff law, fir/iir filter](/img/73/626ffd0215f557ade3b9b681adb644.png)







