# Raspberry Pi (舊的) [文件](https://www.raspberrypi.org/documentation/) [壞軌檢查](https://raymii.org/s/blog/Broken_Corrupted_Raspberry_Pi_SD_Card.html) [壞軌檢查](http://ithelp.ithome.com.tw/articles/10082957) ## 安裝 - 使用 [ImageUSB](http://www.osforensics.com/tools/write-usb-images.html) 燒錄 [Raspbian](https://www.raspberrypi.org/downloads/raspbian/) 映像檔 ## 設定 ### 預設登入 - `pi / raspberry` ### 修改密碼 ``` $ sudo passwd pi ``` ### 修改設定 ``` $ sudo raspi-config ``` - 記得開 SSH ### 增加 `apt` 來源 [mirrors](https://www.raspbian.org/RaspbianMirrors) ``` $ 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](https://foreachsam.github.io/book-util-apt/book/) ``` $ sudo apt-get update $ sudo apt-get upgrade -y # 只更新軟體 $ sudo apt full-upgrade -y # 完整更新 ``` ## 基地台 [ref.](https://blog.gtwang.org/iot/setup-raspberry-pi-as-wireless-access-point/) [ref.](http://blog.itist.tw/2016/03/using-raspberry-pi-3-as-wifi-ap-with-raspbian-jessie.html) - `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](https://w1.fi/cgit/hostap/plain/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](https://www.samba.org/samba/docs/using_samba/ch09.html) ### `/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.](https://www.digitalocean.com/community/tutorials/how-to-set-up-an-apache-mysql-and-python-lamp-server-without-frameworks-on-ubuntu-14-04) ## 安裝 ``` $ 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.](https://dev.mysql.com/doc/refman/5.7/en/charset-applications.html) ``` [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.](https://oshlab.com/install-latest-node-js-raspberry-pi-3/) ``` $ 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.](https://wuhuanblog.blogspot.tw/2015/11/raspberry-pi-2-jupyter.html) [ref.](https://jupyter-notebook.readthedocs.io/) [ref.](https://techknight.eu/2016/01/03/setup-jupyter-notebook-centosrhel-7/) ## 安裝 ``` $ sudo pip install jupyter ``` ``` $ (sudo) jupyter notebook --generate-config ``` ``` $ python ``` ```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` `樹莓派`