树莓派安装ubuntu-server,配置镜像,安装python/mysql/samba记录

时间:2022-08-16 23:40:08

目标:
  1/在raspberrypi 3B上安装ubuntu-server
  2/配置好python/mysql/samba等服务,实现爬虫稳定运行
我的硬件准备:
  1/raspberrypi 3B
  2/16G class10 micro sd卡/读卡器
  3/Hdmi转VGA转接头/usb键盘
软件准备:
  1/win32diskimager-1.0.0-install.exe
  (https://ncu.dl.sourceforge.net/project/win32diskimager/Archive/win32diskimager-1.0.0-install.exe)
  2/ubuntu-mate-16.04.2-desktop-armhf-raspberry-pi.img
  (https://www.finnie.org/software/raspberrypi/ubuntu-rpi3/ubuntu-16.04-preinstalled-server-armhf+raspi3.img.xz)

安装过程:
step1:安装ubuntu-server
  1/将内存卡格式化为FAT32
  2/打开win32diskmager,将解压过的ubuntu img文件写入sd卡
  3/修改sd卡中的config.txt,以保证启动时hdmi接口有视频信号。hdmi转vga,修改如下:
    a)hdmi_safe=1
    b)framebuffer_width=800
       framebuffer_height=600
    c)hdmi_force_hotplug=1
    d)hdmi_group=2
       hdmi_mode=35
    e)hdmi_drive=2
    f)config_hdmi_boost=4
    具体原理参看(http://www.ncnynl.com/archives/201607/228.html)
  4/将sd插入树莓派,连接hdmi接口和键盘,而后连接电源
  5/开始程序结束后,输入默认用户名ubuntu和密码ubuntu,设置新密码。使用sudu passwd root设置root密码
  6/修改/etc/ssh/sshd_config,改PermitRootLogin=yes,sshd restart以使root账户可ssh登录

step2:安装镜像站和软件:
  1/国内只有中科大为基于armhf的ubuntu提供镜像。vi /etc/apt/source.list,添加配置,具体见:http://mirrors.ustc.edu.cn/help/ubuntu-ports.html
  2/apt-get install aptitude && aptitude update && aptitude disk-upgrade 若未软件未完全升级,则再disk-upgrade一遍
  3/aptitude install python2.7 && ln -s /user/bin/python2.7 /user/bin/python && aptitude install python-pip
  4/新建文件夹和文件~/.pip/pip.conf,添加pip镜像配置,具体见http://www.cnblogs.com/microman/p/6107879.html
  5/aptitude install mysql-server. 而后,增加utf8mb4字符集配置(http://www.cnblogs.com/shihaiming/p/5855616.html),sql模式配置  (http://www.cnblogs.com/ainiaa/archive/2010/12/31/1923002.html),以及mysql远程访问(http://www.cnblogs.com/machine/p/3317190.html)。具体分两步:
    a)更新/etc/mysql/my.cnf
      [client]
      default-character-set = utf8mb4
      [mysql]
      default-character-set = utf8mb4
      [mysqld]
      character-set-client-handshake = FALSE
      character-set-server = utf8mb4
      collation-server = utf8mb4_unicode_ci
      init_connect='SET NAMES utf8mb4'
      sql_mode='NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER'

      !includedir /etc/mysql/conf.d/
      !includedir /etc/mysql/mysql.conf.d/
    b)更新/etc/mysql/mysql.conf.d/mysqld.cnf
      注释掉 bind_address=127.0.0.1这一行
  6/安装samba,配置参见http://blog.csdn.net/splenday/article/details/47116969,或简单地修改/etc/samba/smb.conf
    workgroup = WORKGROUP 下增加security = user
    最后添加[share]
    path=/tasks
    public=yes
    writable=no

step3:大坑(disk-upgrade后可能重启时无法启动)
  1/树莓派没有BIOS,其启动配置在config.txt里,aptitude disk-upgrade后可能导致重启时,遇到
    No FDT memory address configured. Please configure the FDT address via "fdt add " command.
    ERROR: Did not find a cmbline Flattened Device Tree等错误
  此时,需将sd卡拔出,修改config文件:
  注释掉 device_tree_address=0x100
      device_tree_end=0x8000
  增添 device_tree_address=0x02008000
  而后重启
  具体参见(https://raspberrypi.stackexchange.com/questions/65913/ubuntu-server-on-raspi-3-poweroff-how-to-reboot/65952)

补充:
  1/我用的是5V3A的供电插头,可直接带起移动硬盘(硬盘无需额外供电)
  2/我用爬虫使用进城池(10进程)爬取某站图片和其他数据,毫无压力。速度比i5 16G的服务器稍慢。但完全满意。