首页 > 系统相关 >RK平台之nginx移植

RK平台之nginx移植

时间:2023-06-14 17:02:18浏览次数:38  
标签:gnu -- ngx nginx linux NGX 移植 RK

1 下载源码并解压
wget http://nginx.org/download/nginx-1.12.2.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1h.tar.gz
wget https://sourceforge.net/projects/pcre/files/pcre/8.41/pcre-8.41.tar.bz2
wget https://www.zlib.net/fossils/zlib-1.2.11.tar.gz

2 步骤
2.1 设置交叉编译环境
$ vim ~/.bashrc
...
export PATH=/opt/zlg/m1808-sdk-v1.6.0-ga/host/bin:$PATH
export CC=aarch64-linux-gnu-gcc

$ source ~/.bashrc
$ aarch64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/opt/zlg/m1808-sdk-v1.6.0-ga_2021.07.16/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../libexec/gcc/aarch64-linux-gnu/6.3.1/lto-wrapper
Target: aarch64-linux-gnu
Configured with: '/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/snapshots/gcc.git~linaro-6.3-2017.05/configure' SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libmudflap --enable-lto --enable-shared --without-included-gettext --enable-nls --disable-sjlj-exceptions --enable-gnu-unique-object --enable-linker-build-id --disable-libstdcxx-pch --enable-c99 --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-arch=armv8-a --enable-threads=posix --enable-multiarch --enable-libstdcxx-time=yes --enable-gnu-indirect-function --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/sysroots/aarch64-linux-gnu --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu/aarch64-linux-gnu/libc --enable-checking=release --disable-bootstrap --enable-languages=c,c++,fortran,lto --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=aarch64-linux-gnu --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 6.3.1 20170404 (Linaro GCC 6.3-2017.05) 

2.2 修改nginx编译配置
nginx本身并不支持交叉编译,因此需要对其进行一定的修改。(具体修改看m1808-nginx-with-rtmp.patch里面的内容)

将m1808-nginx-with-rtmp.patch文件拷贝到解压后的nginx-1.12.2目录,并进入nginx-1.12.2源码目录,将m1808-nginx-with-rtmp.patch补丁打上

$ cd nginx-1.12.2/
$ patch -p1 <m1808-nginx-with-rtmp.patch

file: m1808-nginx-with-rtmp.patch

yanz@yanz-virtual-machine:~/opt/nginx-rtmp-build/nginx-1.12.2$ cat m1808-nginx-with-rtmp.patch 
diff --git a/auto/feature b/auto/feature
index 3561f59..bc43b6f 100644
--- a/auto/feature
+++ b/auto/feature
@@ -53,7 +53,7 @@ if [ -x $NGX_AUTOTEST ]; then
 
         yes)
             # /bin/sh is used to intercept "Killed" or "Abort trap" messages
-            if /bin/sh -c $NGX_AUTOTEST >> $NGX_AUTOCONF_ERR 2>&1; then
+#            if /bin/sh -c $NGX_AUTOTEST >> $NGX_AUTOCONF_ERR 2>&1; then
                 echo " found"
                 ngx_found=yes
 
@@ -61,9 +61,9 @@ if [ -x $NGX_AUTOTEST ]; then
                     have=$ngx_have_feature . auto/have
                 fi
 
-            else
-                echo " found but is not working"
-            fi
+#            else
+#                echo " found but is not working"
+#            fi
         ;;
 
         value)
diff --git a/auto/types/sizeof b/auto/types/sizeof
index 480d8cf..61dcd2d 100644
--- a/auto/types/sizeof
+++ b/auto/types/sizeof
@@ -14,7 +14,7 @@ END
 
 ngx_size=
 
-cat << END > $NGX_AUTOTEST.c
+cat << _EOF > $NGX_AUTOTEST.c
 
 #include <sys/types.h>
 #include <sys/time.h>
@@ -25,22 +25,41 @@ $NGX_INCLUDE_UNISTD_H
 $NGX_INCLUDE_INTTYPES_H
 $NGX_INCLUDE_AUTO_CONFIG_H
 
-int main(void) {
-    printf("%d", (int) sizeof($ngx_type));
+#if !defined( PASTE)
+#define PASTE2( x, y) x##y
+#define PASTE( x, y)  PASTE2( x, y)
+#endif /* PASTE */
+
+#define SAY_IF_SIZEOF( typename, type, size)   \\
+    static char PASTE( PASTE( PASTE( sizeof_, typename), _is_), size) \\
+    [(sizeof(type) == (size)) ? 1 : -1]
+
+SAY_IF_SIZEOF(TEST_TYPENAME, TEST_TYPE, TEST_SIZE);
+
+int main(void)
+{
     return 0;
 }
 
-END
+_EOF
 
 
-ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
-          -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
+_ngx_typename=`echo "$ngx_type" | sed 's/ /_/g;s/\*/p/'`
+ngx_size="-1"
+ngx_size=`for i in 1 2 4 8 16 ; do \
+    $CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
+    -DTEST_TYPENAME="$_ngx_typename" -DTEST_TYPE="$ngx_type" -DTEST_SIZE="$i" \
+    $NGX_AUTOTEST.c -o $NGX_AUTOTEST \
+    $NGX_LD_OPT $ngx_feature_libs >/dev/null 2>&1 || continue ;\
+    echo $i ; break ; done`
 
-eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
+rm -rf $NGX_AUTOTEST*
 
+if test -z $ngx_size ; then
+    ngx_size=-1
+fi
 
-if [ -x $NGX_AUTOTEST ]; then
-    ngx_size=`$NGX_AUTOTEST`
+if [ $ngx_size -gt 0 ]; then
     echo " $ngx_size bytes"
 fi
 
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c
index 7756370..d086f37 100644
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -4,7 +4,7 @@
  * Copyright (C) Nginx, Inc.
  */
 
-
+#define _GNU_SOURCE
 #include <ngx_config.h>
 #include <ngx_core.h>
 #include <ngx_event.h>
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
index 7d6ca76..06f1cb4 100644
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -54,6 +54,7 @@ typedef int               ngx_err_t;
 #define NGX_ENOMOREFILES  0
 #define NGX_ELOOP         ELOOP
 #define NGX_EBADF         EBADF
+#define NGX_SYS_NERR            1
 
 #if (NGX_HAVE_OPENAT)
 #define NGX_EMLINK        EMLINK
diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
index c128c9a..cb947da 100644
--- a/src/os/unix/ngx_time.h
+++ b/src/os/unix/ngx_time.h
@@ -8,7 +8,7 @@
 #ifndef _NGX_TIME_H_INCLUDED_
 #define _NGX_TIME_H_INCLUDED_
 
-
+#include <time.h>
 #include <ngx_config.h>
 #include <ngx_core.h>


2.3 新建config.sh脚本,添加configure配置项
$ vim config.sh
./configure \                                                                             
    --crossbuild=Linux::aarch64 \
    --with-ld-opt= \
    --with-ipv6 \
    --prefix=../nginx-install/ \
    --conf-path=/etc/nginx/nginx.conf \
    --sbin-path=/usr/sbin/nginx \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/run/lock/nginx.lock \
    --user=www-data \
    --group=www-data \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --http-client-body-temp-path=/var/tmp/nginx/client-body \
    --http-proxy-temp-path=/var/tmp/nginx/proxy \
    --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
    --http-scgi-temp-path=/var/tmp/nginx/scgi \
    --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
    --with-threads \
    --with-pcre=../pcre-8.41 \
    --with-openssl=../openssl-1.1.1h \
    --with-openssl-opt="no-shared linux-armv4 --cross-comile-prefix=aarch64-linux-gnu- " \
    --with-zlib=../zlib-1.2.11 \
    --without-select_module \
    --without-poll_module \
    --without-http-cache \
    --with-http_ssl_module \
    --with-http_sub_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-http_auth_request_module \
    --add-module=../nginx-rtmp-module-master \
    --with-debug \
    --with-cc-opt='-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -DUSE_UPDATEENGINE=ON -DSUCCESSFUL_BOOT=ON'

2.4 对objs/Makefile的修改
执行./config.sh脚本后生成用于编译的objs/Makefile文件,由于在configure配置项上无法配置pcre的交叉编译环境,因此在执行make编译前,还需要对objs/Makefile做修改。

打开objs/Makefile

1 添加pcre的交叉编译环境,如下:

2 由于编译链接libcrypto.a库时需要加在-ldl -lpthread的前面,否则会报错,因此修改objs/Makefile如下:

3 由于通过objs/Makefile直接编译openssl,在编译过程中会出现交叉编译环境不正确的情况。最终采用以下方式解决openssl交叉编译问题,如下:
在执行make编译前,先进入到…/openssl-1.1.1h/的目录,执行如下Configure配置:

$ ./Configure \                                                                             
    linux-armv4 \
    --prefix=/home/yanz/opt/nginx-rtmp-build/openssl-1.1.1h/.openssl \
    no-shared no-asm no-ssl2 \
    -DOPENSSL_USE_IPV6 \
    -DOPENSSL_NO_DYNAMIC_ENGINE

这里暂不对openssl的配置命令做详述,有兴趣可以查阅相关资料。

然后回到nginx-1.12.2源码目录下,修改objs/Makefile,将一下两行配置删除:

删除后,如下:


2.5 编译
通过以上修改后,执行make进行编译,此时可以看到编译时使用正确的交叉编译工具aarch64-linux-gnu-gcc进行编译即可。

编译完成后在objs/目录下生成可执行文件nginx,使用file命令查看nginx运行平台:


2.6 测试
在板子上执行如下命令,停止nginx服务:

killall nginx

将生成的nginx可执行程序拷贝到板子上/usr/sbin/目录下,并启动nginx服务器:

//启动nginx
$ /usr/sbin/nginx

修改/etc/nginx/nginx.conf配置文件,添加rtmp配置:

执行如下命令重新加载配置:

# nginx -s reload
1
配置板子ip地址与电脑处于同一网口,此处测试配置板子ip: 192.168.1.136
在板子上执行ffmpeg推流命令:

# ffmpeg -re -i ./test.mp4 -c copy -f flv rtmp://192.168.1.136:1935/myapp/test

在电脑上用vlc播放rtmp://192.168.1.136:1935/myapp/test即可。

标签:gnu,--,ngx,nginx,linux,NGX,移植,RK
From: https://www.cnblogs.com/kn-zheng/p/17480765.html

相关文章

  • Ubuntu 源代码编译安装 Nginx
    建立nginx用户和用户组sudogroupaddnginxsudouseraddnginx-gnginx-s/sbin/nologin-M在线安装依赖sudoapt-yinstallgccmakeopenssllibssl-devlibpcre3libpcre3-devlibgd-devvimwgetnet-tools下载并解压nginx源代码wgethttp://nginx.org/download/nginx-1.24......
  • Flink 的 checkpoint 机制对比 spark 有什么不同和优势?
    sparkstreaming的checkpoint仅仅是针对driver的故障恢复做了数据和元数据的checkpoint。而flink的checkpoint机制要复杂很多,它采用的是轻量级的分布式快照,实现了每个算子的快照,及流动中的数据的快照。......
  • 如何在Ubuntu Nginx上安装fcgiwrap
    fcgiwrap是一个简单的服务器,用于在FastCGI上运行CGI应用程序。我们可以用它来为nginxwebserver提供干净的CGI支持。它是一个轻量级的服务器,具有零配置选项,可以使用同一个池来运行不同的站点。本文介绍了如何在Ubuntu20.04上安装fcgiwrap。CGI的意思是CommonGatewayInterface,......
  • WPF在win10/11上启用模糊特效 适配Dark/Light Mode
    先看效果图win11:win10: 大佬们已经总结了许多在WPF上开启亚克力效果的方法,本文只是做一些填坑和适配工作.正文开始先来看看部分版本Windows的模糊效果和我的适配方案:1).早期Windows10:SetWindowCompositionAttribute方法参照:在Windows10上为WPF窗口添加模糊特......
  • 悟空派WuKongPi全志H3(香橙派orangepi zero)折腾记录(u-boot移植)
    最近在某宝上看到一个悟空派,仔细一看这不就是香橙派orangepizero吗,不过它的USB是Type-C,于是我买了一块打算折腾一下。 拿到了首先获取一下u-boot源码,因为板子和香橙派orangepizero一样就直接用香橙派的源码了gitclonehttps://github.com/orangepi-xunlong/u-boot-orange......
  • 压测: wrk压测的lua脚本使用随机列表与字符串参数
    ......
  • Network File System 网络文件系统(centos 6)
    预备知识:1 什么是程序、进程、线程?程序:安装的软件就是程序进程:运行的程序---就是进程线程:运行的程序同时完成多个任务2 NFS三个主要组件?Rpc.nfsd  :它是基本的NFS守护进程,主要功能是管理客户端是否能够登录服务器;(由nfs进程实现)Rpc.mount:主要功能是管理NFS......
  • Nginx 重啟/修改conf後生效
    Nginx重啟/修改conf後生效 1.程序運行參數Nginx安裝後只有一個程序文件,本身並不提供各種管理程序,它是使用參數和系統信號機制對Nginx進程本身進行控制的。Nginx的參數包括有如下幾個:-c<path_to_config>:使用指定的配置文件而不是conf目錄下的nginx.conf。-t:測試配置......
  • mac下nginx+tomcat+memcached集群配置和共享session
     mac下nginx+tomcat+memcached集群配置和共享session  首先分别安装nginx(版本1.5.8)、tomcat(版本7.0)、memcached(版本1.4.17),具体安装说明请分别参考下面的文章。 nginx安装说明 http://stephen830.iteye.com/blog/2002195tomcat安装说明http://stephen830.iteye.com/blog/2001......
  • 在上一操作期间遇到问题:Debug|AnyCPU 配置中 TargetFrameworkMoniker和NugetTargetMon
    在上一操作期间遇到问题:Debug|AnyCPU配置中TargetFrameworkMoniker和NugetTargetMoniker属性的值均为空场景使用VS打开之前的项目,报错:在上一操作期间遇到问题:Debug|AnyCPU配置中TargetFrameworkMoniker和NugetTargetMoniker属性的值均为空新建项目后,选择该项目未项......