簡介:本文主要介紹ubuntu20.04容器中搭建xfce遠程桌面、C++、Go環境、容器內docker操作配置、zsh配置 一、創建容器 1、創建容器 docker pull ubuntu:20.04docker run -itd --privileged --name=my-desktop--u ...
簡介:本文主要介紹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
6、重新打開終端即可
九、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遠程連接