树莓派配置, 包括常用开发环境及部分实用工具的安装与配置
安装raspbian系统至SD卡
略
选择国内仓库源
sudo sed -i 's#://raspbian.raspberrypi.org#s://mirrors.ustc.edu.cn/raspbian#g' /etc/apt/sources.list
sudo sed -i 's#://archive.raspberrypi.org/debian#s://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian#g' /etc/apt/sourceslist.d/raspi.list
使用VNC协议无线连接桌面
系统已经默认安装RealVNC,直接启动即可
vncserver
使用RDP协议无线连接桌面
sudo apt install tightvncserver xrdp
安装tightvncserver将会自动卸载realvnc
安装phpMyAdmin环境
安装nginx,php-fpm,mairadb
sudo apt install nginx php-fpm mariadb-server
配置数据库
- 安全设置
sudo mysql_secure_installation
- 登录
mysql -uroot -p
报错,错误信息为:ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
解决方案:
sudo mysql -uroot -p update mysql.user set authentication_string=PASSWORD('root'), plugin='mysql_native_password' where user='root'; flush privileges;
配置nginx以支持php
sudo vim /etc/nginx/sites-available/default
----------------------------------- location / { index index.html index.htm index.php default.html default.htm default.php; } location ~\.php$ { fastcgi_pass unix:/run/php/php7.3-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } -----------------------------------
配置php以支持mysql
- 安装php的mysql扩展
sudo apt install php-mysql
- 在配置文件中加入php的mysql扩展
sudo vim /etc/php/7.3/fpm/php.ini
----------------------------------- extension=mysqli ;去掉注释 -----------------------------------
安装phpMyAdmin
cd ~/Downloads wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz tar zxvf phpMyAdmin-latest-all-languages.tar.gz sudo mv phpMyAdmin-*-all-languages /var/www/html/pma
安装tomcat环境
安装jdk环境
sudo apt install openjdk-8-jdk
下载tomcat8.5.42并解压至/usr/local/java目录下
cd ~/Downloads wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz tar zxf apache-tomcat-8.5.42.tar.gz sudo mkdir /usr/local/java sudo mv apache-tomcat-8.5.42 /usr/local/java/tomcat
设置开机自启动tomcat
sudo vim /etc/rc.local
----------------------------------- /usr/local/java/tomcat/bin/startup.sh # 在exit 0前加入tomcat启动文件 -----------------------------------
配置无线静态IP
编辑dhcpcd.conf文件
sudo vim /etc/dhcpcd.conf
----------------------------------- interface wlan0 static ip_address=192.168.0.200/24 static routers=192.168.0.1 static domain_name_server=114.114.114.114 -----------------------------------
安装花生壳实现内网穿透
下载安装花生壳
cd ~/Downloads wget http://download.oray.com/peanuthull/embed/phddns_3.0.3_systemd.deb sudo dpkg -i phddns_3.0.3_systemd.deb
安装ftp服务器实现文件共享
安装vsftp
sudo apt install vsftpd
配置vsftp
sudo vim /etc/vsftpd.conf
----------------------------------- write_enable=YES local_umask=022 -----------------------------------
挂载移动硬盘
sudo mount -o uid=pi,gid=pi /dev/sda1 ~/Public
开机后自动推送IP至邮箱
安装邮件客户端
sudo apt install msmtp mutt
配置msmtp
vim .msmtprc
----------------------------------- account default host smtp.qq.com from luanrzh@qq.com auth plain user luanrzh@qq.com password mfnamealwuktbabi logfile /var/log/msmtp.log -----------------------------------
.msmtprc初始权限会报错:msmtp: /home/pi/.msmtprc: contains secrets and therefore must have no more than user read/write permissions
修改.msmtprc文件权限
chmod 600 .msmtprc
配置mutt
vim .muttrc
----------------------------------- set sendmail="/usr/bin/msmtp" set use_from=yes set from="luanrzh@qq.com" set realname="pi" set editor="vim" -----------------------------------
新增"获取IP并发邮件"的脚本
vim send-ip-mail.sh
----------------------------------- #!/bin/bash # check network availability while true do TIMEOUT=5 SITE_TO_CHECK="https://www.126.com/" RET_CODE=`curl -I -s --connect-timeout $TIMEOUT $SITE_TO_CHECK -w %{http_code} | tail -n1` if [ "x$RET_CODE" = "x200" ]; then echo "Network OK, will send mail..." break else echo "Network not ready, wait..." sleep 1s fi done # get the IP address of eth0, e.g. "192.168.16.5" ETH0_IP_ADDR=`ifconfig eth0 | sed -n "2,2p" | awk '{print substr($2,1)}'` WLAN0_IP_ADDR=`ifconfig wlan0 | sed -n "2,2p" | awk '{print substr($2,1)}'` # send the Email echo -e "有线:${ETH0_IP_ADDR}\n无线:${WLAN0_IP_ADDR}" | mutt -s " 树莓派IP" luanrzh@qq.com -----------------------------------
编写 开机运行脚本
sudo vim /etc/rc.local
----------------------------------- #... /home/pi/send-ip-mail.sh >> /home/pi/send-ip-mail.log 2>&1 exit 0 -----------------------------------
上述脚本是以root用户执行,当前/root目录下还没有msmtp和mutt的配置文件
复制配置文件至/root目录下
sudo cp .msmtprc /root sudo cp .muttrc /root