• 树莓派的利用(一)----跌宕起伏的使用过程


    Raspberry Pi(中文名“树莓派”),是只有信用卡大小的微型电脑,其系统基于Linux。为了改善学校宿舍的上网环境(校园网登陆系统导致不能用路由器多设备通用网络),通过树莓派访问校园网登陆系统上网并且24小时开机分享热点实现24小时多设备上网。

    1、准备材料:

    我所用到的设备

    (1)一块树莓派以及电源

    (2)一根HDMI线

    (3)一根网线

    (4)一块500G硬盘

    (5)硬盘座

    (6)显示器

    (7)笔记本电脑

    (8)tf卡读卡器

    2、下面按照我的使用步骤进行记录:

    1. 树莓派安装操作系统
      1. 用读卡器将树莓派NOOBS操作系统解压缩至tf卡中。注意!不要把解压后的文件夹拖入tf卡中,应该点进文件夹,同时按ctrl+A将所有文件复制进tf卡中;
      2. 将tf卡插入树莓派,将除了电源以外的线都接好,包括散热风扇、硬盘、屏幕HDMI线等,其中网线接在宿舍上网端口上,最后接上电源,树莓派启动;
      3. 最后,根据系统提示安装好操作系统,进入桌面;
      4. 树莓派初始的登录用户名:pi初始密码:raspberry
      5. sudo passwd root #设置root密码

        sudo passwd -u root #解锁root用户

    2. 树莓派通过HDMI连接显示器
      1. 很明显,使用显示器的我发现有一点不对劲,树莓派桌面显示居然有黑边,于是上网查找解决办法;
      2. 打开config.txt:sudo nano /boot/config.txt;
      3. 在默认情况下,取消注释(取消“#”)修改下面这段,
        overscan_left=-16
        overscan_right=-16
        overscan_top=-16
        overscan_bottom=-16
        树莓派的显示输出就占满了屏,关于后面的“-16”这个数字,根据自己的屏实际情况来确定。
    3. 树莓派通过VNC由笔记本控制
      1. 输入命令行sudo raspi-config;
      2. 选择5.Interfacing Options;
      3. 找到VNC(远程桌面),选择 Yes(是)。
    4. 树莓派安装热点分享程序create_ap
      1. 将代码clone到本地
        sudo git clone https://github.com/oblique/create_ap
        cd create_ap
        sudo make install
      2. 安装依赖的库
        sudo apt-get install util-linux procps hostapd iproute2 iw haveged dnsmasq
      3. 打开热点(此时,树莓派wifi开着,但没有连wifi)
        sudo create_ap wlan0 eth0 热点名 密码
      4. 此时不出意外热点将会开启,但是会有warn,可以执行以下代码
        sudo create_ap --no-virt wlan0 eth0 m热点名 热点
      5. 以服务方式启动,执行开机自启
        #1.修改服务配置,添加--no-virt参数
        sudo vi /usr/lib/systemd/system/create_ap.service
        #
        ExecStart=/usr/bin/create_ap --config /etc/create_ap.conf
        # 修改为 
        ExecStart=/usr/bin/create_ap --no-virt --config /etc/create_ap.conf
        
        #2.默认配置文件/etc/create_ap.conf,将下面两横改为自己的ssid和密码即可,修改自己的dhcp网关
        sudo vi /etc/create_ap.conf
        # 将
        GATEWAY=10.0.0.1
        SSID=MyAccessPoint
        PASSPHRASE=12345678 
        # 修改为
        GATEWAY=192.168.123.1
        SID=dzxj
        PASSPHRASE=11111111
        
        # 启动一个服务:
        systemctl start create_ap.service
        # 关闭一个服务:
        systemctl stop create_ap.service
        # 重启一个服务:
        systemctl restart create_ap.service
        # 显示一个服务的状态:
        systemctl status create_ap.service
        # 在开机时启用一个服务:
        systemctl enable create_ap.service
        # 在开机时禁用一个服务:
        systemctl disable create_ap.service
        # 查看服务是否开机启动:
        systemctl is-enabled create_ap.service
      6. 异常一:WARN: brmfmac driver doesn't work properly with virtual interfaces and it can cause kernel panic. For this reason we disallow virtual interfaces for your adapter.For more info: https://github.com/oblique/create_ap/issues/203
        ERROR: Your adapter can not be a station (i.e. be connected) and an AP at the same time
        处理:sudo nmcli dev dis wlan0
      7. 异常二:

        sudo create_ap wlan0 eth0 my_raspi 88166908
        WARN: brmfmac driver doesn't work properly with virtual interfaces and it can cause kernel panic. For this reason we disallow virtual interfaces for your adapter. For more info: https://github.com/oblique/create_ap/issues/203 WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt Config dir: /tmp/create_ap.wlan0.conf.cDxIozig PID: 1132 Network Manager found, set wlan0 as unmanaged device... DONE/bin/create_ap: line 1669: dnsmasq: command not found

        ERROR: Wrong version format!

        处理:
        
        sudo yum install dnsmasq -y
      8. 异常三:

        sudo create_ap wlan0 eth0 my_raspi 12345678
        WARN: brmfmac driver doesn't work properly with virtual interfaces andit can cause kernel panic. For this reason we disallow virtual interfaces for your adapter. For more info: https://github.com/oblique/create_ap/issues/203 WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt Config dir: /tmp/create_ap.wlan0.conf.gC5KSqVQ PID: 2497 Sharing Internet using method: nat hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlan0.conf.gC5KSqVQ/hostapd_ctrl Configuration file: /tmp/create_ap.wlan0.conf.gC5KSqVQ/hostapd.conf

        处理:
        sudo create_ap --no-virt wlan0 eth0 my_raspi 12345678

        Failed to create interface mon.wlan0: -95 (Operation not supported)

    5. 树莓派安装seafile,首先seafile-7.0.4安装包有一个bug,在自定义输入seafile依赖文件夹时会出错。查询相关问题解决办法后发现依然没用。。。。那我就退而求其次安装了seafile-6.3.4,以后有时间再研究7.0.4版本。
      1. 挂载移动硬盘
        #确认硬盘已经插好,查看状态
        sudo fdisk -l
        #找到硬盘的Device项目,应该为/dev/sda1,然后
        df -h
        #发现硬盘并未挂载,下面创建挂载目录
        sudo mkdir /home/pi/toshiba
        #然后把硬盘挂载在这个目录
        sudo mount /dev/sda1 /home/pi/toshiba
        #再次
        df -h
        #发现硬盘以及挂载在了相应的目录了,但是我们的硬盘是NTFS格式的,Linux不能直接读取,下面安装NTFS格式可读写软件
        sudo aptitude install ntfs-3g
        #加载内核模块
        modprobe fuse 
        #让移动硬盘开机自动挂载
        sudo nano /etc/fstab 
        #在文件的最后一行添加
        /dev/sda1  /home/pi/toshiba ntfs-3g defaults,noexec,umask=0000 0 0 
        #有时若挂载出错,报错Mount is denied,用命令
        sudo fuser -m -u /dev/sda1sudo kill 1308 
        #再按照步骤重新挂载。
      2. 安装seafile所需依赖
        sudo apt-get update
        
        sudo apt-get install python2.7 libpython2.7 python-setuptools python-imaging python-ldap python-urllib3 sqlite3 python-requests

        至此,树莓派的环境已经初始化完毕,适合安装seafile。

      3. 安装并部署seafile

        先将seafile安装包在官网上现在下来,放在/home/pi/seafile文件夹中。

        cd /home/pi/seafile

        然后解压文件夹

        sudo tar -xzf seafile-server_6.3.4_stable_pi.tar.gz

        接着安装seafile

        cd seafile-server-6.3.4
        
        sudo ./setup-seafile.sh

        之后根据提示填写信息部署seafile

        Press [Enter] to continue#此处按回车继续
        [sever name]:  #此处给服务器起一个名字
        [This server’s ip or domain]:  #输入局域网内树莓派的IP
        Where would you like to store your seafile data?Note: Please use a volume with enough free space.[default: /home/pi/seafile/seafile-data ]#高度注意!!此处是在指定seafile的数据存放位置,因为之前挂载了硬盘,切不可直接按默认设置,需要改到硬盘目录下,你可以填写/home/pi/toshiba/seafile-data
        What tcp port do you want to use for seafile fileserver?8082 is the recommended port.[default: 8082 ]# seafile服务器的端口号,默认8082,回车表示默认即可,若自行修改则要额外开放端口
        If you are OK with the configuration, press [ENTER] to continue.# 这里确认你的seafile服务器配置,没问题继续回车-----------------------------------------------------------------
        Seahub is the web interface for seafile server.Now let's setup seahub configuration. Press [ENTER] to continue
        -----------------------------------------------------------------
        # 这里开始安装seahub,回车继续-----------------------------------------------------------------
        Your seafile server configuration has been completed successfully.
        -----------------------------------------------------------------
        # 已经安装完成了,下边是告诉你怎么启动安装好的程序。
        run seafile server:     ./seafile.sh { start | stop | restart }
        run seahub  server:     ./seahub.sh  { start <port> | stop | restart <port> }
        -----------------------------------------------------------------
        If the server is behind a firewall, remember to open these tcp ports:
        -----------------------------------------------------------------
        # 下边是程序要使用的端口,如果开启了防火墙,需要开放这两个端口。
        port of seafile fileserver:   8082
        port of seahub:  8000 

        这时安装并没有结束,由于seafile-6.3.4所需python-urllib3版本为1.23,而现在已经到了1.25版本,所以还需执行以下代码:

        sudo pip install urllib3==1.23
      4. 开启seafile

        执行下列代码:

        cd /home/pi/seafile/seafile-server-6.3.4
        sudo ./seafile.sh start
        sudo ./seahub.sh start

        此时需要配置管理员账号和密码,按要求输入即可。

        最后可以在浏览器访问:IP:8000 到达seafile“云盘”管理页面。
      5. 开启重新启动
        #首先创建seafile服务文件
        sudo nano /etc/systemd/system/seafile.service
        
        #输入下列内容
        [Unit]
        Description=Seafile
        # add mysql.service or postgresql.service depending on your database to the line below
        After=network.target
        [Service]
        Type=oneshot
        ExecStart=${seafile_dir}/seafile-server-latest/seafile.sh start
        ExecStop=${seafile_dir}/seafile-server-latest/seafile.sh stop
        RemainAfterExit=yes
        User=seafile
        Group=seafile
        [Install]
        WantedBy=multi-user.target
        
        #再创建seahub启动文件
        sudo nano /etc/systemd/system/seahub.service
        
        输入下列内容
        [Unit]
        Description=Seafile hub
        After=network.target seafile.service
        [Service]
        # change start to start-fastcgi if you want to run fastcgi
        ExecStart=${seafile_dir}/seafile-server-latest/seahub.sh start
        ExecStop=${seafile_dir}/seafile-server-latest/seahub.sh stop
        User=seafile
        Group=seafile
        Type=oneshot
        RemainAfterExit=yes
        [Install]
        WantedBy=multi-user.target
        
        #最后设置开机自启动
        sudo systemctl enable seafile.service
        sudo systemctl enable seahub.service

        这样开机自启动就设置完成了

    3、总结

      由于树莓派3b+硬件的限制,通过开热点上网网速有点慢,不过不玩lol等游戏,对我的影响不大。做seafile主要是为了利用一下从旧电脑上拆下来的500G的硬盘,局域网内seafile上传的文件被进行分块加密,同时下载速度感人,估计笔记本手机在线看电影是不可能的了。下一步可能会利用云服务器DDNS服务内网穿透一下,再看看树莓派有什么新玩法。

    4、感谢

      非常感谢知乎用户ddch对我的帮助,其中seafile有关内容来自ddch文章“树莓派3B+部署seafile的实录”。

      https://zhuanlan.zhihu.com/p/57202972

  • 相关阅读:
    慢sql
    drf 和django 字段参数解析
    django uwsgi
    django 中间件原理图和实现方法
    解决 控制台console导入模型报错 django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured.
    版本控制器 django全局和局部配置
    极客论坛Cpu瓶颈定位思路
    jmeter grpc 自定义开发java请求案例
    论文阅读笔记四十七:Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression(CVPR2019)
    论文阅读笔记四十六:Feature Selective Anchor-Free Module for Single-Shot Object Detection(CVPR2019)
  • 原文地址:https://www.cnblogs.com/jwxdzxj/p/11574634.html
Copyright © 2020-2023  润新知