win 10安装配置Ubuntu子系统


windows 10安装Ubuntu子系统

1.首先到微软商店下载

下载地址:https://aka.ms/wslstore

2.更换源并更新系统

root@Lanever-PC:~# uname -a
Linux Lanever-PC 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux
root@Lanever-PC:~# lsb_release -a   #显示LSB和特定版本的所有信息
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic
root@Lanever-PC:~# cp /etc/apt/sources.list /etc/apt/sources.list.bak   #备份源
root@Lanever-PC:~# vim /etc/apt/sources.list
# 阿里源
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-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports 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/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
root@Lanever-PC:~# apt-get update && apt-get upgrade -y


Ubuntu 20.04 LTS国内适用源:

root@afeicomputer:~# cat /etc/apt/sources.list
# 阿里源
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/ xenial main restricted universe multiverse
# 中科大
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
root@afeicomputer:~#

3.子系统Ubuntu安装桌面环境并实现远程连接

(1)X-Windows介绍

    Windows X服务器基于xorg git源(例如xming或cygwin的xwin),但使用Visual C ++ 2012 Express Edition进行编译。源代码也可以使用VS2008,VS2008 Express Edition和VS2010 Express Edition进行编译,尽管当前项目和makefile不再完全兼容。

    从1.14.3.0开始的版本不再与Windows XP兼容。
X-Windows下载地址:https://sourceforge.net/projects/vcxsrv/
    

(2)配置X-Windows连接Ubuntu

在这里插入图片描述
可自行选择桌面,选择多桌面或者全屏桌面,Display number设置成0
在这里插入图片描述
其他的保持默认就行
在这里插入图片描述

    

(3)Ubuntu安装桌面环境

root@Lanever-PC:~# apt-get install ubuntu-desktop unity compizconfig-settings-manager -y  

启动安装的X-Windows:

root@Lanever-PC:~# export DISPLAY=localhost:0
root@Lanever-PC:~# ccsm
compizconfig - Info: Backend     : ini
compizconfig - Info: Integration : true
compizconfig - Info: Profile     : default
Loading icons...

会弹出ccsm的配置界面,勾选需要的Desktop组件(一般只需要勾选Desktop中的Ubuntu Unity Plugin即可,其它默认就好)
在这里插入图片描述
配置完成关闭ccsm
在这里插入图片描述

    
启动compiz

root@Lanever-PC:~# compiz
compiz (core) - Info: Loading plugin: core
compiz (core) - Info: Starting plugin: core
compiz (core) - Info: Loading plugin: ccp
compiz (core) - Info: Starting plugin: ccp
compizconfig - Info: Backend     : ini
compizconfig - Info: Integration : true
compizconfig - Info: Profile     : default

在这里插入图片描述
    

4.子系统Ubuntu安装mysql

root@afeicomputer:/mnt/d/Linux/Linux software/ubuntu# wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb --no-check-certificate
root@afeicomputer:/mnt/d/Linux/Linux software/ubuntu# dpkg -i mysql-apt-config_0.8.12-1_all.deb

按Tab键选择"ok“,继续安装:
在这里插入图片描述
选择需要安装的版本:
在这里插入图片描述

root@afeicomputer:/mnt/d/Linux/Linux software/ubuntu# apt-get update && apt-get install lsb-release -y   #更新添加的mysql源
root@afeicomputer:/mnt/d/Linux/Linux software/ubuntu# apt -y install mysql-server

    
设置密码:
在这里插入图片描述

root@afeicomputer:/mnt/d/Linux/Linux software/ubuntu# apt policy mysql-server   #查看软件包是否已安装
mysql-server:
  Installed: 8.0.18-1ubuntu18.04
  Candidate: 8.0.18-1ubuntu18.04
...

启动mysql:发现在子系统Ubuntu中不能用systemctl启动mysql,并且在/etc/init.d下也没有mysql启动脚本。可用如下方式启动:

root@afeicomputer:~# mysqld --user=root  #以root用户启动
...   #并且这时cmd无法结束掉

    
查看进程:

root@afeicomputer:~# netstat -nltup  #服务中无法看到,它以进程形式存在
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
root@afeicomputer:~# ps -aux |grep "mysql"
root       901  0.2  4.8 2740728 401096 ?      Sl   11:06   0:00 mysqld --user=root
root       963  0.0  0.0  14804  1200 tty1     S    11:12   0:00 grep --color=auto mysql
root@afeicomputer:~# mysql -uroot -pcl123456 
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 MySQL Community Server - GPL
...
mysql> \q
Bye
root@afeicomputer:~#

可以在Windows的Cmd中查看mysql端口:

C:\Users\Administrator>netstat -ano |findstr 3306
  TCP    0.0.0.0:3306           0.0.0.0:0              LISTENING       684
  TCP    0.0.0.0:33060          0.0.0.0:0              LISTENING       684

关闭mysql:

root@afeicomputer:~# kill -9 901  #结束mysql进程

    
有时mysqld --user=root可能会启动失败,可用mysqld_safe --user=root启动:

root@afeicomputer:~# mkdir /var/run/mysqld
root@afeicomputer:~# chown mysql:mysql /var/run/mysqld/
root@afeicomputer:~# mysqld_safe --user=root
2020-01-11T02:23:33.918541Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2020-01-11T02:23:34.050317Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

    

5.WSL Ubuntu配置ssh

root@afeicomputer:~# dpkg -l |grep "ssh-server"
ii  openssh-server                 1:8.2p1-4                         amd64        secure shell (SSH) server, for secure access from remote machines
root@afeicomputer:~# vim /etc/ssh/sshd_config   #修改配置文件
...
34 PermitRootLogin yes
...
 58 PasswordAuthentication yes 
...
root@afeicomputer:~# ssh-keygen -A
root@afeicomputer:~# service ssh start
root@afeicomputer:~# service ssh --full-restart
 * Stopping OpenBSD Secure Shell server sshd                                                                     [ OK ]
 * Starting OpenBSD Secure Shell server sshd                                                                     [ OK ]

在这里插入图片描述

root@afeicomputer:~# ps -e |grep ssh   #查看服务是否启动
  517 ?        00:00:00 sshd
root@afeicomputer:~# apt install net-tools -y
root@afeicomputer:~# ifconfig wifi0 |grep 'inet' |awk '{print $2}' |tr -d "addr" |sed -n '1p'   #检索出IP
192.168.1.2

Xshell连接测试:
在这里插入图片描述
    


©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页
实付 19.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值