WSL 2将支持GPU,还能运行GUI应用!
1. 安装WSL 2
1.1 Windows系统版本需要
WSL 2仅适用于Windows 10版本18917或更高版本。
Windows版本验证,命令常规中用ver检测:
1 2 3 | C:\Users\kylin>ver Microsoft Windows [版本10.0.18362.778] |
1.2 Windows更新与Windows预览体验计划开启
具体相关操作可以参考https://docs.microsoft.com/zh-cn/windows/wsl/wsl2-install下的相关视频。
Important
Currently to update to Windows 10, version 2004 (Build 19041), you will need to join the Windows Insider program and select the “Release Preview” ring. The public release should arrive by late May.
Windows系统更新完毕后检测系统版本:
1 2 3 4 5 6 | Microsoft Windows [版本 10.0.19624.1000] (c) 2020 Microsoft Corporation. 保留所有权利。 C:\Users\kylin>ver Microsoft Windows [版本 10.0.19624.1000] |
或者选择Windows徽标键+ R来检查Windows版本,键入winver,然后选择“ 确定”。
Windows系统版本符合WSL 2安装使用,继续往下…
1.3启用“虚拟机平台”可选组件并确保启用了WSL
如果使用过WSL 1,则系统已经确保启用了WSL,WSL使用需要开启开发人员模式;
- 没有使用过WSL 1的话,需要确保同时安装了”适用于 Linux 的 Windows 子系统”和”虚拟机平台”可选组件。 可以通过在 PowerShell 中运行以下命令来执行以下操作:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS C:\WINDOWS\system32> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
部署映像服务和管理工具
版本: 10.0.18362.1
映像版本: 10.0.18362.778
启用一个或多个功能
[==========================100.0%==========================]
操作成功完成。
PS C:\WINDOWS\system32> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
部署映像服务和管理工具
版本: 10.0.18362.1
映像版本: 10.0.18362.778
启用一个或多个功能
[=========================== 100.0%==========================]
操作成功完成。
PS C:\WINDOWS\system32> - 启用或关闭Windows功能中选择“适用于Linux的Windows操作系统”和“虚拟机平台”可选组件:
组件选择之后,需要重启计算机来完成两个组件的安装。
1.4下载安装适用于Linux的Windows操作系统
我这里选择Ubuntu,在Windows应用商店中搜索“ Linux”,选择Ubuntu发布相关版本进行下载安装:
下载安装完成之后初次启动需要初始化发行版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 安装,这可能需要几分钟的时间..。 请创建一个默认的UNIX用户帐户。用户名不需要与您的Windows用户名匹配。 有关更多信息,请访问:https : //aka.ms/wslusers 输入新的UNIX用户名:Ubuntu adduser:请输入与通过NAME_REGEX [ _SYSTEM ]配置变量配置的正则表达式匹配的用户名。使用` --force-badname ` 选项放松这个检查或重新配置NAME_REGEX。 输入新的UNIX用户名:ubuntu 新密码: 重新输入新密码: passwd:密码更新成功 安装成功! 要以管理员身份(用户“ root” )运行命令,请使用“ sudo <command>” 。见“人sudo_root” 的详细信息。欢迎使用Ubuntu 20.04 LTS ( GNU / Linux 4.4.0-19624-Microsoft x86_64 ) *文档:https: //help.ubuntu.com *管理:https: //landscape.canonical.com *支持:https:// ubuntu .COM /优势 系统信息,周二5月12日11点44分32秒CST 2020 系统负载:0.52用户登录:0 用法/家:未知的IPv4地址为 ETH4:192.168.189.1 内存使用:44%的IPv4地址为 eth5:192.168.234.1 交换用法:0%IPv4地址用于 wifi0:192.168.0.8 流程:7次0更新可以立即进行安装。这些更新中有0个是安全更新。可用更新的列表是更超过一个星期了。要检查是否有新更新,请运行:sudo apt update 该消息每天显示一次。要禁用它,请创建/home/ubuntu/.hushlogin文件。 ubuntu @ kylin:?$ |
上述被翻译出问题!!!
此用户帐户用于启动发行版本时的登录的非管理员用户。
更新和升级分发版的包
大多数分发版随附了一个空的/精简的包目录。 我们强烈建议定期更新包目录,并使用分发版的首选包管理器升级已安装的包。 在 Debian/Ubuntu 上使用 apt:
1 | ubuntu@kylin:$ sudo apt update && sudo apt upgrade |
Windows不会自动更新或升级Linux发行版:Linux用户经常意外自行控制此任务。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ubuntu@kylin:?$ wslfetch ./+o+- Windows 10 Linux Subsystem yyyyy. 'yyyyyy+ root@kylin .;//+/////h yyyyyyo BUILD: 19624 .++ .:/++++++/-.`sss/` BRANCH: rs_prerelease .:++o: `\++++++++/:---:/- RELEASE: Ubuntu 20.04 LTS o:+o+:++. `````'-/ooo+++++\ KERNEL: Linux 4.19.104-microsoft-standard .:+o:+o/. `+sssooo+\ UPTIME: 0d 0h 2m .++/+ +oo+o:` \sssooo; /+++//+: oo+o \+/+o+++ o++o ydddhh+ .++.o+ +oo+:` /dddhhh; .+.o+oo:. oddhhhh+ \+.++o+o` -,,,,.:ohdhhhhh+ `:o+++ ohhhhhhhhyo++os: .o: .syhhhhhhh'.oo++o. /osyyyyyyy.oooo+++\ `````+oo+++o:/ `oo++'` root@kylin:~# lsb_release -a | lolcat No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04 LTS Release: 20.04 Codename: focal ubuntu @ kylin:/ $ sudo apt install lolcat |
1.5 使用命令行设置要由WSL 2支持的发行版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | Windows PowerShell 版权所有(C) Microsoft Corporation。保留所有权利。 安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows PS C:\Users\kylin> wsl -help 命令行选项无效: -help 版权所有 (c) Microsoft Corporation. 保留所有权利。 使用情况: wsl.exe [Argument] [Options...] [CommandLine] 用于运行 Linux 二进制文件的参数: 如果未提供命令行,wsl.exe 将启动默认 shell。 --exec、-e <命令行> 执行指定的命令而不使用默认的 Linux shell。 -- 按原样传递剩余的命令行。 选项: --distribution、-d <发行版本> 运行指定的分发。 --user、-u <UserName> 以指定用户身份运行。 用于管理适用于 Linux 的 Windows 子系统的参数: --export <发行版本> <文件名> 将分发导出到 tar 文件。 对于标准输出,文件名可以是 -。 --import <发行版> <安装位置> <文件名> [Options] 将指定的 tar 文件作为新分发进行导入。 对于标准输入,文件名可以是 -。 选项: --version <版本> 指定用于新分发的版本。 --list、-l [Options] 列出分发。 选项: --all 列出所有分发,包括当前正在 安装或卸载的分发。 --running 只列出当前正在运行的分发。 --quiet、-q 只显示分发名称。 --verbose、-v 显示有关所有分发的详细信息。 --set-default、-s <发行版本> 将分发设置为默认值。 --set-default-version <版本> 更改新分发的默认安装版本。 --set-version <发行版本> <版本> 更改指定分发的版本。 --shutdown 立即终止所有正在运行的分发和 WSL 2 轻型工具虚拟机。 --terminate, -t <发行版本> 终止指定的分发。 --unregister <发行版本> 注销分发并删除启动文件系统。 --help 显示使用情况信息。 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | Windows PowerShell 版权所有(C) Microsoft Corporation。保留所有权利。 安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows PS C:\Users\kylin> wsl -l --all 适用于 Linux 的 Windows 子系统分发版: Legacy (默认) Ubuntu-20.04 PS C:\Users\kylin> wsl -l -v NAME STATE VERSION * Legacy Stopped 1 Ubuntu-20.04 Running 1 PS C:\Users\kylin> wsl --set-version Ubuntu-20.04 2 正在进行转换,这可能需要几分钟时间... 有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2 转换完成。 PS C:\Users\kylin> wsl -l -v NAME STATE VERSION * Legacy Stopped 1 Ubuntu-20.04 Stopped 2 PS C:\Users\kylin> wsl --set-version Legacy 2 正在进行转换,这可能需要几分钟时间... 有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2 旧分发不支持 WSL 2。 PS C:\Users\kylin> wsl -l 适用于 Linux 的 Windows 子系统分发版: Legacy (默认) Ubuntu-20.04 PS C:\Users\kylin> wsl -s Ubuntu-20.04 PS C:\Users\kylin> wsl -l 适用于 Linux 的 Windows 子系统分发版: Ubuntu-20.04 (默认) Legacy |
Legacy (默认)是WSL初期发行时的Bash on Ubuntu on Windows,该发行版不支持WSL 2。
1.6 下载安装Windows Terminal
下载安装Windows Terminal方便同时使用PowerShell、Ubuntu、Bash on Ubuntu on Windows等CLI。
在应用商店中搜索“Terminal”,进行下载安装。
给Windows Terminal设置像cmd一样的快捷启动方式:
- 打开“编辑系统环境变量”;
- 新建用户变量:
变量名 wt ,值 C:\Users\kylin(用户名)\AppData\Local\Microsoft\WindowsApps\wt.exe
保存成功之后就可以在运行中输入wt打开Windows Terminal。
2. WSL 2 Linux系统设置
2.1 WSL 修改默认登录用户为root
1 2 3 4 5 6 7 8 9 | #WSL修改默认登录用户为根本,管理员用户打开CMD运行以下命令: Microsoft Windows [版本 10.0.19624.1000] (c) 2020 Microsoft Corporation. 保留所有权利。 C:\WINDOWS\system32> C:\Users\kylin(用户名)\AppData\Local\Microsoft\WindowsApps\ubuntu2004.exe config --default-user root C:\WINDOWS\system32> net stop lxssmanager LxssManagerManager服务正在停止。 LxssManager服务已启动成功停止。 C:\WINDOWS\system32> |
再次打开Ubuntu-20.04就是root用户。
2.2 root用户设置密码
1 2 3 4 5 6 7 8 | ubuntu@kylin:~$ sudo passwd root [sudo] password for ubuntu: New password: Retype new password: passwd: password updated successfully ubuntu@kylin:~$ su root Password: root@kylin:/home/ubuntu# |
2.3 Ubuntu- 20.04更新阿里源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | root@kylin:/# cp /etc/apt/sources.list /etc/apt/sourses.list.bak root@kylin:/# vi /etc/apt/sources. #删除文件中内容并添加以下内容: deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb 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 main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse #更新升级 root@kylin:$ sudo apt update && sudo apt upgrade |
2.4 Ubuntu 检测ssh与ufw服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | root@kylin:/# service ssh status * sshd is not running root@kylin:/# service ssh start * Starting OpenBSD Secure Shell server sshd sshd: no hostkeys available -- exiting. root@kylin:/# sshd -T sshd: no hostkeys available -- exiting. root@kylin:/# ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key root@kylin:/# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key root@kylin:/etc/ssh# sshd -T port 22 addressfamily any listenaddress [::]:22 listenaddress 0.0.0.0:22 usepam yes logingracetime 120 x11displayoffset 10 maxauthtries 6 maxsessions 10 clientaliveinterval 0 clientalivecountmax 3 streamlocalbindmask 0177 permitrootlogin without-password ignorerhosts yes ignoreuserknownhosts no hostbasedauthentication no hostbasedusesnamefrompacketonly no pubkeyauthentication yes kerberosauthentication no kerberosorlocalpasswd yes kerberosticketcleanup yes gssapiauthentication no gssapicleanupcredentials yes gssapikeyexchange no gssapistrictacceptorcheck yes gssapistorecredentialsonrekey no gssapikexalgorithms gss-gex-sha1-,gss-group14-sha1- passwordauthentication no kbdinteractiveauthentication no challengeresponseauthentication no printmotd no printlastlog yes x11forwarding yes x11uselocalhost yes permittty yes permituserrc yes strictmodes yes tcpkeepalive yes permitemptypasswords no compression yes gatewayports no usedns no allowtcpforwarding yes allowagentforwarding yes disableforwarding no allowstreamlocalforwarding yes streamlocalbindunlink no fingerprinthash SHA256 exposeauthinfo no pidfile /run/sshd.pid xauthlocation /usr/bin/xauth ciphers [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] macs [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 banner none forcecommand none chrootdirectory none trustedusercakeys none revokedkeys none securitykeyprovider internal authorizedprincipalsfile none versionaddendum none authorizedkeyscommand none authorizedkeyscommanduser none authorizedprincipalscommand none authorizedprincipalscommanduser none hostkeyagent none kexalgorithms curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256 casignaturealgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],ssh-ed25519,[email protected],rsa-sha2-512,rsa-sha2-256 hostbasedacceptedkeytypes [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],ssh-ed25519,[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa hostkeyalgorithms [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],ssh-ed25519,[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa pubkeyacceptedkeytypes [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],ssh-ed25519,[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa rdomain none loglevel INFO syslogfacility AUTH authorizedkeysfile .ssh/authorized_keys .ssh/authorized_keys2 hostkey /etc/ssh/ssh_host_rsa_key hostkey /etc/ssh/ssh_host_ecdsa_key hostkey /etc/ssh/ssh_host_ed25519_key acceptenv LANG acceptenv LC_* authenticationmethods any subsystem sftp /usr/lib/openssh/sftp-server maxstartups 10:30:100 permittunnel no ipqos lowdelay throughput rekeylimit 0 0 permitopen any permitlisten any permituserenvironment no pubkeyauthoptions none root@kylin:/etc/ssh# service ssh start * Starting OpenBSD Secure Shell server sshd [ OK ] #Ubuntu的防火墙状态检测,防火墙可能限制SSH端口22 root@kylin:~# service ufw status * Firewall is not running... [fail] root@kylin:~# |
2.5 ssh本地免密登陆
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | root@kylin:/# ssh localhost root@localhost: Permission denied (publickey). root@kylin:/# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa Your public key has been saved in /root/.ssh/id_rsa.pub The key fingerprint is: SHA256:9VAHvCaC5qpmdHnyQ67jo2uhRwChWHKYuLUDVFIDAD8 root@kylin The key`s randomart image is: +---[RSA 3072]----+ |XB*+ .o.. | |O=o . ... | |++E. . o . | |o o. o ...oo | | . . + S. o. | | + + + | | + o B | |. = + + | | =+=o+ . | +----[SHA256]-----+ root@kylin:/# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys root@kylin:/# chmod 0600 ~/.ssh/authorized_keys root@kylin:/# ssh localhost Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.19.104-microsoft-standard x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Wed May 13 12:35:01 CST 2020 System load: 0.0 Processes: 22 Usage of /: 0.5% of 250.98GB Users logged in: 0 Memory usage: 1% IPv4 address for eth0: 172.28.150.27 Swap usage: 0% 0 updates can be installed immediately. 0 of these updates are security updates. The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. root@kylin:~# exit logout Connection to localhost closed. |
2.6 Ubuntu 远程ssh失败问题解决
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # 其他主机 ssh 失败,scp 远程拷贝文件失败 root@kylin:~# ssh [email protected] [email protected]: Permission denied (publickey). #远程主机修改 /etc/ssh/sshd_config PasswordAuthentication no 改为 PasswordAuthentication yes root@kylin:~# ssh [email protected] [email protected]'s password: Permission denied, please try again. [email protected]'s password: Permission denied, please try again. [email protected]'s password: [email protected]: Permission denied (publickey,password).' #远程主机修改 /etc/ssh/sshd_config PermitRootLogin prohibit-password 改为 PermitRootLogin yes root@kylin:~# service ssh restart * Restarting OpenBSD Secure Shell server sshd [ OK ] |
2.7 Ubuntu安装jdk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | root@kylin:~# mkdir scpfile #解压文件 root@kylin:~/scpfile# tar -zxvf jdk-8u181-linux-x64.tar.gz -C /usr/java/ root@kylin:~/scpfile# cd /usr/java/ #更改文件夹用户组和用户名 root@kylin:/usr/java# chown -R root:root jdk1.8.0_181/ root@kylin:/usr/java# ln -sf /usr/java/jdk1.8.0_181 /usr/java/latest root@kylin:/usr/java# ln -sf /usr/java/latest /usr/java/default root@kylin:/usr/java# ll total 12 drwxr-xr-x 3 root root 4096 May 13 17:29 ./ drwxr-xr-x 15 root root 4096 May 13 17:12 ../ lrwxrwxrwx 1 root root 16 May 13 17:29 default -> /usr/java/latest/ drwxr-xr-x 7 root root 4096 Jul 7 2018 jdk1.8.0_181/ lrwxrwxrwx 1 root root 22 May 13 17:29 latest -> /usr/java/jdk1.8.0_181/ root@kylin:/usr/java# sudo vim /etc/profile #--- #添加 Java 相关的环境变量到/etc/profile export JAVA_HOME=/usr/java/latest export PATH=$JAVA_HOME/bin:$PATH #--- root@kylin:/usr/java# source /etc/profile root@kylin:/usr/java# echo $JAVA_HOME /usr/java/latest root@kylin:/usr/java# java -version java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode) root@kylin:/usr/java# |
2.8 Ubuntu 添加用户组和用户
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | root@kylin:~# sudo groupadd hadoop root@kylin:~# sudo useradd -s /bin/bash -g hadoop -d /home/hadoop -m hadoop root@kylin:~# echo hadoop | passwd --stdin hadoop passwd: unrecognized option '--stdin' Usage: passwd [options] [LOGIN] Options: -a, --all report password status on all accounts -d, --delete delete the password for the named account -e, --expire force expire the password for the named account -h, --help display this help message and exit -k, --keep-tokens change password only if expired -i, --inactive INACTIVE set password inactive after expiration to INACTIVE -l, --lock lock the password of the named account -n, --mindays MIN_DAYS set minimum number of days before password change to MIN_DAYS -q, --quiet quiet mode -r, --repository REPOSITORY change password in REPOSITORY repository -R, --root CHROOT_DIR directory to chroot into -S, --status report password status on the named account -u, --unlock unlock the password of the named account -w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS -x, --maxdays MAX_DAYS set maximum number of days before password change to MAX_DAYS root@kylin:~# sudo passwd hadoop New password: Retype new password: passwd: password updated successfully # 给hadoop用户与root一般的权限 root@kylin:~# echo "%hadoop ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers root@kylin:~# cat /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d %hadoop ALL=(ALL) NOPASSWD: ALL |
2.9 创建系统初始化和服务初始化文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | # 2.9.1 创建系统初始化文件 root@kylin:~# touch InitSystem root@kylin:~# chmod u+x InitSystem root@kylin:~# vim InitSystem root@kylin:~# cat InitSystem | lolcat #!/bin/bash #InitSystem.sh ########################### #Linux(Ubuntu) System Init #Author kylin ########################### WORK_DIR=$(pwd) #Only root [[ $EUID -ne 0 ]] && echo 'Error: This script must be run as root!' && exit 1 #Enable ssh service ssh start root@kylin:~# ./InitSystem * Starting OpenBSD Secure Shell server sshd [ OK ] # 2.9.2 创建系统服务Enable文件,方便开启相关服务 root@kylin:~# touch InitService root@kylin:~# chmod u+x InitService root@kylin:~# cat InitSystem >> InitService root@kylin:~# vim InitService root@kylin:~# cat InitService | lolcat #!/bin/bash #InitService ############################## #Linux(Ubuntu) Service Enable #Author kylin ############################## WORK_DIR=$(pwd) #Only root [[ $EUID -ne 0 ]] && echo 'Error: This script must be run as root!' && exit 1 #IP Addr. ip=`ifconfig eth0 | egrep -o "inet [^ ]*" | grep -o "[0-9.]*"` echo "$ip cloudera.kylin.com cloudera" >> /etc/hosts # 由于WSL目前不知道如何使用静态IP,并且WSL中的/etc/hosts文件是根据Windows系统自动生成的,每次重启会清除上述IP的添加信息, # 所以上述配置在这里合时宜,行的通。如果需要固定一些配置,则可以将内容写入/etc/wsl.conf。 #Enable ssh service ssh restart #Disnable ufw service ufw stop #Enable mysql service service mysql restart #Enable Httpd service apache2 restart |
WSL 2 不能使用systemctl 指令,可以选择书写服务等初始化文件:
1 2 3 4 5 6 | root@kylin:~# systemctl status mysql System has not been booted with systemd as init system (PID 1). Can`t operate. Failed to connect to bus: Host is down # 这是因为WSL是Windows的一个子服务,终端中无法重启Windows的服务.我们无法使用reboot或使用systemctl命令来管理systemd服务。 # net stop lxssmanager |
WSL 2 相关链接:
Docker Desktop WSL2 backend
相关博文-WSL2作为生产力工具