前言
需要在一台服务器上安装测试虚拟机,因为服务器没有显示器,所以不能通过VirtualBox客户端安装和管理虚拟机,命令行方式又太繁琐,听说可以通过网页的方式管理虚拟机,今天特意试了下这种方案,将过程记录如下。
安装virtualbox
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
加入apt源
deb http://download.virtualbox.org/virtualbox/debian xenial contrib
安装 virtualbox
sudo apt update
sudo apt install virtualbox virtualbox-ext
安装web
sudo apt install php-fpm php-saop php-xml nginx
wget https://github.com/phpvirtualbox/phpvirtualbox/archive/master.zip
unzip master.zip
sudo cp -r phpvirtualbox-5.2-0 /var/www/html/phpvirtualbox
sudo cp cp /var/www/html/phpvirtualbox/config.php-example /var/www/html/phpvirtualbox/config.php
配置服务
启动vboxweb服务
/usr/bin/vboxwebsrv -b -H 127.0.0.1 -p 18083
修改密码为真实运行virtualbox程序的账号密码
sudo vi /var/www/html/phpvirtualbox/config.php
12 var $username = 'vbox';
13 var $password = 'pass';
修改nginx
vi /etc/nginx/sites-enabled/default
35 root /var/www/html;
36
37 # Add index.php to the list if you are using PHP
38 index index.html index.htm index.nginx-debian.html;
39
40 server_name _;
41
42 #location / {
43 # First attempt to serve request as file, then
44 # as directory, then fall back to displaying a 404.
45 # try_files $uri $uri/ =404;
46 #}
47
48 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
49 #
50 location ~ \.php$ {
51 include snippets/fastcgi-php.conf;
52 #
53 # # With php7.0-cgi alone:
54 # fastcgi_pass 127.0.0.1:9000;
55 # # With php7.0-fpm:
56 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
57 }
58
59 # deny access to .htaccess files, if Apache's document root
60 # concurs with nginx's one
61 #
62 location ~ /\.ht {
63 deny all;
64 }
重新加载
/usr/sbin/nginx -s reload
访问
http://127.0.0.1/phpvirtualbox 默认账号密码都为admin
新建虚拟机
新建虚拟机的方法和virtualbox一样,只是要注意在设置里启用"Remote Display"
这样可以通过其他远程工具连接上虚拟机,继续后面的安装了。