(系统版本:CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-4-2009-sda.raw)
一、安装系统
1、烧录系统
这里用到树莓派官方(https://www.raspberrypi.com/software/)的烧录软件
Raspberry Pi Imager
2.下载安装包,本次使用没有UI的系统,华为云下载相应镜像
(注:此系统不含 GNOME,只是命令行)
3烧录完成
二、登陆系统,.
把烧录好的SD卡插入树莓派,通上电并接上路由器,通过路由器的管理页面观察树莓派的ip地址。
跟Raspberry Pi OS不同,centOS是默认开启ssh的。
默认帐号密码登陆 root 密码centos
默认用户名:root
默认密码:centos
2.修改密码
passwd root
3. 到目前为止我们已经成功安装centos并通过局域网连接树莓派。
如果想让树莓派连接Wi-Fi,可以输入
nmtui
#设置有线IP为10.8.0.188
#连接wifi casey
选 active connection连接wifi
三、硬盘扩容
fd -h
命令查看,发现32G的tf卡只用了2G,光是系统就基本用满了,装不了什么东西,所以得把剩下30G(29724664)也用上。这里暂时只使用16G,(约14862332)
fdisk /dev/mmcblk0
p——查看旧分区情况
d——删除分区,并按照提示删除第三个分区
n——添加一个分区,空间起始位置按照系统默认
p——查看新分区情况
w——写入分区信息并退出软件
先p查看分区,抄下第三分区的开始start (1593344)
【d】删除第三分区,
【n】新建第三分区【p】,使用16G,所以end长度29724664
[w] 保存,
重启
reboot
重启后,刷新分区
resize2fs /dev/mmcblk0p3
四、安装软件vim,vi
1.安装vim
yum install -y vim
2、换源
清理旧仓库
# 清除缓存
yum clean all
sudo rm -rf /var/cache/yum
# 卸载epel仓库
yum remove epel-release
# 删除所有旧仓库文件
# 注意,如有其它仓库文件请自行重装或选择性删除
rm -rf /etc/yum.repos.d/*
建立仓库
vim /etc/yum.repos.d/CentOS-Base.repo
内容
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.ustc.edu.cn/centos-altarch/$releasever/os/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32
#released updates
[updates]
name=CentOS-$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.ustc.edu.cn/centos-altarch/$releasever/updates/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.ustc.edu.cn/centos-altarch/$releasever/extras/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://mirrors.ustc.edu.cn/centos-altarch/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32
sudo vi /etc/yum.repos.d/epel.repo
[epel]
name=Epel rebuild for armhfp
baseurl=https://armv7.dev.centos.org/repodir/epel-pass-1/
enabled=1
gpgcheck=0
重新缓存
yum makecache
yum update -y
yum upgrade -y
安装wget
yum install -y wget
安装gcc
yum install -y gcc
5、安装python3并配置pip
安装python3
下载python
#下载
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz
#解压
tar -zxvf Python-3.8.3.tgz
先安装make
yum install make -y
安装zlib,由于直接安装失败,我是通过源码安装的
yum -y install zlib -y
cd /var
mkdir www
cd www
mkdir setup
cd setup
wget http://www.im.com.cn/source/armhf/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make && make install
安装openssl
yum install -y openssl
编择python3
mkdir /usr/local/python3 #创建编译安装目录
cd Python-3.8.3
./configure --prefix=/opt/python-3.7.1 --with-openssl=/opt/openssl-1.0.2q
make && make install
最后成功会出现那列语句
Successfully installed pip-19.2.3 setuptools-41.2.0
创建软件连接
ll /usr/bin/ |grep python3
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
现在同时保留了原版python2.7 和新的python3
同样链接pip
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
给pip也换个源
mkdir ~/.pip/
vim ~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
五、建立用户,授予权限
. 修改文 件 /etc/rc.d/rc.local 与/etc/rc.local
setterm -powersave off -blank 0
这种方式在启动时再次设置。
adduser mee
passwd mee
chmod -v u+w /etc/sudoers
vim /etc/sudoers
找到root ALL=(ALL) ALL
然后添加temp_user ALL=(ALL) NOPASSWD:ALL
如需新用户使用sudo时不用输密码,把最后一个ALL改为NOPASSWD:ALL即可。
chmod -v u-w /etc/sudoers
六、安装小软件
1.安装iw管理wireless
#安装wifi管理软件
yum install -y iw
#安装USB管理软件
yum install -y usbutils
#安装v4l软件
yum install -y v4l-utils
#安装 NTFS 软件
yum install -y ntfs-3g
#unzip
yum install -y zip unzip
#用于安装git的前备软件
yum install -y install zlib-devel
yum install -y openssl-devel
yum install -y cpio
yum install -y expat-devel
yum install -y gettext-devel
yum install -y curl-devel
yum install -y perl-ExtUtils-CBuilder
yum install -y perl-ExtUtils-MakeMaker
yum install -y automake
#用于管理ipv6
yum install -y haveged
systemctl enable haveged
systemctl start haveged
2. 安装wire less tools
cd /var/www/setup
wget https://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29.tar.gz
wget http://www.inhhh.com/download/wireless_tools.29.tar.gz
tar -zxvf wireless_tools.29.tar.gz
cd /var/www/setup/wireless_tools.29
make
make install
reboot
#关闭power_save
sudo iw wlan0 set power_save off
查看 power_save
iw waln0 get power_save
Don’t forget to add /usr/local/lib/ to /etc/ld.so.conf, and run ldconfig as root
意思就是编辑
/etc/ld.so.conf, 文件,加上一行
vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib/
使生效
sudo ldconfig
测试命令
iwlist
iwconfig
七,重装git 2.25.1
wget https://github.com/git/git/archive/v2.25.1.zip
git --version
yum remove git -y
unzip v2.25.1.zip
cd git-2.25.1
make prefix=/usr/local all
make prefix=/usr/local install
vi /etc/profile
增加一行
PATH=/usr/local/bin:$PATH
source /etc/profile
echo $PATH
git --version
CentOS7取消服务器自动休眠
CentOS作为服务器操作系统,默认会自动休眠的设定有点匪夷所思。
手动关闭自动休眠的方法如下:
[root@CentOS ~]
# vi /etc/X11/xorg.conf
复制代码
Section “ServerFlags”
Option “BlankTime” “0” #关闭黑屏
Option “StandbyTime” “0” #关闭待机
Option “SuspendTime” “0” #关闭睡眠
Option “OffTime” “0”
EndSection
Section “Monitor”
Option “DPMS” “false”
EndSection
复制代码
[root@CentOS ~]
# reboot
八、安装wiringpi
cd /var/www/setup
mkdir WiringPi
cd WiringPi
#克隆库
git clone https://github.com/WiringPi/WiringPi.git
#进入文件夹
cd WiringPi
#编译安装
./build
gpio -v
九、安装opencv
安装pkg-config
cd /var/www/setup
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
tar -zxvf pkg-config-0.29.2.tar.gz
cd pkg-config-0.29.2
./configure --prefix=/usr/local/pkg-config --with-internal-glib
make
make install
yum install -y ffmpeg ffmpeg-devel
ffmpeg --version
#准备软件
yum install -y gcc
yum install -y gcc-c++
yum install -y gtk2-devel
yum install -y gimp-devel
yum install -y gimp-devel-tools
#yum install -y gimp-help-browser
#yum install -y zlib-devel
yum install -y libtiff-devel
yum install -y libjpeg-devel
yum install -y libpng-devel
yum install -y gstreamer-devel
yum install -y libavc1394-devel
yum install -y libraw1394-devel
yum install -y libdc1394-devel
yum install -y jasper-devel
yum install -y jasper-utils
yum install -y swig
yum install -y python
yum install -y libtool
yum install -y nasm
yum install -y numpy
yum install -y autoconf
yum install -y automake
yum install -y freetype-devel
yum install -y git
yum install -y make
yum install -y mercurial
yum install -y pkgconfig
yum install -y gstreamer-plugins-base-devel
yum install -y cmake
#下载opencv-3.4.14
cd /var/www/setup
mkdir opencv
cd opencv
wget http://www.im.com.cn/source/armhf/opencv-3.4.14.tar.gz
tar -zxvf opencv-3.4.14.tar.gz
cd opencv-3.4.14
mkdir release
cd release
#cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_PYTHON_SUPPORT=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_OPENGL=ON -D WITH_GTK=ON ..
make
make install
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}
pkg-config --modversion opencv
#添加库路径(创建opencv.conf文件)
输入命令:
vi /etc/ld.so.conf.d/opencv.conf
输入/usr/local/lib,并保存退出
#添加环境变量
输入命令:vi /etc/profile
在末尾加入:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
更新环境变量:source /etc/profile
#、设置另外环境变量
输入命令:vi /etc/bashrc
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
更新环境变量:source /etc/profile
#更新系统库缓存
输入命令:ldconfig
#、查看opencv是否安装成功
输入命令:pkg-config—cflags opencv
pkg-config—libs opencv
如果没有出错,说明安装成功。
#测试
输入命令:cd ..../OpenCV-2.4.0/samples/cpp
g++ `pkg-config --cflags --libs opencv` drawing.cpp -o drawing
./drawing
十、安装ffmpeg rtmp视频推流
1.安装准备软件
yum install -y yasm
2.源码编译安装 x264
cd /var/www/setup
mkdir x264
cd x264
# wget https://codeload.github.com/qupai/x264/zip/master
wget http://www.ingridmillet.com.cn/source/armhf/x264-master.zip
#tar -zxvf x264-master
unzip x264-master
cd x264-master
#查看帮助信息
./configure --help
#我们需要的是x264以.so or .a的形式来支援ffmpeg,所以一般就关注shared和static关键词就可以了, --disable-cli一定要填,不然make出错
./configure --prefix=/usr/local/x264 --enable-shared --enable-static --disable-cli --enable-strip --enable-yasm
make
make install
vim /etc/profile
末尾加入内容export PKG_CONFIG_PATH=/usr/local/x264/lib/pkgconfig,具体看各位自己x264的安装路径
source /etc/profile
3.源码编译安装 FFMPEG
在FFmpeg官网获取源码 http://ffmpeg.org/download.html ,当前版本为 ffmpeg-4.2.tar.bz2 ,配置完成后编译并安装
cd /var/www/setup
mkdir ffmpeg
cd ffmpeg
# wget https://ffmpeg.org/releases/ffmpeg-4.1.tar.bz2
# tar -jxvf ffmpeg-4.1.tar.bz2
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure --prefix=/usr/local/ffmpeg --enable-shared --enable-yasm --enable-libx264 --enable-gpl --enable-pthreads --extra-cflags=-I/usr/local/x264/include --extra-ldflags=-L/usr/local/x264/lib --disable-x86asm
make
make install
如果遇到错误,把相关lib目录添加到lib
find / -name libavdevice.so.58
#find / -name libx264.so.*
vim /etc/ld.so.conf
#将上述目录添加到最后一行并保存退出;
/sbin/ldconfig
#执行 ldconfig -v 命令,更新 ld.so.cache,使修改立即生效:
ldconfig -v
4. 创建软连接
#相当于 windows 中的创建快捷方式:
ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/local/bin/
ln -s /usr/local/ffmpeg/bin/ffprobe /usr/local/bin/
ln -s /usr/local/ffmpeg/bin/ffserver /usr/local/bin/
5. 头文件拷贝
#路径 /usr/local/ffmpeg/include/ 包含的文件信息如下:
cd /usr/local/ffmpeg/include/
ls
#/usr/local/ffmpeg/include 目录下创建 ffmpeg 目录:
mkdir ffmpeg
#将 /usr/local/ffmpeg/include 路径下所有目录复制到 ffmpeg 目录中:
复制代码
cp -r libswscale/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libswresample/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libpostproc/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavutil/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavformat/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavfilter/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavcodec/ /usr/local/ffmpeg/include/ffmpeg/
cp -r libavdevice/ /usr/local/ffmpeg/include/ffmpeg/
#将 /usr/local/ffmpeg/include 路径下 ffmpeg/ 目录复制到 /usr/include/:
cp -r ffmpeg/ /usr/include/
6.PKG_CONFIG_PATH 变量设置
ffmpeg 安装程序会在 /usr/local/ffmpeg/lib/pkgconfig 目录下提供 libavcodec.pc libswscale.pc 等5个.pc文件,分别对应安装的五个库文件。必须要让 pkg-config 能找到 ffmpeg 的 *.pc 文件,通过 PKG_CONFIG_PATH 来设置 pkg-config 来更新。
cd /usr/local/ffmpeg/lib/pkgconfig/
vim /etc/profile
#添加如下配置:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/ffmpeg/lib/pkgconfig
export FFMPEG_HOME=/usr/local/ffmpeg
export PATH=$PATH:$FFMPEG_HOME
#使配置立即生效:
source /etc/profile
4.测试推流
ffmpeg -version
ffmpeg -ss 0 -t 100 -pix_fmt yuv420p -i /dev/video0 -c:v h264_omx -f flv rtmp://10.8.0.188:8884/live
ffmpeg -ss 0 -t 100 -pix_fmt yuv420p -i /dev/video0 -c:v h264_v4l2m2 -f flv rtmp://10.8.0.188:8884/live