Skip to content

Instantly share code, notes, and snippets.

@bestpika
Last active October 18, 2016 00:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bestpika/c4fc1df6398261f5b272 to your computer and use it in GitHub Desktop.
Save bestpika/c4fc1df6398261f5b272 to your computer and use it in GitHub Desktop.

Raspberry Pi

doc.

安裝

  • 使用 ImageUSB1 燒錄 Raspbian2 映像檔

設定

預設登入

  • pi / raspberry

修改密碼

$ sudo passwd pi

修改設定

$ sudo raspi-config

增加 apt 來源

mirrors

$ sudo nano /etc/apt/sources.list
deb http://free.nchc.org.tw/raspbian/raspbian/ {...} # 國網中心

開機啟動服務

  • 加入
$ sudo update-rc.d {服務} defaults
  • 移除
$ sudo update-rc.d {服務} remove

開機執行指令

$ sudo crontab -e
@reboot {cmd}
| ; && &

更新

韌體

$ sudo apt-get update
$ sudo apt-get install -y rpi-update
$ sudo rpi-update

軟體

apt

$ sudo apt-get update
$ sudo apt-get upgrade -y # 只更新軟體
$ sudo apt full-upgrade -y # 完整更新

基地台

ref. ref.

  • wlan0
$ sudo ifdown wlan0
$ sudo nano /etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet static
    # wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    address 192.168.100.1
    netmask 255.255.255.0
$ sudo ifup wlan0
  • DHCP
$ sudo apt-get install -y isc-dhcp-server
$ sudo nano /etc/dhcp/dhcpd.conf
# option domain-name ...;
# option domain-name-servers ...;
authoritative;
subnet 192.168.100.0 netmask 255.255.255.0 {
  range 192.168.100.100 192.168.100.199;
  option broadcast-address 192.168.100.255;
  option routers 192.168.100.1;
  default-lease-time 1800;
  max-lease-time 3600;
  option domain-name "local";
  option domain-name-servers 192.168.100.1;
}
$ sudo nano /etc/default/isc-dhcp-server
INTERFACES="wlan0"
$ sudo service isc-dhcp-server restart
  • AP
$ sudo apt-get install -y hostapd

hostapd.conf

$ sudo nano /etc/hostapd/hostapd.conf
# hostapd.conf
interface=wlan0
ssid=RPI3-TFL-SETUP
utf8_ssid=1
country_code=TW
hw_mode=g
channel=8
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wmm_enabled=1
wpa=2
wpa_passphrase={密碼}
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
$ sudo nano /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
$ sudo hostapd /etc/hostapd/hostapd.conf # 測試

Pre-Install

$ sudo apt-get install -y libcurl4-gnutls-dev libssl-dev libevent-dev libexpat1-dev libz-dev libmysqlclient-dev
$ sudo apt-get install -y gettext git

Samba (smbd)

安裝

$ sudo apt-get install -y samba

設定

smb.conf

/etc/samba/smb.conf

  • config
[{英文名稱}]
   comment = {說明}
   path = {路徑}
   browseable = yes/no
   writable = yes/no
   public = yes/no
  • example
$ mkdir -p /home/pi/share
$ sudo chmod 777 /home/pi/share
[share]
   comment = share
   path = /home/pi/share
   browseable = yes
   writable = yes
   public = no

管理

新增使用者

$ sudo pdbedit -a pi

列出使用者

$ sudo pdbedit -L

LAMP

ref.

安裝

$ sudo apt-get install -y apache2 mysql-server php5 libapache2-mod-php5 php5-mysql

設定

$ sudo a2enmod userdir
$ sudo a2enmod cgi
$ sudo service apache2 restart
$ sudo nano /etc/apache2/mods-enabled/userdir.conf
<Directory ...>
    Options ... ExecCGI
    AddHandler cgi-script .cgi .pl .py
</Directory>
$ sudo service apache2 restart

Apache (apache2)

設定

VirtualHost

  • 設定
$ sudo nano /etc/apache2/sites-available/{名稱}
  • 啟用
$ sudo a2ensite {名稱}

MySQL (mysql)

安裝

$ sudo apt-get install -y mysql-server

設定

$ sudo nano /etc/mysql/my.cnf
$ sudo sed -i 's,^bind-address.*,bind-address\t\t= 0.0.0.0,g' /etc/mysql/my.cnf

ref.

[mysqld]
bind-address = 0.0.0.0
...
character-set-server = utf8
collation-server = utf8_general_ci

管理

新增使用者

CREATE USER '{USER}'@'%' IDENTIFIED BY '{PSWD}';
GRANT ALL ON *.* TO '{USER}'@'%' IDENTIFIED BY '{PSWD}';

備份資料庫

$ mysqldump -u root -p {資料庫} > {路徑} --routines

還原資料庫

$ mysql -u root -p {資料庫} < {路徑}

Node.js

安裝

ref.

$ sudo curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -
$ sudo apt-get install -y nodejs

npm

$ sudo npm install npm@latest -g # 更新
$ sudo npm install pm2 -g

Python

安裝

$ sudo apt-get install -y python-dev python-pip build-essential virtualenv python-serial minicom

pip

$ sudo pip install pyyaml termcolor pymysql google-api-python-client

Jupyter

ref. ref. ref.

安裝

$ sudo pip install jupyter
$ (sudo) jupyter notebook --generate-config
$ python
>>> from notebook.auth import passwd
>>> passwd()
$ sudo nano /root/.jupyter/jupyter_notebook_config.py
$ nano /homes/pi/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip = '*'
c.NotebookApp.notebook_dir = u'{路徑}'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'{密碼}'
$ (sudo) jupyter notebook

問題與解決

Q: 官方 7" LCD 顛倒

A:config.txt 加入 lcd_rotate=2

附註

tags: raspberry pi 樹莓派

Footnotes

  1. http://www.osforensics.com/tools/write-usb-images.html

  2. https://www.raspberrypi.org/downloads/raspbian/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment