模擬伺服器的操作

目標:以virtualbox 安裝 ubuntu 17.04 系統,並且在ubuntu 下安裝 amp(lamp)

step1:下載已經作好系統的 ubuntu1704.ova

step2:安裝virtualbox

step3:安裝virtualbox ext-pack

step4:開啟virtualbox,在檔案/匯入應用裝置

step5:啟動ubuntu1704虛擬機

step6:登入系統,帳號密碼為teacher,ntpc

註:如果滑鼠鍵盤被困在虛擬機內,可按 host key離開,內鍵的host key 為右ctrl

目標:建立2個網卡,NAT 負責外部網路(可上網安裝軟體);僅限主機介面卡--和本地機的連線

step1:因要安裝虛擬機的網卡,請先將虛擬機關機

step2:<設定值/網路>,<介面卡1->NAT>,<介面卡2->僅限主機>

step3:虛擬機開機,並登入系統

step4:查虛擬機的 ip , 指令 ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

link/ether 08:00:27:d8:40:a8 brd ff:ff:ff:ff:ff:ff

inet 192.168.56.100/24 brd 192.168.56.255 scope global enp0s3

valid_lft forever preferred_lft forever

inet6 fe80::a00:27ff:fed8:40a8/64 scope link

valid_lft forever preferred_lft forever

3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

link/ether 08:00:27:e7:4e:67 brd ff:ff:ff:ff:ff:ff

inet 10.0.3.15/24 brd 10.0.3.255 scope global enp0s8

valid_lft forever preferred_lft forever

inet6 fe80::a00:27ff:fee7:4e67/64 scope link

valid_lft forever preferred_lft forever


注意第2,第3介面卡,找 inet 後面的 ip

step5: 指令 sudo nano /etc/network/interfaces

[sudo] password for teacher:(在此輸teacher 的密碼 ntpc,輸入過程不會有任何顯示)

# This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface

auto lo

iface lo inet loopback

# The primary network interface

auto enp0s3

iface enp0s3 inet dhcp


在下方輸入

auto enp0s8

iface enp0s8 inet dhcp

依序按 Ctrl+x , Y ,enter

會將檔案存檔再離開 nano 編輯器

step 6: 指令 sudo service networking restart

會將網路重啟

step7:再查虛擬機的 ip , 指令 ip addr

step8:指令 ping 8.8.8.8

測試能否連線外網

step9:在本機操作,開啟cmder,

指令 ping 192.168.56.100

測試能否連線虛擬機


註:如果<介面卡>請選[橋接介面卡],可以取得ip,用[橋接介面卡]會比上面 [nat] + [僅限主機]的方式更方便,因為虛擬機和主機的ip 同網段,虛擬機的網路行為如真實機器一般

目標:安裝 amp(apache2,php7,mysql)

以下都在cmder 底下操作

step1:從本機以 ssh 登入虛擬機

指令 ssh teacher@192.168.56.100 (ip 為 僅限本機介面卡或橋接介面卡的 ip)

The authenticity of host '192.168.56.100 (192.168.56.100)' can't be established.

ECDSA key fingerprint is SHA256:8oNU255K0+1C/ZV1Gxi4KuwGzmYC2ix5h3foHMqhGaI.

Are you sure you want to continue connecting (yes/no)? yes(按yes)

Warning: Permanently added '192.168.56.100' (ECDSA) to the list of known hosts.

teacher@192.168.56.100's password:

Welcome to Ubuntu 17.04 (GNU/Linux 4.10.0-19-generic x86_64)

* Documentation: https://help.ubuntu.com

* Management: https://landscape.canonical.com

* Support: https://ubuntu.com/advantage

* What are your preferred Linux desktop apps? Help us set the default

desktop apps in Ubuntu 18.04 LTS:

- https://ubu.one/apps1804

100 個套件可以更新。

62 個屬於安全性更新

Last login: Tue Aug 8 07:07:29 2017

step2 安裝 apache2

sudo nano /etc/sysctl.conf

Add these lines to the bottom of sysctl.conf

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

sudo sysctl -p

指令 sudo apt install apache2

step3 安裝 php7

指令 sudo apt install php php-cli

step4 安裝 mysql

指令 sudo apt install mysql-server mysql-client

安裝過程,會要求輸入 mysql 使用者 root 的密碼, 輸 ntpc

step5 安裝 mysql 的管理程式 phpmyadmin

指令 sudo apt install phpmyadmin

安裝過程,會詢問目前伺服器的 web server ,請選 apache

需要 mysql 密碼,都是 ntpc

目標:為方便上傳製作網頁,設定apache DocumentRoot 的位置到 /home/teacher 底下

step1:指令

ssh teacher@192.168.56.100

指令mkdir wwwroot

指令 sudo nano /etc/apache2/sites-available/000-default.conf

#DocumentRoot /var/www/html 本行前面加#

加入下列文字

DocumentRoot /home/teacher/wwwroot

 <Directory /home/teacher/wwwroot>                 
         options Indexes FollowSymLinks MultiViews 
         AllowOverride None                        
         Require all granted                       
 </Directory> 

存檔離開

指令sudo service apache2 restart

10.231.56.xxxx