4

Ubuntu20.04 + VirtualBox相关

 1 year ago
source link: https://blog.51cto.com/xfxuezhang/5968992
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Ubuntu20.04 + VirtualBox相关

精选 原创

目录

​​教程​​

​​添加用户和用户组​​

​​安装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 <username>

添加sudo权限

sudo usermod -G sudo <username>

添加root权限

sudo vim /etc/sudoers

修改添加:

# User privilege specification
root ALL=(ALL) ALL
<username> ALL=(ALL) ALL

安装SSH

sudo apt install openssh-server
sudo systemctl status ssh

如果ssh连不上桌面版Ubuntu,记得这里开一下:

Ubuntu20.04 + VirtualBox相关_virtualbox

apt换源

cp /etc/apt/sources.list /etc/apt/sources.list.bk
sudo rm /etc/apt/sources.list
sudo 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 multiverse
deb 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 multiverse
deb 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 multiverse
deb 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 ~/.pip
sudo vim ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

升级Python

不推荐手动升级,容易出问题。还是上anaconda吧。

sudo apt update
sudo apt install software-properties-common
sudo apt install python3.7
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
sudo update-alternatives --config python3 # 选Python3.7那个
sudo apt-get remove python3-apt
sudo apt-get install python3-apt

开启远程桌面(windows连接,desktop版ubuntu)

安装vino 用于设置共享桌面

sudo apt-get install vino

设置共享桌面(可选,好像可以不用开

Ubuntu20.04 + VirtualBox相关_ubuntu_02

 安装dconf-editor

sudo apt-get install dconf-editor

启动dconf-editor

dconf-editor

依次展开org->gnome->desktop->remote-access,将 requre-encryption 设为 False

Ubuntu20.04 + VirtualBox相关_ubuntu_03

安装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
Ubuntu20.04 + VirtualBox相关_ubuntu_04

 打开win10远程连接,进行连接。这里的用户名填写你系统的用户名,密码填写设置共享桌面的密码

Ubuntu20.04 + VirtualBox相关_虚拟机_05
Ubuntu20.04 + VirtualBox相关_ubuntu_06

如果黑屏,可以先注销原有的用户登录(也就是另一个地方已经登录了这个用户了,需要先注销登录)。

Ubuntu20.04 + VirtualBox相关_虚拟机_07

升级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-rc2
cmake .
make
sudo make install
sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
cmake --version
Ubuntu20.04 + VirtualBox相关_ubuntu_08

 删除安装包

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

安装Samba

sudo apt update
sudo apt install samba samba-common

创建一个用于分享的samba目录(如果在/home就跳过这步)

mkdir /home/<username>/sambashare/

给创建的这个目录设置权限

sudo chmod 777 /home/<username>/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/<username>/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系统直接进行文件共享了

Ubuntu20.04 + VirtualBox相关_服务器_09
Ubuntu20.04 + VirtualBox相关_ssh_10

安装Mosquitto MQTT

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
sudo 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.deb

sudo dpkg -i emqx-5.0-beta.2-otp24.1.5-2-ubuntu18.04-amd64.deb

emqx start

安装Redis

sudo apt update
sudo apt install redis-server -y
sudo systemctl status redis-server

远程访问:

1、服务器后台控制台放行6379端口。

2、修改配置文件。

sudo nano /etc/redis/redis.conf

取消注释:
# bind 0.0.0.0 ::1
改为:
bind 0.0.0.0


sudo systemctl restart redis-server

3、设置密码。

sudo vi /etc/redis/redis.conf

取消注释:
# requirepass foobared
并改为你的密码:
requirepass 123456

sudo systemctl restart redis-server

安装LAMP

sudo apt install apache2 -y
sudo apt install mysql-server mysql-client
sudo apt-get install php
sudo apt-get install libapache2-mod-php
sudo apt-get install php-mysql

# 设置mysql密码:
sudo mysql_secure_installation

如果mysql报错“'Access denied for user 'root'@'localhost'”,解决方法:

sudo mysql

-- for MySQL
ALTER 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/html
git clone https://hub.fastgit.org/typecho/typecho.git
sudo chmod 777 /var/www/html -R
sudo mv typecho/* ./

sudo apt install php-mbstring
sudo /etc/init.d/apache2 restart

4、数据库增加一个typecho的database

mysql -uroot -p

mysql> 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.service

tracker reset --hard

VirtualBox开启双屏

1、关闭虚拟机(如ubuntu)

2、打开虚拟机的“设置->显示->监视器数量”,改为“2

Ubuntu20.04 + VirtualBox相关_virtualbox_11

 3、启动虚拟机

4、“启用”显示屏2

Ubuntu20.04 + VirtualBox相关_虚拟机_12

 5、双屏开启完成,分别拖到两个物理显示器即可

Ubuntu20.04 + VirtualBox相关_virtualbox_13

VirtualBox增加磁盘内存

0、查看磁盘使用情况:df -h

Ubuntu20.04 + VirtualBox相关_ubuntu_14

 1、关闭ubuntu,打开“管理 - 虚拟介质配置”。

Ubuntu20.04 + VirtualBox相关_服务器_15

 2、选中要增加的“镜像vdi”,调整大小。

Ubuntu20.04 + VirtualBox相关_virtualbox_16

 3、打开ubuntu虚拟机,安装分区管理软件gparted。(因为上面只是增加了空间,并没有分配)

sudo apt install gparted

然后命令框输入

gparted
Ubuntu20.04 + VirtualBox相关_虚拟机_17

4、上图中,灰色unallocated的左边的如果没有另外的分区,则可以跳过步骤5和8

5、点击右边灰色unallocated的左边的白色块,右击,选择“swapoff”,然后删除该swap分区。

Ubuntu20.04 + VirtualBox相关_虚拟机_18

6、选择要待扩容的根分区,这里是“/dev/sda2”。将条拉满(注意剩5G空间用于重建swap分区,不要的话也可以不留),再点确定。

Ubuntu20.04 + VirtualBox相关_ssh_19

7、跟上面一样,再选择待扩容的分区,这里是“/dev/sda5”。将条拉满,再点确定。

8、这里可以重建swap分区(我就不建了,内存够用)。创建完记得跟步骤5一样点一下“swapon”。

Ubuntu20.04 + VirtualBox相关_ubuntu_20

 9、点击“应用”,完成操作。

Ubuntu20.04 + VirtualBox相关_服务器_21

 10、再去看一下,发现修改成功了。

Ubuntu20.04 + VirtualBox相关_ssh_22

清理apt无用源

对于如这种情况的:

Ubuntu20.04 + VirtualBox相关_虚拟机_23
sudo add-apt-repository --remove ppa:george-edison55/cmake-3.x
sudo apt install ppa-purge
sudo ppa-purge [options] <ppa:ppaowner>[/ppaname]
# 具体用法:https://askubuntu.com/questions/307/how-can-ppas-be-removed

安装NVIDIA驱动

虚拟机上装不了cuda,可以考虑 docker版。

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

重启虚拟机,验证:

nvidia-smi
lspci | grep -i nvidia

安装mosquitto

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa # 引入mosquitto仓库
sudo apt-get update
sudo 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

# Apache
sudo apt update
sudo apt upgrade -y
sudo apt install apache2 -y
sudo systemctl status apache2

# MySQL
sudo apt-get install mysql-server -y
sudo systemctl status mysql
# 如果安装出错,请参考:https://stackoverflow.com/questions/47075429/error-setting-up-mysql-table-mysql-plugin-doesnt-exist
sudo service mysql start
sudo mysql_secure_installation

# 如果跟我一样装不成功,就换宝塔面板装吧。。。。
sudo service mysql stop
sudo apt-get --purge remove "mysql*" -y
sudo rm -rf /etc/mysql/

sudo mysql_secure_installation # 设置密码

# PHP
sudo apt install php libapache2-mod-php php-mysql -y
sudo systemctl restart apache2
sudo apt-cache show php-gd # 安装模块,如php-gd,或全部php*

1、下载免费字体:

sudo cp *.ttf /usr/share/fonts

3、建立字体缓存

fc-cache -f -v
fc-list | grep "Hack"

Can't initialize GTK backend in function 'cvInitSystem'

今天vscode上用OpenCV忽然报这个错:

Ubuntu20.04 + VirtualBox相关_服务器_24

是cv::imshow这个函数无法执行显示。

解决:

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

Ubuntu20.04 + VirtualBox相关_ubuntu_25

ssh REMOTE HOST IDENTIFICATION HAS CHANGED

清除缓存即可

ssh-keygen -R "you server hostname or ip"
Ubuntu20.04 + VirtualBox相关_虚拟机_26

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK