這邊會使用LEDE的OpenWRT, 然後透過Hyper-V建置VM安裝LEDE...
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-713223a3e596e250e829fa4fd62ffc5d.jpg)
既然要塞Unifi Controller, 那只能透過掛載其他的OS環境來執行...
這種情況下, RAM的要求不能太低. 意思是如果是非VM的產品...
那RAM最好不要太小. 來看以下掛載其他OS環境執行Unifi Controller的Memory Usage情況..
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-5d484d8049ab8d6e36b5e3370294dfab.jpg)
從上圖可以看出這個要求是系統記憶體最好在1GB以上. 在這樣的要求下, 大多AP產品都會被打槍...=_="
除了建置VM以外的方案, 就只有軟體路由器符合這個條件.
當安裝LEDE後, 當然得確定internet能不能上的去了.
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-5ae9d88775614882878f343b6b3ada7e.jpg)
確認沒問題後, 這邊Hyper-V再掛載一個16GB的drive用來作為Unifi Controller使用.
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-528020526b06fe10dc318361cbcd81f7.jpg)
往下執行opkg update來更新套件列表:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-fa3fe604d0274f1d9058c36eac27cefa.jpg)
在執行df -h來看看分區表:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-2de54529fe813631700ac7f551177ebb.jpg)
不過完全是新的drive當然是甚麼資訊都看不到, 執行ls /dev/[sh]d* 來查看:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-eb3ba44b7a35d8f2ea792e917fbe3f3d.jpg)
可以看出有一個新得sdb儲存裝置, 為了確認. 使用fdisk檢查, 不過LEDE沒有安裝這個套件. 因此需要下載安裝:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-02eba515ff76ef98efb2a1c0f38d8c0c.jpg)
安裝完成後, 使用fdisk -l /dev/sdb 確認這個新的sdb儲存裝置:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-e3fe9541d6caf9553bc465c6cbab0a55.jpg)
確認沒問題後, 格式化該裝置, 使用fdisk:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-dde7695d146b6cb7556daa7ee058ddfc.jpg)
最後使用w參數進行寫入操作:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-443d80054636e04c9d1533edcd240280.jpg)
在使用fdisk -l /dev/sdb 確認是否建立一個partition:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-fd983128248e71180f71003c01dc02a5.jpg)
得知這個partition為 /dev/sdb1.
LEDE應該是預設有安裝e2fsprogs的工具. 使用該工具建立ext4檔案系統.
應用 mkfs.ext4 /dev/sdb1
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-b2c0a86fc29f50a95fd92997f3644e3e.jpg)
接下來安裝block-mount來掛載檔案系統:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-cbcd35931b9ebde1502fcc0daeb6d9ff.jpg)
然後再用block-mount去mount新的ext4檔案系統.
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-57d50ad82ad162be47579d17be344aed.jpg)
不過我在測試中發現有點問題. 按下Apply&Save後, LEDE整個就死掉了. 必須強制reboot.
reboot完成後, 使用 df -h來查看, 發現已mount成功:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-723f73da1a8ef608438a6300a54ca8d2.jpg)
安裝debootstrap套件用來載入其他的OS環境:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-5adfd003f3863f5d4c6d5731eea16f37.jpg)
安裝完成後, 這邊將安裝debian的Linux環境, 使用如下命令:
debootstrap --arch=amd64 jessie /mnt/sdb1/debian http://mirrors.163.com/debian/
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-bdb47810622b7692132e904ee58d0b06.jpg)
這邊可能會遇到一個問題, 就是他下載的失敗率頗高的. 這個命令可能要多執行2~3次才會成功.
安裝debian完成後, 透過GUI的Startup, 寫入以下命令啟動時自動掛載(更新/etc/rc.local):
mount -o bind /proc /mnt/sdb1/debian/proc
mount -o bind /dev /mnt/sdb1/debian/dev
mount -o bind /dev/pts /mnt/sdb1/debian/dev/pts
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-629b1825a0da8ae75124545ba736b829.jpg)
Submit過後, 將LEDE進行reboot. 之後chroot進入debian環境:
chroot /mnt/sdb1/debian /bin/bash
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-16a317f0b4c0047bdd81237e3cac8770.jpg)
為了下載Unifi Controller軟體, 首先要更新sources.list來源內容.
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-5b5b3f8d96ef9dc23cb8a91ff3229d1c.jpg)
用vi編輯加入以下的來源:
deb http://www.ubnt.com/downloads/unifi/debian unifi5 ubiquiti
儲存後, 使用apt-get update進行套件資源更新:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-18f03389ae36ad79978161af07f17d0e.jpg)
增加GPG key, 使用如下命令:
apt-key adv --keyserver keyserver.ubuntu.com --recv C0A52C50
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-36702f81b92965513d53f1125118aa9c.jpg)
import完成後, 重點就是開始安裝Unifi Controller了. 使用如下命令:
apt install unifi
確認安裝完成後, 直接用browser測試是否能正常進入Unifi Controller的Web控制介面:
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-ad649b7cc8abca0f161185e2ea4aa8ca.jpg)
確認沒問題後, 進行最後的收工. 因為reboot過後, 相關的服務不會被啟用. 因此需要在GUI的Startup更新/etc/rc.local的內容, 添加如下命令. 注意跟mount執行的順序:
chroot /mnt/sdb1/debian service mongodb start
chroot /mnt/sdb1/debian service unifi start
![[UBNT學習] 如何整合Unifi Controller到OpenWRT(LEDE)](http://attach.mobile01.com/attach/201708/mobile01-706480fcea294434adf5bdce170f0415.jpg)
上述命令加入後, 在下一次的reboot, Unifi等相關服務都會被自動啟用.
使得Unifi Controller能正常操作.