Tinyhttpd實戰一:設置虛擬機環境,運行Tinyhttpd

安裝linux虛擬機

首先安裝vmware軟件,而後下載Ubuntu iso文件下載地址
而後創建Ubuntu虛擬機,運行內存與硬盤建議爲4G+20G
建議離線安裝

解決vmware tools無法安裝問題

VMware Tools是VMware虛擬機中自帶的一種增強工具,是VMware提供的增強虛擬顯卡和硬盤性能、以及同步虛擬機與主機時鐘的驅動程序。

只有在VMware虛擬機中安裝好了VMware Tools,才能實現主機與虛擬機之間的文件共享,同時可支持自由拖拽的功能,鼠標也可在虛擬機與主機之前自由移動(不用再按ctrl+alt),且虛擬機屏幕也可實現全屏化。

在安裝完虛擬機後,有可能會碰到vmware tools安裝選項爲灰色的情況
在這裏插入圖片描述
此時可以手動安裝vmware tools
步驟如下:
方法1: 在虛擬機設置中添加cd/dvd驅動器,並使用vmware安裝目錄下的linux.iso文件
在這裏插入圖片描述
在這裏插入圖片描述
方法2:將cd/dvd驅動器,軟盤全部設爲自動檢測
在這裏插入圖片描述
在這裏插入圖片描述
開啓虛擬機,點擊安裝vmware tools,打開光盤文件,其中有一個名爲 VMwareTools…tar.gz 的壓縮包,將這個壓縮包移動到你想解壓的目錄(例如 /home/Documents/VMTools),然後點擊這個壓縮包,右鍵選擇“extract here”解壓到當前目錄。

打開終端,進入到解壓後的文件夾,然後進入到 vmware-tools-distrib 目錄,輸入 sudo ./vmware-install.pl 回車,接着就是輸入 yes 再一直回車了。

vmware提示虛擬機似乎正在使用中

刪除虛擬機配置文件(vmx)文件夾中的.lck文件

vmware 開機黑屏

可能的解決方法
方法1:以管理員身份運行命令行窗口---->輸入 netsh winsock reset,然後重啓計算機。

方法2:VM->Settings->Hardware->Display在右面的內容欄中將Accelerate 3D graphics 取消打勾,然後重啓即可
方法3:,打開虛擬機的首選項 打開設備,更改設置,啓用虛擬打印機
方法4重裝系統

創建root用戶

首先輸入命令:sudo passwd
輸入兩次密碼後root用戶創建成功
用su root切換用戶

運行Tinyhttpd

由於虛擬機自帶的源網速過慢,故開始前需要換源
ubuntu18.04的阿里源:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

修改配置文件:/etc/apt/sources.list
用root權限打開,清除其全部內容,換成上面的鏡像
sudo getdit /etc/apt/sources.list
直接將電腦中的Tinyhttpd拖至虛擬機上,安裝geany編輯器

sudo apt-get update
sudo apt-get install geany
sudo apt-get install make
sudo apt-get install gcc

修改makefile文件

all: httpd client

LIBS = -lpthread 

httpd: httpd.c

	gcc -g -W -Wall -pthread $(LIBS) -o $@ $<



client: simpleclient.c

	gcc -W -Wall -o $@ $<

clean:

	rm httpd

htdocs中的cgi文件第一行的#!/usr/bin/perl -Tw 設爲虛擬機上的perl位置(用which perl查詢)
然後修改htdocs中文件權限


cd htdocs

sudo chmod 600 index.html  

sudo chmod 764 color.cgi check.cgi  

而後在tinyhttpd目錄下直接make
如果出現make: Nothing to be done for `all’
則make clean 而後再次make

運行 ./httpd
最後在瀏覽器中輸入localhost:端口號
在這裏插入圖片描述
在這裏插入圖片描述

發佈了48 篇原創文章 · 獲贊 8 · 訪問量 1901
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章