Ubuntu20.04 + VirtualBox相關

2022-12-26 18:16:13 來源:51CTO博客

目錄

??教程??


(資料圖片)

??添加用戶和用戶組??

??安裝SSH??

??apt換源??

??pip換源??

??升級Python??

??開啟遠程桌面(windows連接,desktop版ubuntu)??

??升級CMake3.22??

??安裝Samba??

??安裝Mosquitto MQTT??

??安裝EMQX MQTT??

??安裝Redis??

??安裝LAMP??

??安裝typecho??

??安裝g20??

??關閉搜索,節省內存??

??VirtualBox開啟雙屏??

??VirtualBox增加磁盤內存??

??清理apt無用源??

??安裝NVIDIA驅動??

??安裝mosquitto??

??安裝LAMP??

??安裝字體??

??報錯??

??Can"t initialize GTK backend in function "cvInitSystem"??

??ssh REMOTE HOST IDENTIFICATION HAS CHANGED??


歡迎關注公眾號:小鋒學長生活大爆炸


教程

添加用戶和用戶組

添加用戶

sudo adduser 

添加sudo權限

sudo usermod -G sudo 

添加root權限

sudo vim /etc/sudoers

修改添加:

# User privilege specificationroot ALL=(ALL) ALL ALL=(ALL) ALL

安裝SSH

sudo apt install openssh-serversudo systemctl status ssh

如果ssh連不上桌面版Ubuntu,記得這里開一下:

apt換源

備份:

cp /etc/apt/sources.list /etc/apt/sources.list.bk

修改:

sudo rm /etc/apt/sources.listsudo vim /etc/apt/sources.list

注意根據不同版本:ubuntu | 鏡像站使用幫助 | 清華大學開源軟件鏡像站 | Tsinghua Open Source Mirror

填入:

# 默認注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

pip換源

mkdir ~/.pipsudo vim ~/.pip/pip.conf

輸入:

[global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple

升級Python

不推薦手動升級,容易出問題。還是上anaconda吧。

sudo apt updatesudo apt install software-properties-commonsudo apt install python3.7sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2sudo update-alternatives --config python3 # 選Python3.7那個sudo apt-get remove python3-aptsudo apt-get install python3-apt

開啟遠程桌面(windows連接,desktop版ubuntu)

安裝vino 用于設置共享桌面

sudo apt-get install vino

設置共享桌面(可選,好像可以不用開

安裝dconf-editor

sudo apt-get install dconf-editor

啟動dconf-editor

dconf-editor

依次展開org->gnome->desktop->remote-access,將 requre-encryption 設為 False

安裝xdrp

sudo apt-get  install xrdp

一旦安裝完成,Xrdp 服務將會自動啟動。你可以輸入下面的命令,驗證它:

sudo systemctl status xrdp

默認情況下,Xrdp 使用??/etc/ssl/private/ssl-cert-snakeoil.key???,它僅僅對“ssl-cert” 用戶組成語可讀。運行下面的命令,將??xrdp??用戶添加到這個用戶組:

sudo adduser xrdp ssl-cert

重啟 Xrdp 服務,使得修改生效:

sudo systemctl restart xrdp

打開win10遠程連接,進行連接。這里的用戶名填寫你系統的用戶名,密碼填寫設置共享桌面的密碼

如果黑屏,可以先注銷原有的用戶登錄(也就是另一個地方已經登錄了這個用戶了,需要先注銷登錄)。

升級CMake3.22

下載

wget https://cmake.org/files/v3.22/cmake-3.22.0-rc2-linux-x86_64.tar.gz

解壓

tar zxvf CMake-3.22.0-rc2-linux-x86_64.tar.gz

編譯安裝

cd CMake-3.22.0-rc2cmake .makesudo make install

更新

sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force

查看

cmake --version

刪除安裝包

cd ..rm CMake-3.22.0-rc2-linux-x86_64.tar.gzrm -rf CMake-3.22.0-rc2/

安裝Samba

安裝

sudo apt updatesudo apt install samba samba-common

創建一個用于分享的samba目錄(如果在/home就跳過這步)

mkdir /home//sambashare/

給創建的這個目錄設置權限

sudo chmod 777 /home//sambashare/ -R

添加用戶(下面的sxf是我的用戶名,之后會需要設置samba的密碼)。這里添加的用戶在 Linux 中必須存在。

sudo smbpasswd -a sxf

配置samba的配置文件

sudo nano /etc/samba/smb.conf

在配置文件smb.conf的最后添加下面的內容

[sambashare]    comment = Samba on Ubuntu    path = /home//sambashare    read only = no    browsable = yes    public = yes    available = yes    writable = yes    valid users = sxf    write list = sxf    create mask = 0700    directory mask = 0700    force user = sxf

重啟samba服務器

sudo service smbd restart

Windows徽標+R 在彈出的運行窗口中輸入 \\ip 即可訪問。輸入samba用戶名及密碼訪問即可看到共享,然后就可以在Linux系統與Windows系統直接進行文件共享了

安裝Mosquitto MQTT

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppasudo apt-get updatesudo apt-get install mosquittosudo apt-get install mosquitto-clientssudo apt clean

安裝EMQX MQTT

wget https://www.emqx.com/zh/downloads/broker/v5.0-beta.2/emqx-5.0-beta.2-otp24.1.5-2-ubuntu18.04-amd64.debsudo dpkg -i emqx-5.0-beta.2-otp24.1.5-2-ubuntu18.04-amd64.debemqx start

安裝Redis

sudo apt updatesudo apt install redis-server -ysudo systemctl status redis-server

遠程訪問:

1、服務器后臺控制臺放行6379端口。

2、修改配置文件。

sudo nano /etc/redis/redis.conf取消注釋:# bind 0.0.0.0 ::1改為:bind 0.0.0.0sudo systemctl restart redis-server

3、設置密碼。

sudo vi /etc/redis/redis.conf取消注釋:# requirepass foobared 并改為你的密碼:requirepass 123456sudo systemctl restart redis-server

安裝LAMP

sudo apt install apache2 -ysudo apt install mysql-server mysql-clientsudo apt-get install phpsudo apt-get install libapache2-mod-phpsudo apt-get install php-mysql# 設置mysql密碼:sudo mysql_secure_installation

如果mysql報錯“"Access denied for user "root"@"localhost"”,解決方法:

sudo mysql-- for MySQLALTER USER "root"@"localhost" IDENTIFIED WITH mysql_native_password BY "你的密碼";

安裝typecho

1、完成上面的LAMP安裝

2、進入apache目錄下

cd /var/www/html

3、下載typecho安裝包并授權

官網:Typecho Official Site

cd /var/www/htmlgit clone https://hub.fastgit.org/typecho/typecho.gitsudo chmod 777 /var/www/html -Rsudo mv typecho/* ./sudo apt install php-mbstringsudo /etc/init.d/apache2 restart

4、數據庫增加一個typecho的database

mysql -uroot -pmysql> create database typecho;

5、瀏覽器進入安裝頁面

http://你的服務器ip/install.php

6、根據指引完成安裝即可

安裝g20

uoip/g2opy: Python binding of SLAM graph optimization framework g2o (github.com)

關閉搜索,節省內存

1、Settings -> Search,關閉搜索 2、執行

systemctl --user mask tracker-store.service tracker-miner-fs.service tracker-miner-rss.service tracker-extract.service tracker-miner-apps.service tracker-writeback.servicetracker reset --hard

3、重啟

VirtualBox開啟雙屏

1、關閉虛擬機(如ubuntu)

2、打開虛擬機的“設置->顯示->監視器數量”,改為“2

3、啟動虛擬機

4、“啟用”顯示屏2

5、雙屏開啟完成,分別拖到兩個物理顯示器即可

VirtualBox增加磁盤內存

0、查看磁盤使用情況:df -h

1、關閉ubuntu,打開“管理 - 虛擬介質配置”。

2、選中要增加的“鏡像vdi”,調整大小。

3、打開ubuntu虛擬機,安裝分區管理軟件gparted。(因為上面只是增加了空間,并沒有分配)

sudo apt install gparted

然后命令框輸入

gparted

4、上圖中,灰色unallocated的左邊的如果沒有另外的分區,則可以跳過步驟5和8

5、點擊右邊灰色unallocated的左邊的白色塊,右擊,選擇“swapoff”,然后刪除該swap分區。

6、選擇要待擴容的根分區,這里是“/dev/sda2”。將條拉滿(注意剩5G空間用于重建swap分區,不要的話也可以不留),再點確定。

7、跟上面一樣,再選擇待擴容的分區,這里是“/dev/sda5”。將條拉滿,再點確定。

8、這里可以重建swap分區(我就不建了,內存夠用)。創建完記得跟步驟5一樣點一下“swapon”。

9、點擊“應用”,完成操作。

10、再去看一下,發現修改成功了。

df -h

清理apt無用源

對于如這種情況的:

sudo add-apt-repository --remove ppa:george-edison55/cmake-3.x

或者

sudo apt install ppa-purgesudo ppa-purge [options] [/ppaname]# 具體用法:https://askubuntu.com/questions/307/how-can-ppas-be-removed

安裝NVIDIA驅動

虛擬機上裝不了cuda,可以考慮 docker版。

安裝:

sudo apt-get install  virtualbox-guest-dkmssudo ubuntu-drivers installsudo apt install nvidia-cuda-toolkit

重啟虛擬機,驗證:

nvidia-smilspci  | grep -i nvidia

安裝mosquitto

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa # 引入mosquitto倉庫sudo apt-get updatesudo apt-get install mosquitto -y # 安裝mosquitto包sudo apt-get install mosquitto-clients -y # 安裝mosquitto客戶端sudo service mosquitto status # 查詢mosquitto是否正確運行

若需配置文件,請另外搜索(sudo vim /etc/mosquitto/mosquitto.conf)。

測試:

#打開一個終端,執行以下命令訂閱主題"mqtt"mosquitto_sub -h localhost -t "mqtt" -v#打開另外一個終端,發布消息到主題 “mqtt”mosquitto_pub -h localhost -t "mqtt" -m "Hello MQTT"#現在你會看到消息被顯示在前一個終端上了.#通過以下命令,可以定于到官放所有測試的mqtt信息,當然你發布的信息別人也能訂閱到mosquitto_sub -h test.mosquitto.org -t "#"   -v#也可以在官方mqtt服務下發布自己專屬的信息mosquitto_sub -h test.mosquitto.org -t  "myxyz123"  -v#訂閱自己的信息mosquitto_pub -h test.mosquitto.org -t "myxyz123"  -m  "hello mqtt"

安裝LAMP

# Apachesudo apt updatesudo apt upgrade -ysudo apt install apache2 -ysudo systemctl status apache2# MySQLsudo apt-get install mysql-server -ysudo systemctl status mysql# 如果安裝出錯,請參考:https://stackoverflow.com/questions/47075429/error-setting-up-mysql-table-mysql-plugin-doesnt-existsudo service mysql startsudo mysql_secure_installation# 如果跟我一樣裝不成功,就換寶塔面板裝吧。。。。sudo service mysql stopsudo apt-get --purge remove "mysql*" -ysudo rm -rf /etc/mysql/ sudo mysql_secure_installation # 設置密碼# PHPsudo apt install php libapache2-mod-php php-mysql -ysudo systemctl restart apache2sudo apt-cache show php-gd  # 安裝模塊,如php-gd,或全部php*

安裝字體

1、下載免費字體:

sudo cp *.ttf /usr/share/fonts

3、建立字體緩存

fc-cache -f -v

4、驗證

fc-list | grep "Hack"

報錯

Can"t initialize GTK backend in function "cvInitSystem"

今天vscode上用OpenCV忽然報這個錯:

是cv::imshow這個函數無法執行顯示。

解決:

需要在命令窗口中執行才行。

ssh REMOTE HOST IDENTIFICATION HAS CHANGED

清除緩存即可

ssh-keygen -R "you server hostname or ip"

標簽: 配置文件 設置密碼 安裝字體

上一篇:Android平臺GB28181設備接入端如何調節實時音量?
下一篇:天天最新:STL庫之集合基本使用方法