Ubuntu Server 19.10 from raspberry-pi 4B+

這篇主要紀錄 ubuntu server 跑在 raspberry pi 3 b+ 的過程
並架設 wordpress 和開機自動回報IP

Ubuntu Server 19.10 for raspberry-pi (ubuntu classic version)
https://ubuntu.com/download/raspberry-pi
先確認sd 卡是哪個裝置名稱


sudo fdisk -l /dev/sdc
demos
sudo mkfs.vfat /dev/sdc -I

2. 把img 寫入 sd 卡裝置

xzcat ~/Downloads/piServer/ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz | sudo dd of=/dev/sdc bs=32M

3. 將sd卡置入raspberry pi,
登入預設帳號密碼 ubuntu, ubuntu

4. 如果HDMI顯示有問題,可以在以下路徑修改

boot/firmware/config.txt
hdmi_drive=2
sdtv_mode=0
hdmi_group=2
hdmi_mode=16

5. 設定/安裝 無線網路連線

sudo apt install wireless-tools
sudo apt install network-manager
sudo vim /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
wifis:
wlan0:
optional: true
dhcp4: true
access-points:
<$SSID>:
password: <$PASSWORD>
ethernets:
eth0:
dhcp4: true
optional: true
version: 2

測試設定是否正確

sudo netplan --debug try

6. 接著讓pi 開機時自動送出ifconfig

botNotify.py

import sys
import requests
import os
def main():
msg="no msg"
cmd='ifconfig'
m=os.popen(cmd)
t=m.read()
m.close()
if len(sys.argv) > 1:
msg=sys.argv[1]
URL = "https://hooks.slack.com/……/" #slack hook
r = requests.post(URL, json={"username":"empathytechbot", "channel": "aiot", "text":t})

print(r.status_code)
if __name__ == “__main__”:
main()

Botstart.sh

#!/bin/sh
Python3 /etc/init.d/botNotify.py

修改權限

chmod 755 /etc/init.d/botstart
update-rc.d botstart.sh defaults
update-rc.d -f botstart.sh remove

設定開機執行

root@ubuntu:/etc/init.d# sudo update-rc.d botstart.sh defaults
root@ubuntu:/etc/init.d# sudo update-rc.d botstart.sh enable

7. 接著安裝需要的架站軟體

sudo apt install apache2
sudo apt-get install mysql-server
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install software-properties-common
sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm
sudo apt-get install libapache2-mod-php7.1
sudo apt-get update
sudo reboot

or

sudo apt install php-fpm
sudo apt install php-mysql php-gd
sudo apt install php libapache2-mod-php
sudoapt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt install php7.3 php7.3-common php7.3-opcache php7.3-cli php7.3-gd php7.3-curl php7.3-mysql
sudo reboot


wget https://tw.wordpress.org/latest-zh_TW.zip

就是一台可以個人用的 server 囉。

8.

vim /etc/mysql/my.cnf

[mysqld]
default_authentication_plugin= mysql_native_password
mysql -uroot -p
use mysql
ALTER USER $user IDENTIFIED WITH mysql_native_password BY ‘passwd’
FLUSH PRIVILEGES;

Leave a comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *