简介:本文主要介绍ubuntu20.04容器中搭建xfce远程桌面、C++、Go环境、容器内docker操作配置、zsh配置
一、创建容器
1、创建容器
docker pull ubuntu:20.04
docker run -itd --privileged --name=my-desktop--ulimit memlock=-1:-1 --network="network-local" -p 22666:22 -p 5901:5901 -v /var/run/docker.sock:/var/run/docker.sock ubuntu:20.04 /bin/bash
2、进入容器
docker exec -it my-desktop /bin/bash
二、创建普通用户
1、更新apt源以及sudo
apt update && apt install -y sudo
2、创建用户
adduser limstorm
3、赋予用户sudo权限
usermod -aG sudo
4、切换为limstorm用户
su limstorm
5、设置root用户密码,ABCD#1234
sudo passwd root
6、安装vim并更换apt源为阿里源
sudo apt install vim && sudo vim /etc/apt/sources.list
```
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
```
7、更新apt源
sudo apt update
三、安装xface桌面环境,并安装tigervnc, 使用普通用户
1、安装xface以及tigervnc,选择gdm3启动器
sudo apt install xfce4 tigervnc-standalone-server
中间依次输入:6、10、18、30、1、1
2、启动dbus service(xface4启动需连接dbus)
sudo service dbus start
3、设置vnc密码,ABCD#1234
vncpasswd
中间依次输入:密码、密码、n
4、配置vnc xstartup
vim ~/.vnc/xstartup
```
#!/bin/sh
xsetroot -solid grey
startxfce4 &
```
5、启动vncserver,不需要设置geometry,默认会自动调整;:1表示第一个窗口,其端口号为5901(5900+1)
vncserver -localhost no :1
6、tigervncviewer连接,连接地址使用DockerIP:5901或者宿主机IP:映射端口
下载地址:https://sourceforge.net/projects/tigervnc/files/stable/1.13.1/,根据所需下载不同系统版本
7、停止vncserver
vncserver -kill :1
Q&A:
1、打开终端报错:failed to execute default Terminal Emulator
解决办法:
sudo apt-get install xfce4-terminal && sudo apt purge gnome-terminal
然后Applications - Settings - Perfered Applications - Utilities - Terminal Emulator选择Xfce Terminal即可,重新打开终端正常执行
2、打开浏览器报错:failed to execute default Web Browser
解决办法:
(1)安装必要依赖库:sudo apt install firefox
(2)依照终端一样的操作,选择firefox浏览器为默认浏览器,chrome、edge不稳定,容易宕机
四、Docker以及docker-compose安装
1、安装docker.io以及docker-compose
sudo apt install docker.io docker-compose
2、普通用户直接运行docker
sudo gpasswd -a useradmin docker # useradmin是普通用户示例, 需要替换为自己的用户名
newgrp docker # 更新docker用户组
sudo chmod -R 777 /var/run/docker.sock
五、中文语言包安装
1、安装中文语言包
sudo apt-get install language-pack-zh-han*
2、安装ibus拼音
sudo apt-get install ibus ibus-pinyin # 安装ibus拼音
3、设置中文语言以及中文输入法
(1)配置中文语言:
Applications - Setttings - Language Support - Install/Remove Languages - 选择English和Chinese(simplified) - Apply,input method选择IBus,然后Apply System-Wide,close
(2)配置ibus输入法
sudo apt-get install ibus ibus-pinyin # 安装ibus拼音
Applications - Setttings - IBus Preferences - Input Method - Add - Chinese-Pinyin - Add - Close
(3)启动ibus-daemon
nohup ibus-daemon --xim &
(4)登陆自动启动ibus输入法
Applications - Setttings - Session and Startup - Application Autostart - Add - Name: ibus; Description: The ibus input-method; Command: ibus-daemon --xim; Trigger:on login - OK - Close
六、编译环境安装
1、C++及python等环境配置
sudo apt install libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev libgflags-dev git build-essential autoconf gcc g++ ccache libncurses5-dev byacc cmake lcov libprotobuf-dev protobuf-compiler liblz4-dev libreadline-dev libmysqlcppconn-dev libcurl4-openssl-dev libssl-dev gdb valgrind pip libdw-dev zip unzip curl
2、Go环境配置
wget https://dl.google.com/go/go1.15.linux-amd64.tar.gz
sudo tar -C /usr/local -xvf go1.15.linux-amd64.tar.gz
rm -rf go1.15.linux-amd64.tar.gz
3、Node配置
wget https://npm.taobao.org/mirrors/node/v14.19.3/node-v14.19.3-linux-x64.tar.gz
tar -xzvf node-v14.19.3-linux-x64.tar.gz
sudo mv node-v14.19.3-linux-x64 /usr/local/node
rm -rf node-v14.19.3-linux-x64.tar.gz
4、环境变量配置
vim /etc/profile
```
export NODE_HOME=/usr/local/node
export GOPATH=/home/limstorm/gowork/
export PATH=$NODE_HOME/bin:$PATH:/usr/local/go/bin
```
vim ~/.bashrc
```
source /etc/profile
```
5、安装yarn
npm install -g yarn
如果连接超时,可以设置npm为淘宝源:
npm config set registry https://registry.npm.taobao.org
6、安装cpplint
pip install cpplint
七、zsh安装
1、安装zsh
sudo apt install zsh
chsh -s /bin/zsh #将zsh设置成默认shell(不设置的话启动zsh只有直接zsh命令即可)
2、安装oh-my-zsh
sh -c "$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)" #国内镜像源
3、安装插件
#zsh-autosuggestions 命令行命令键入时的历史命令建议
git clone https://gitee.com/renkx/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
#zsh-syntax-highlighting 命令行语法高亮插件
git clone https://gitee.com/Annihilater/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
4、配置文件~/.zshrc
```
#防止中文乱码
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
ZSH_THEME="robbyrussell"
# 配置要使用的插件
plugins=(
git
extract
zsh-autosuggestions
zsh-syntax-highlighting
)
source $ZSH/oh-my-zsh.sh
source $ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /etc/profile
```
5、安装powerlevel10k主题
git clone https://gitee.com/wangl-cc/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
vim ~/.zshrc #将robbyrussell替换为powerlevel10k/powerlevel10k
zsh #切换到zsh进行p10k的自定义配置,也可使用p10k configure进行配置
八、终端字体设置Nerd Font
1、下载字体
https://www.nerdfonts.com/font-downloads,我选择的是Hack Nerd Font
2、解压到字体目录
sudo unzip Hack.zip -d /usr/share/fonts/
3、刷新字体缓冲
sudo fc-cache -fv
4、设置terminal字体
Edit - Preferences - Appearence - Font - Hack Nerd Font Regular + 13 - Close
5、设置terminal默认编码
Edit - Preferences - Advanced - Encoding - Unicode - UTF-8
5、重新打开终端即可
九、ssh安装
1、limstorm用户
(1)安装openssh-server
sudo apt install openssh-server
(2)设置limstorm用户登陆密码
passwd limstorm
(3)启动ssh服务,默认禁止root用户访问
sudo service ssh restart
(4)docker外连接容器
ssh limstorm@宿主机IP -p宿主机映射端口
ssh limstorm@容器IP -p22
以上两种方式均可
2、root用户
(1)安装openssh-server
apt install openssh-server
(2)设置当前用户登陆密码
passwd root
(3)修改配置文件
vim /etc/ssh/sshd_config
将PermitRootLogin prohibit-password修改为PermitRootLogin yes
(4)启动ssh服务
service ssh restart
(5)docker外连接容器
ssh root@宿主机IP -p宿主机映射端口
ssh root@容器IP -p22
以上两种方式均可
十、制作镜像,导出镜像文件
docker commit my-desktop ubuntu-20-04-desktop:3.0 #commit容器
docker save -o ubuntu-20-04-desktop-3.0.tar ubuntu-20-04-desktop:3.0 #导出镜像文件
docker load -i ubuntu-20-04-desktop-3.0.tar #导入镜像文件
十一、使用方式
1、创建docker network[可忽略]
docker network create network-local
2、创建容器
docker run -itd --privileged --name=my-desktop --ulimit memlock=-1:-1 --network="network-local" -p 22666:22 -p 5901:5901 -v /var/run/docker.sock:/var/run/docker.sock ubuntu-20-04-desktop:3.0 /bin/bash
3、进入容器
docker exec -it my-desktop /bin/bash
4、切换用户
su limstorm
5、启动vncserver
sudo service dbus start
vncserver -localhost no :1
6、启动ssh
sudo service ssh start
7、即可vncviewer或者ssh远程连接
标签:Ubuntu20.04,sudo,apt,ssh,install,ubuntu,docker,zsh,xfce From: https://www.cnblogs.com/limstorm/p/17320144.html