Nginx: Streaming with RTMP / DASH / HLS: Unterschied zwischen den Versionen

Aus QBWiki
Zur Navigation springenZur Suche springen
Zeile 11: Zeile 11:
 
git clone https://github.com/nginx/nginx.git
 
git clone https://github.com/nginx/nginx.git
 
</code>
 
</code>
 +
<syntaxhighlight lang="bash" line="1">
 +
apt install iptables-persistent wget curl iptraf-ng dnsutils git build-essential ffmpeg libpcre3 libpcre3-dev libssl-dev zlib1g-dev dehydrated vim
 +
mkdir -p /var/www
 +
 +
# Iptables
 +
iptables -A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
 +
iptables -A INPUT -p udp -m state --state RELATED,ESTABLISHED -j ACCEPT
 +
iptables -A INPUT -i lo -j ACCEPT
 +
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
 +
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
 +
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
 +
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 1935 -j ACCEPT
 +
iptables -A INPUT -p icmp -m icmp --icmp-code 0 -j ACCEPT
 +
iptables -A INPUT -p icmp -m icmp --icmp-code 3 -j ACCEPT
 +
iptables -A INPUT -p icmp -m icmp --icmp-code 8 -j ACCEPT
 +
iptables -P INPUT DROP
 +
iptables -P FORWARD DROP
 +
iptables-save > /etc/iptables/rules.v4
 +
 +
hostname -f > /etc/dehydrated/domains.txt
 +
sed -i -e 's/WELLKNOWN.*/WELLKNOWN=\/var\/www\/acme-challenge/g' /etc/dehydrated/config
 +
 +
working_dir="/opt"
 +
 +
# Create Nginx User
 +
adduser --system --no-create-home --shell /bin/false --group --disabled-login nginx
 +
 +
# Create Nginx directories:
 +
mkdir -p /etc/nginx
 +
mkdir -p /var/log/nginx
 +
mkdir -p /run/nginx
 +
mkdir -p /var/cache/nginx
 +
 +
# Permissions
 +
chown -R nginx:nginx /etc/nginx
 +
chown -R nginx:nginx /var/log/nginx
 +
chown -R nginx:nginx /run/nginx
 +
chown -R nginx:nginx /var/cache/nginx
 +
 +
cd "${working_dir}"
 +
 +
git clone https://github.com/arut/nginx-rtmp-module.git
 +
git clone https://github.com/nginx/nginx.git
 +
 +
cd "${working_dir}/nginx"
 +
mv "${working_dir}/nginx/auto/configure" "${working_dir}/nginx"
 +
chmod +x "${working_dir}/nginx/configure"
 +
 +
arg_chain='--prefix=/etc/nginx --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log --user=nginx --group=nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_gunzip_module --with-debug --add-module=/opt/nginx-rtmp-module --http-client-body-temp-path=/var/cache/nginx/client_body_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --http-log-path=/var/log/nginx/access.log'
 +
 +
./configure ${arg_chain}
 +
 +
# NGINX-RTMP-ERROR beheben (OBSOLET)
 +
#linenum="$(grep -Rn 'case ESCAPE' /opt/nginx-rtmp-module/ngx_rtmp_eval.c |awk -F':' '{print $1}')"
 +
#insertnum="$(($linenum - 1 ))"
 +
#
 +
#sed -i "${insertnum} a /* fall through */" /opt/nginx-rtmp-module/ngx_rtmp_eval.c
 +
 +
make -j`nproc`
 +
make install
 +
 +
# Systemd Service-file
 +
 +
tee /usr/lib/systemd/system/nginx.service <<EOF
 +
[Unit]
 +
Description=A high performance web server and a reverse proxy server
 +
After=network.target
 +
 +
[Service]
 +
Type=forking
 +
PIDFile=/run/nginx/nginx.pid
 +
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
 +
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
 +
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
 +
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
 +
TimeoutStopSec=5
 +
KillMode=mixed
 +
 +
[Install]
 +
WantedBy=multi-user.target
 +
EOF
 +
 +
 +
systemctl daemon-reload
 +
systemctl enable nginx
 +
 +
mv /etc/nginx /etc/default.nginx
 +
mkdir -p /etc/nginx/{conf.d,rtmp.d,}
 +
chown -R nginx:nginx /etc/nginx
 +
 +
systemctl start nginx
 +
 +
</syntaxhighlight>

Version vom 12. Juni 2022, 13:39 Uhr


Abhängigkeiten

root@master01 $ > apt install git build-essential libpcre3-dev libssl-dev zlib1g-dev

Fetch Nginx + Modules

cd /opt

git clone https://github.com/arut/nginx-rtmp-module.git

git clone https://github.com/nginx/nginx.git

 1 apt install iptables-persistent wget curl iptraf-ng dnsutils git build-essential ffmpeg libpcre3 libpcre3-dev libssl-dev zlib1g-dev dehydrated vim
 2 mkdir -p /var/www
 3 
 4 # Iptables
 5 iptables -A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
 6 iptables -A INPUT -p udp -m state --state RELATED,ESTABLISHED -j ACCEPT
 7 iptables -A INPUT -i lo -j ACCEPT
 8 iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
 9 iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
10 iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
11 iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 1935 -j ACCEPT
12 iptables -A INPUT -p icmp -m icmp --icmp-code 0 -j ACCEPT
13 iptables -A INPUT -p icmp -m icmp --icmp-code 3 -j ACCEPT
14 iptables -A INPUT -p icmp -m icmp --icmp-code 8 -j ACCEPT
15 iptables -P INPUT DROP
16 iptables -P FORWARD DROP
17 iptables-save > /etc/iptables/rules.v4
18 
19 hostname -f > /etc/dehydrated/domains.txt
20 sed -i -e 's/WELLKNOWN.*/WELLKNOWN=\/var\/www\/acme-challenge/g' /etc/dehydrated/config
21 
22 working_dir="/opt"
23 
24 # Create Nginx User
25 adduser --system --no-create-home --shell /bin/false --group --disabled-login nginx
26 
27 # Create Nginx directories:
28 mkdir -p /etc/nginx
29 mkdir -p /var/log/nginx
30 mkdir -p /run/nginx
31 mkdir -p /var/cache/nginx
32 
33 # Permissions
34 chown -R nginx:nginx /etc/nginx
35 chown -R nginx:nginx /var/log/nginx
36 chown -R nginx:nginx /run/nginx
37 chown -R nginx:nginx /var/cache/nginx
38 
39 cd "${working_dir}"
40 
41 git clone https://github.com/arut/nginx-rtmp-module.git
42 git clone https://github.com/nginx/nginx.git
43 
44 cd "${working_dir}/nginx"
45 mv "${working_dir}/nginx/auto/configure" "${working_dir}/nginx"
46 chmod +x "${working_dir}/nginx/configure"
47 
48 arg_chain='--prefix=/etc/nginx --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log --user=nginx --group=nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_gunzip_module --with-debug --add-module=/opt/nginx-rtmp-module --http-client-body-temp-path=/var/cache/nginx/client_body_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --http-log-path=/var/log/nginx/access.log'
49 
50 ./configure ${arg_chain}
51 
52 # NGINX-RTMP-ERROR beheben (OBSOLET)
53 #linenum="$(grep -Rn 'case ESCAPE' /opt/nginx-rtmp-module/ngx_rtmp_eval.c |awk -F':' '{print $1}')"
54 #insertnum="$(($linenum - 1 ))"
55 #
56 #sed -i "${insertnum} a /* fall through */" /opt/nginx-rtmp-module/ngx_rtmp_eval.c
57 
58 make -j`nproc`
59 make install
60 
61 # Systemd Service-file
62 
63 tee /usr/lib/systemd/system/nginx.service <<EOF
64 [Unit]
65 Description=A high performance web server and a reverse proxy server
66 After=network.target
67 
68 [Service]
69 Type=forking
70 PIDFile=/run/nginx/nginx.pid
71 ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
72 ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
73 ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
74 ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
75 TimeoutStopSec=5
76 KillMode=mixed
77 
78 [Install]
79 WantedBy=multi-user.target
80 EOF
81 
82 
83 systemctl daemon-reload
84 systemctl enable nginx
85 
86 mv /etc/nginx /etc/default.nginx
87 mkdir -p /etc/nginx/{conf.d,rtmp.d,}
88 chown -R nginx:nginx /etc/nginx
89 
90 systemctl start nginx