ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

WSL2初体验之使用 docker版 Ubuntu 18.04,VNC远程控制

2020-12-31 12:04:17  阅读:405  来源: 互联网

标签:linux 初体验 VNC 18.04 ubuntu apt 软件包 4.15 com


一、前言

以前用 Oracle VM VirtualBox,玩 CentOS 7,时不时就卡一些,而且还不流畅(我喜欢平滑顺畅完美);无意中发现了 windows WSL2发布了,感觉很溜啊!内嵌子系统,高大上啊!如果你感兴趣,接着看文章吧。借鉴了很多大佬的经验帖子。

二、基础知识准备

  • docker 镜像、容器等概念要理解,常用命令要熟悉。
  • ubuntu 与 centOS 常用命令要区分,要会用;ubuntu 18 安装软件用:apt-get
  • 要保持会折腾的心,要会静心、有耐心。

三、坑,很多很多坑,_(´ཀ`」∠)_吐了

  • 1.Docker Desktop 安装后,不要对 WIN10优化启动项,让它自启动(重复3遍~~~)。让我o(╥﹏╥)o会儿,我又重装了它。
  •  

  • 2.看看如下:Windows 终端 powerShell,炫不? 可以美化的。
  • 提前做好 "容器"的端口映射,因为要用 VNC连接;docker run -it -d --name u18-mine -h u18-mine -p 127.0.0.1:5901:5901 -v //g/u18home/soft:/u18home/soft ubuntu:18.04
  • 不然,你"容器"中的系统搞了一遍,发现端口不对,你只能去各种倒腾修改 docker配置了。o(╥﹏╥)o
  •  

  • 3.进入 docker ubuntu后,不要着急下载软件。先去 更换国内源。防止,下错软件版本。以免造成依赖死循环。

  • 4.如果你像我一样,基于下边那个镜像 pull,恭喜,各种命令都没有,ORZ~~~,连 sudo/nano/vi/vim/gcc等也没有。

  •  

  • 5.进入 ubuntu后,不要直接装 KDE桌面,没有那么容易(我还没成功);先装个xfce4,兼容性好些,VNC 也可以远程连上。

  • 6.不要轻易执行:docker rm <CONTAINER ID>,你会后悔的,刚才搞了一遍,一条命令回到解放前,ε=(´ο`*)))唉。

  • 7.想起来,再补充。

四、WSL2

适用于 Linux 的 Windows 子系统安装指南 (Windows 10)

https://docs.microsoft.com/zh-cn/windows/wsl/install-win10#update-to-wsl-2

安装和设置 Windows 终端

https://docs.microsoft.com/zh-cn/windows/terminal/get-started

Windows Terminal 美化实例

https://zhuanlan.zhihu.com/p/76436374

Windows Terminal 美化主题配色

https://windowsterminalthemes.dev/

1.

2.

3.

4.

5.示例

    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "colorScheme": "DimmedMonokai",
                "hidden": false,
                "useAcrylic": true,
                "acrylicOpacity": 0.75
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "Command Prompt",
                "commandline": "cmd.exe",
                "colorScheme": "DimmedMonokai",
                "hidden": false,
                "useAcrylic": true,
                "acrylicOpacity": 0.75
            },
            {
                "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
                "hidden": false,
                "name": "Ubuntu-18.04",
                "source": "Windows.Terminal.Wsl"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            }
        ]
    },
   "schemes": [
        {
            "name": "BirdsOfParadise",
            "black": "#573d26",
            "red": "#be2d26",
            "green": "#6ba18a",
            "yellow": "#e99d2a",
            "blue": "#5a86ad",
            "purple": "#ac80a6",
            "cyan": "#74a6ad",
            "white": "#e0dbb7",
            "brightBlack": "#9b6c4a",
            "brightRed": "#e84627",
            "brightGreen": "#95d8ba",
            "brightYellow": "#d0d150",
            "brightBlue": "#b8d3ed",
            "brightPurple": "#d19ecb",
            "brightCyan": "#93cfd7",
            "brightWhite": "#fff9d5",
            "background": "#2a1f1d",
            "foreground": "#e0dbb7"
        },
        {
            "name": "BlulocoDark",
            "black": "#4a505d",
            "red": "#f81141",
            "green": "#23974a",
            "yellow": "#fd7e57",
            "blue": "#285bff",
            "purple": "#8c62fd",
            "cyan": "#366f9a",
            "white": "#ccd5e5",
            "brightBlack": "#61697a",
            "brightRed": "#fc4a6d",
            "brightGreen": "#37bd58",
            "brightYellow": "#f6be48",
            "brightBlue": "#199ffd",
            "brightPurple": "#fc58f6",
            "brightCyan": "#50acae",
            "brightWhite": "#ffffff",
            "background": "#1e2127",
            "foreground": "#abb2bf"
        },
        {
            "name": "DimmedMonokai",
            "black": "#3a3d43",
            "red": "#be3f48",
            "green": "#879a3b",
            "yellow": "#c5a635",
            "blue": "#4f76a1",
            "purple": "#855c8d",
            "cyan": "#578fa4",
            "white": "#b9bcba",
            "brightBlack": "#888987",
            "brightRed": "#fb001f",
            "brightGreen": "#0f722f",
            "brightYellow": "#c47033",
            "brightBlue": "#186de3",
            "brightPurple": "#fb0067",
            "brightCyan": "#2e706d",
            "brightWhite": "#fdffb9",
            "background": "#1f1f1f",
            "foreground": "#b9bcba"
        }                  
    ],

五、WSL2安装Docker

按照以下2步骤,你就不用担心拉取的镜像,创建的容器占用C盘了。

https://zhuanlan.zhihu.com/p/163763066

WSL2 Docker Distro迁移

https://blog.csdn.net/simongame/article/details/107032441

六、ubuntu18初体验

1.每次,以 root用户身份进入;更改“软件源地址”。

cp   /etc/apt/sources.list   /etc/apt/sources.list.bak

想要编辑,使用 vim,安装缺提示:E: Unable to locate package vim

https://blog.csdn.net/miss1181248983/article/details/88578287

deb http://archive.ubuntu.com/ubuntu/trusty main universe restricted multiverse这个地址添加到/etc/apt/sources.list文件中,然后 apt-get update更新完之后安装就可以了。

echo deb http://archive.ubuntu.com/ubuntu/trusty main universe restricted multiverse >> /etc/apt/sources.list

https://blog.csdn.net/u012308586/article/details/102953882

阿里源:

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

#更新软件列表,换源完成。就可以安装匹配的想要的各种命令了。

apt-get update

#配置GCC

apt-get  install  build-essential

2.基于命令行更新软件包的方法

https://blog.csdn.net/davidhzq/article/details/102671746

Ubuntu主要更新升级命令介绍
        我们先来看看这几个命令的功能和区别,这几个命令看起来很相似,作用上有较大差别千万不要弄错了。

  • apt-get update
    从服务器获取全部可用的、最新的软件包列表,并缓存到本地电脑。执行效果如下。
  • 
    hzq@ubuntu:~$ sudo apt-get update
    [sudo] hzq 的密码: 
    命中:1 http://mirrors.yun-idc.com/ubuntu xenial InRelease
    命中:2 http://mirrors.yun-idc.com/ubuntu xenial-updates InRelease
    命中:3 http://mirrors.yun-idc.com/ubuntu xenial-backports InRelease
    命中:4 http://mirrors.yun-idc.com/ubuntu xenial-security InRelease
    正在读取软件包列表... 完成  
    hzq@ubuntu:~$
    

     

  • apt-get upgrade
    这个命令,会把本地已安装的软件,与刚下载的软件列表里对应软件进行对比,如果发现已安装的软件版本太低,就会提示你更新。upgrade 不会删除在列表中已经没有的软件包,也不会安装有依赖需求但尚未安装的软件包。执行效果如下。
  • 
    hzq@ubuntu:~$ sudo apt-get upgrade
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    正在计算更新... 完成
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
    hzq@ubuntu:~$
    

     

  • apt-get full-upgrade
    根据列表信息,对需要升级的软件包进行完整安装。也就是先删除软件,然后完整地重新安装整个软件。所以要注意,这个功能是会删除软件的,所以执行此命令之前最好备份一下。执行效果如下。
  • 
    hzq@ubuntu:~$ sudo apt-get full-upgrade
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    正在计算更新... 完成
    下列软件包是自动安装的并且现在不需要了:
      linux-headers-4.15.0-45 linux-headers-4.15.0-45-generic linux-image-4.15.0-45-generic
      linux-modules-4.15.0-45-generic linux-modules-extra-4.15.0-45-generic snapd-login-service
    使用'sudo apt autoremove'来卸载它(它们)。
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
    hzq@ubuntu:~$
    

     

  • apt-get dist-upgrade
    dist-upgrade 可能会为了解决软件包冲突而删除一些已安装的软件包,也可能会为了解决软件包依赖问题安装新的软件包。执行效果如下。
  • 
    hzq@ubuntu:~$ sudo apt-get dist-upgrade
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树
    正在读取状态信息... 完成       
    正在计算更新... 完成
    下列软件包是自动安装的并且现在不需要了:
      linux-headers-4.15.0-45 linux-headers-4.15.0-45-generic linux-image-4.15.0-45-generic
      linux-modules-4.15.0-45-generic linux-modules-extra-4.15.0-45-generic snapd-login-service
    使用'sudo apt autoremove'来卸载它(它们)。
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
    

     

  • apt list --upgradable
    根据列表对比信息,看看有哪些可更新的软件,如果没有则显示为空。执行效果如下。
  • 
    hzq@ubuntu:~$ sudo apt list --upgradable
    正在列表... 完成
    hzq@ubuntu:~$
    

     

  • apt-get autoremove
    一般来说,更新完成之后会有一些不需要的旧组件需要清除。此时使用apt autoremove即可完成清理。执行效果如下。
  • 
    hzq@ubuntu:~$ sudo apt-get autoremove
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树       
    正在读取状态信息... 完成       
    下列软件包将被【卸载】:
      linux-headers-4.15.0-45 linux-headers-4.15.0-45-generic linux-image-4.15.0-45-generic
      linux-modules-4.15.0-45-generic linux-modules-extra-4.15.0-45-generic snapd-login-service
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 6 个软件包,有 0 个软件包未被升级。
    解压缩后将会空出 335 MB 的空间。
    您希望继续执行吗? [Y/n] y
    (正在读取数据库 ... 系统当前共安装有 251733 个文件和目录。)
    正在卸载 linux-headers-4.15.0-45-generic (4.15.0-45.48~16.04.1) ...
    正在卸载 linux-headers-4.15.0-45 (4.15.0-45.48~16.04.1) ...
    正在卸载 linux-modules-extra-4.15.0-45-generic (4.15.0-45.48~16.04.1) ...
    正在卸载 linux-image-4.15.0-45-generic (4.15.0-45.48~16.04.1) ...
    /etc/kernel/postrm.d/initramfs-tools:
    update-initramfs: Deleting /boot/initrd.img-4.15.0-45-generic
    /etc/kernel/postrm.d/zz-update-grub:
    Generating grub configuration file ...
    Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
    Found linux image: /boot/vmlinuz-4.15.0-65-generic
    Found initrd image: /boot/initrd.img-4.15.0-65-generic
    Found linux image: /boot/vmlinuz-4.15.0-64-generic
    Found initrd image: /boot/initrd.img-4.15.0-64-generic
    Found memtest86+ image: /boot/memtest86+.elf
    Found memtest86+ image: /boot/memtest86+.bin
    done
    正在卸载 linux-modules-4.15.0-45-generic (4.15.0-45.48~16.04.1) ...
    正在卸载 snapd-login-service (1.33-0ubuntu0.16.04.1) ...
    正在处理用于 dbus (1.10.6-1ubuntu3.4) 的触发器 ...
    hzq@ubuntu:~$
    

     

  • 通常情况升级更新步骤
    下面给出一般情况的操作流程,你当然可以根据上面命令的含义自己组合使用。
  • 
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt list --upgradable //如果没有了,就直接重启
    sudo apt-get dist-upgrade
    sudo reboot
    sudo apt list –upgradable //重启之后再看一眼
    

     

3.出错、异常处理

  • ubuntu错误:No usable dialog-like program is installed
  • 那么可能只是因为系统原程序没有正确安装的原因,可以运行:apt-get update && apt-get dist-upgrade
  • Ubuntu下提示E: dpkg was interrupted

    mv /usr/bin/localedef /usr/bin/localedef.old
           dpkg --configure -a

  •  

七、Xfce4 桌面安装

为什么首选它?因为,稳定、兼容性好,又能实现 VNC远程连接,KDE想用,还没成功。

https://blog.csdn.net/fxb163/article/details/84193098

https://cloud.tencent.com/developer/article/1350304

https://www.linuxidc.com/linux/2018-08/153435.htm

在安装Xfce前需要更新一下系统

sudo apt-get update

安装Xfce

sudo apt install xfce4 xfce4-goodies

安装期间好像会出现几次弹窗,让你选择,仔细阅读下英文就理解了。

安装VNC Server

sudo apt-get install vnc4server

启动VNC Server(第一次启动VNC Server时会要求设置密码)

vncserver

另外,还需要修改xstartup文件内容(否则在通过VNC远程连接时会出现灰屏现象)

vim ~/.vnc/xstartup
#!/bin/sh  
unset SESSION_MANAGER  
unset DBUS_SESSION_BUS_ADDRESS  
startxfce4 & 

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup  
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources  
xsetroot -solid grey 

Esc,输入:wq!保存退出。

关闭之前开启的VNC Server窗口

vncserver -kill :1   #注意kill之后有空格

再次启动VNC Server

八、远程连接 VNCSERVER

下载 VNC-Viewer:https://www.realvnc.com/en/connect/download/viewer/

 

 

标签:linux,初体验,VNC,18.04,ubuntu,apt,软件包,4.15,com
来源: https://blog.csdn.net/yanfei_1986/article/details/111991823

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有