vbox 中使用ubuntu的操作步骤
在Vbox安装Ubuntu 16.04 Server版本,无法拷贝和复制内容到shell中,故在windows中使用xshell连接服务器方式规避。
需要注意的是:在VirtualBox里面安装ubuntu系统时,需要设置VirtualBox的网络连接方式为:桥接,否则主机无法ping通虚拟机(ubuntu)的IP地址;并且需要设置虚拟机的网关和主机一致,虚拟机的IP地址和主机的IP地址在同一网段。否则不仅不能相互ping通,可能还连不上互联网。
基本信息:
ubuntu16.04.template.vmdk为ubuntu16.04的Desktop版本的模板机,用户为thirsd,密码为111111;
ubuntu16.04-server.template.vdi为ubuntu16.04的Desktop版本的模板机,用户为thirsd,密码为111111;
1、使用模板文件拷贝一份
支持拷贝ubuntu16.04-server.template.vdi
2、修改vdi的uuid,避免加载异常(UUID问题)
VirtualBox可不像VMware那样,直接复制虚拟磁盘文件就可以了事的,只因为VirtualBox识别虚拟磁盘文件VDI采用了uuid识别技术.
问题:将虚拟磁盘文件复制一份重新创建虚拟系统时提示
打开 虚拟硬盘 5.04.vdi 失败.Cannot register the hard disk '5.04.vdi' with UUID {24eb969f-8c98-470d-b2dd-35318f2b8860} because a hard disk '5.04.vdi' with UUID {24eb969f-8c98-470d-b2dd-35318f2b8860} already exists in the media registry ('C:/Documents and Settings/Blinux/.VirtualBox/VirtualBox.xml').
解决方法一:直接复制VDI文件,然后修改UUID
#假设 VBXO的安装路径为:D:\Program Files\Oracle\VirtualBox
#假设 需要修改UUID的VDI文件路径为:D:\Programs\VboxData\ubuntu16.04-server.airflow.vdi
cd D:\Program Files\Oracle\VirtualBox
D:
VBoxManage internalcommands sethduuid "D:\Programs\VboxData\ubuntu16.04-server.airflow.vdi"
解决方法二:直接用Virtualbox自带的克隆vdi文件命令
#如果路径中存在空格可以在路径的两端添加引号
VBoxManage clonehd 'I:/VBOX/RHEL5.4/5.4.vdi' 'I:/VBOX/RHEL5.4/5.4.clone.vdi'
3、安装增强功能
3.1 将ISO挂载磁盘上:
D:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso
3.2 安装增强功能:
sudo mkdir /mnt/cdrom
sudo umount /mnt/cdrom
sudo mount /dev/cdrom /mnt/cdrom
cd /mnt/cdrom
ls
sudo ./VBoxLinuxAdditions.run #确定没有failed
sudo reboot
4、通过xshell连接
4.1更新网络接入模式
修改网卡为 桥链网络模式
sudo reboot
4.2 安装ssh
sudo apt-get update
sudo apt-get install ssh
# 查看ssh的状态
/etc/init.d/ssh status
------------------ 后续操作,可以从xshell进行访问----------------------------
5、更改ubutnu源
5.1 编辑源配置文件
cd /etc/apt/
sudo cp sources.list sources.list.org
编辑sodu vi sources.list
,以阿里源替换
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties deb http://archive.canonical.com/ubuntu xenial partner deb-src http://archive.canonical.com/ubuntu xenial partner deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
清华源:
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
5.2 源生效
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
有时候执行很慢,Ctrl+C后,再次执行,一直卡在
0% [Waiting for headers]
解决方法:
sudo apt-get clean sudo apt-get update
6. 固定IP和DNS
vbox桥连方式,默认dhcp分配IP地址,导致每次重新启动服务器地址均发生改变,不方便维护。
6.1 修改IP地址
编辑配置文件sudo vi /etc/network/interfaces
auto ens33
iface ens33 inet static
address 192.168.1.131
netmask 255.255.255.0
gateway 192.168.1.1
重启网络生效:sudo /etc/init.d/networking restart
ubuntu从17.10开始,已放弃在/etc/network/interface里固定IP的配置,即使配置也不会生效,而是改成netplan方式
sudo vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.103/24]
optional: true
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.1]
version: 2
执行sudo netplan apply
配置生效。
6.2 配置DNS
永久生效,修改:/etc/resolvconf/resolv.conf.d/base
临时生效,修改:/etc/resolv.conf(重启后恢复)
增加DNS的解析地址为:
nameserver 192.168.1.1
然后重启,使得dns生效
7. 同宿主机挂着共享目录
当vbox挂着共享目录,需要安装增加包时,报:
是否要强制分配该介质(VERR_PDM_MEDIA_LOCKED)
https://askubuntu.com/questions/573596/unable-to-install-guest-additions-cd-image-on-virtual-box
There is no need to mount the guest additions ISO and install from it if your guest OS is Ubuntu.
Instead, open a terminal and enter the following -
sudo apt-get install virtualbox-guest-utils
This will install the guest additions and is more or less equivalent to installing via the ISO.
- sudo apt-get install virtualbox-guest-additions-iso
配置共享目录后,应该在/media目录下下存在共享目录
设置好共享名后,进入Ubuntu系统,打开终端,先执行命令,在挂载点目录添加“bdshare”目录,接着执行"mount -t vboxsf BaiduShare /mnt/bdshare/",就能完成共享文件夹的设置。
8、配置python环境
安装anaconda环境
# 下载安装包
wget https://mirrors.bfsu.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh
# 执行安装,需要输入yes
sh Anaconda3-2021.11-Linux-x86_64.s
# 安装后生效配置
source .bashrc
# 检验安装情况
conda -V
#(base) root@thirsd:/etc/netplan# conda -V
#conda 4.11.0
8.1 安装python3.6
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
# 下载安装包
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
tar -zxvf Python-3.6.8.tgz
# 需要安装zlib
sudo apt-get install zlib-dev
sudo apt-get install openssl
# 编译
./configure --prefix=/usr/local --enable-optimizations
make&&sudo make install
# 更改默认python
sudo unlink /usr/bin/python
sudo ln -s /usr/local/bin/python3.6 /usr/bin/python
sudo unlink /usr/bin/pip
sudo ln -s /usr/local/bin/pip3.6 /usr/bin/pip
8.1 安装pip
sudo apt-get install python-pip
8.2 更改pip源和升级pip
mkdir ~/.pip/
vi ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
升级pip
sudo pip install --upgrade pip
8.2 安装virtual-env
sudo pip install virtualenv
附问题:
1) 菜单重新显示和快捷键
将虚拟机窗口的菜单给隐藏了,VirtualBox设有热键,也就是Host key,默认为右Ctrl键。
如果你也不小心隐藏了菜单,你可以这样解决。
首先进入虚拟机,然后按你的Host key+Home键,就会弹出菜单栏,然后选择Switch to scale mode,隐藏的菜单就会重新显示了。
或可以直接按Host key+C,也能达到同样的效果。
网友评论