FFmpeg循环推流脚本

转载过来备用,原文链接见文章结尾。

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================================#
#   System Required: CentOS7 X86_64                               #
#   Description: FFmpeg Stream Media Server                       #
#   Author: LALA                                    #
#   Website: https://www.lala.im                                  #
#=================================================================#

# 颜色选择
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
font="\033[0m"

ffmpeg_install(){
# 安装FFMPEG
read -p "你的机器内是否已经安装过FFmpeg4.x?安装FFmpeg才能正常推流,是否现在安装FFmpeg?(yes/no):" Choose
if [ $Choose = "yes" ];then
	yum -y install wget
	wget --no-check-certificate https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-4.0.3-64bit-static.tar.xz
	tar -xJf ffmpeg-4.0.3-64bit-static.tar.xz
	cd ffmpeg-4.0.3-64bit-static
	mv ffmpeg /usr/bin && mv ffprobe /usr/bin && mv qt-faststart /usr/bin && mv ffmpeg-10bit /usr/bin
fi
if [ $Choose = "no" ]
then
    echo -e "${yellow} 你选择不安装FFmpeg,请确定你的机器内已经自行安装过FFmpeg,否则程序无法正常工作! ${font}"
    sleep 2
fi
	}

stream_start(){
# 定义推流地址和推流码
read -p "输入你的推流地址和推流码(rtmp协议):" rtmp

# 判断用户输入的地址是否合法
if [[ $rtmp =~ "rtmp://" ]];then
	echo -e "${green} 推流地址输入正确,程序将进行下一步操作. ${font}"
  	sleep 2
	else  
  	echo -e "${red} 你输入的地址不合法,请重新运行程序并输入! ${font}"
  	exit 1
fi 

# 定义视频存放目录
read -p "输入你的视频存放目录 (格式仅支持mp4,并且要绝对路径,例如/opt/video):" folder

# 判断是否需要添加水印
read -p "是否需要为视频添加水印?水印位置默认在右上方,需要较好CPU支持(yes/no):" watermark
if [ $watermark = "yes" ];then
	read -p "输入你的水印图片存放绝对路径,例如/opt/image/watermark.jpg (格式支持jpg/png/bmp):" image
	echo -e "${yellow} 添加水印完成,程序将开始推流. ${font}"
	# 循环
	while true
	do
		cd $folder
		for video in $(ls *.mp4)
		do
		ffmpeg -re -i "$video" -i "$image" -filter_complex overlay=W-w-5:5 -c:v libx264 -c:a aac -b:a 192k -strict -2 -f flv ${rtmp}
		done
	done
fi
if [ $watermark = "no" ]
then
    echo -e "${yellow} 你选择不添加水印,程序将开始推流. ${font}"
    # 循环
	while true
	do
		cd $folder
		for video in $(ls *.mp4)
		do
		ffmpeg -re -i "$video" -c:v copy -c:a aac -b:a 192k -strict -2 -f flv ${rtmp}
		done
	done
fi
	}

# 停止推流
stream_stop(){
	screen -S stream -X quit
	killall ffmpeg
	}

# 开始菜单设置
echo -e "${yellow} CentOS7 X86_64 FFmpeg无人值守循环推流 For LALA.IM ${font}"
echo -e "${red} 请确定此脚本目前是在screen窗口内运行的! ${font}"
echo -e "${green} 1.安装FFmpeg (机器要安装FFmpeg才能正常推流) ${font}"
echo -e "${green} 2.开始无人值守循环推流 ${font}"
echo -e "${green} 3.停止推流 ${font}"
start_menu(){
    read -p "请输入数字(1-3),选择你要进行的操作:" num
    case "$num" in
        1)
        ffmpeg_install
        ;;
        2)
        stream_start
        ;;
        3)
        stream_stop
        ;;
        *)
        echo -e "${red} 请输入正确的数字 (1-3) ${font}"
        ;;
    esac
	}

# 运行开始菜单
start_menu
继续阅读

Prometheus+Grafana运维级监控部署

在之前的网站uptime监控中提到过Prometheus+Grafana监控搭配,抽空自己部署了一遍,功能强大,达到了运维级。

Prometheus是主控程序,是监控的Server端。

Node exporter是client端,部署在被监控vps上,用于采集vps数据,向Prometheus传输数据。

Grafana是开源的看板/面板程序,提供可视化图形界面。

三者相结合,提供了一套完整的运维级监控系统。如果需要监控警报,还需要加入Alertmanager。

Prometheus、Node exporter、Altermanager开源地址:

https://github.com/prometheus

Grafana开源地址:https://github.com/grafana/grafana

下面记录下部署过程。

1、docker部署Prometheus

选择用docker部署,简单方便。注意映射9090端口,及prometheus.yml配置文件目录。我这里以/opt/config目录为例:

docker run \
    -p 9090:9090 \
    -v /opt/config:/etc/prometheus \
    prom/prometheus

将宿主机/opt/config目录,挂载到docker的/etc/prometheus目录。

如果是二进制安装,步骤为:

tar zxf prometheus-2.25.0.linux-amd64.tar.gz -C /opt
mv /opt/prometheus-2.25.0.linux-amd64 /opt/prometheus
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus service
 
[Service]
User=root
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data
 
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
 
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
systemctl status prometheus

每次更改了Prometheus配置文件,都需要重启:

systemctl restart prometheus

2、配置prometheus.yml文件

以下为最简单的默认配置文件

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9100']
        labels:
          instance: prometheus

添加配置文件之后,docker程序才能正常启动。

此时访问http://ip:9090端口,访问Prometheus控制界面。目前界面很简陋,所以需要继续部署grafana。

3、部署Grafana面板程序

以debian为例:

sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key

添加源:

echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

安装grafana:

sudo apt-get update
sudo apt-get install grafana

启动Grafana:

sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server

配置随机启动:

sudo systemctl enable grafana-server.service

浏览器访问IP:3000端口,即可打开grafana页面,默认用户名密码都是admin,初次登录会要求修改默认的登录密码。

详细安装说明参考grafana官方:https://grafana.com/docs/grafana/latest/setup-grafana/installation/debian/

也可以选择docker安装grafana,更简单方便,参考官方文档:https://grafana.com/grafana/download/11.1.5?edition=enterprise&platform=docker

4、为Grafana添加Prometheus数据源

点击主界面的“Add your first data source”并选择Prometheus,import,保存即可。

当然你还可以添加更多目标,看到更多详细的数据,Grafana官方也提供了很多dashboard的模板:

https://grafana.com/grafana/dashboards/

推荐排名第一的Node Exporter Full。安装模板也很简单,直接复制模板ID(Copy ID to clipboard)

Grafana后台 – Dashboards – Browse – New – Import – 粘贴ID – Load – 并选择数据源为Prometheus。搞定

5、部署Node exporter

在需要被监控的vps上部署node exporter,当然也可以在Prometheus所在vps上部署,监控本机。

选择下载对应版本并解压:

wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar xvfz node_exporter-1.5.0.linux-amd64.tar.gz
mv /root/node_exporter-1.5.0.linux-amd64 /opt/node_exporter

配置开机启动:

vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter service
 
[Service]
User=root
ExecStart=/opt/node_exporter/node_exporter
 
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
 
[Install]
WantedBy=multi-user.target

如果报错,也可以 vi /etc/systemd/system/node_exporter.service

关于Linux service配置文件的说明,请参考:https://wizardforcel.gitbooks.io/vbird-linux-basic-4e/content/150.html

systemctl daemon-reload
systemctl enable node_exporter

启动服务:

systemctl start node_exporter
systemctl status node_exporter

node exporter默认监控端口是9100,访问ip:9100可以查看node exporter。

注意:在vps面板防火墙中放行9100端口,同时如果vps安装了宝塔等程序,也需要在”安全“中放行9100端口。

iptables也要放行9100:

iptables -I INPUT -s 0.0.0.0/0 -p tcp --dport 9100 -j ACCEPT

6、Node exporter与Prometheus建立连接,传送数据。

编辑Prometheus的prometheus.yml文件,添加以下代码,注意对齐:

  - job_name: 'Linux'
    static_configs:
      - targets: ['xx.xx.xx.xx:9100']
        labels:
          instance: 168itw.com

重启docker Prometheus。

继续阅读

Debian/Ubuntu安装ffmpeg和streamlink

首先update系统。

安装ffmpeg:

apt-get install ffmpeg

安装streamlink

1、安装pip3

apt-get install python3-pip

2、通过pip安装最新版streamlink

pip3 install --user --upgrade streamlink

3、添加环境变量。

如果是root用户安装,在/root/.bashrc中添加以下代码;

如果是Ubuntu安装,在/home/ubuntu/.bashrc中添加以下代码;

export PATH="${HOME}/.local/bin:${PATH}"

4、重连ssh,查看streamlink是否安装成功:

streamlink -V

debian设置ssh密钥登录

1、生成密钥

ssh-keygen

或者:

ssh-keygen -t rsa

一路回车即可。在 root 用户目录中生成了一个 .ssh 目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。

2、在服务器上安装公钥

[root@host ~]$ cd .ssh
[root@host .ssh]$ cat id_rsa.pub >> authorized_keys

如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确:

[root@host .ssh]$ chmod 600 authorized_keys
[root@host .ssh]$ chmod 700 ~/.ssh

3、设置 SSH,打开密钥登录功能

编辑 /etc/ssh/sshd_config 文件,进行如下设置(删除这两行前面的注释#):

AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2
PubkeyAuthentication yes

168itw注:AuthorizedKeysFile不启用,貌似也不影响,没明白这里的作用!

确保允许root 用户通过 SSH 登录:

PermitRootLogin yes

重启ssh服务:

service sshd restart

切换为root用户和密码登录后,下载 .ssh 目录下的私钥文件id_rsa,导入ssh客户端。

确保root用户能够通过密钥登录。

当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:

PasswordAuthentication no

最后,重启 SSH 服务:

[root@host .ssh]$ service sshd restart
继续阅读

常用的数据库管理软件收集

phpmyadmin经常爆出漏洞,而且装在服务器上会占用资源。

收集了一些常用到数据库管理软件,可以直接安装在本地Windows或者Mac。

一、navicat

收费,支持的数据库最全,不过可以教育邮箱学生版激活,网上也有注册机/注册码/破解版,GitHub上也有无限重置试用 navicat premium所有版本的脚本。

https://github.com/malaohu/reset-navicat-premium

https://github.com/yhan219/navicat_reset_mac

二、DBeaver

免费,支持的数据库也很全,我目前就是用的这个。

三、HeidiSQL

免费开源,用的人也很多。

四、TablePlus

收费,网上也能找到序列号。

NAT VPS自建DDNS的几种方法

一、Cloudflare API

这种方法应该是用的最多的。

前提条件:

  • 自有域名
  • 域名已接入Cloudflare

1.获取Global API Key

登入Clooudflare查看:https://dash.cloudflare.com/profile/api-tokens

2.设置DDNS域名

在Cloudflare DNS面板中新建A 记录,例如myddns 指向1.1.1.1 并关闭CF代理开关让云朵灰色。

3.下载cf-ddns脚本

wget -N --no-check-certificate https://raw.githubusercontent.com/yulewang/cloudflare-api-v4-ddns/master/cf-v4-ddns.sh

也可以用GitHub另外2个脚本:

https://github.com/jeessy2/ddns-go

https://github.com/NewFuture/DDNS

4.编辑cf-ddns脚本

vi cf-v4-ddns.sh

或者

​nano cf-v4-ddns.sh

修改脚本中,对应的信息。

# API key, see https://www.cloudflare.com/a/account/my-account,
# incorrect api-key results in E_UNAUTH error
CFKEY=您的Global API Key

# Username, eg: [email protected]
CFUSER=您Cloudflare的帐户名称

# Zone name, eg: example.com
CFZONE_NAME=您的域名

# Hostname to update, eg: homeserver.example.com
CFRECORD_NAME=你的二级域名

保存并退出编辑界面

5.修改cf-ddns脚本权限

chmod +x cf-v4-ddns.sh

6.测试运行脚本

./cf-v4-ddns.sh

##如果上面的步骤无误,您会看到Cloudflare DNS面板中。

##刚才您新建的A 记录IP已更新为VPS的公网IP

7.设定定时任务自动更新ddns的IP

crontab -e

##有些系统会提示让您选择vi或nano编辑定时脚本,选择您熟悉的编辑工具即可

##插入下面一下,表示每分钟更新ddns

*/1 * * * * /root/cf-v4-ddns.sh >/dev/null 2>&1

保存退出。

二、he.net DDNS

he.net的DDNS非常方便,不需要任何脚本,curl请求即可,添加crontab定时任务。

具体参考:https://dns.he.net/docs.html

crontab参考:

*/1 * * * * curl -4 "https://dyn.example.com:[email protected]/nic/update?hostname=dyn.example.com"

he.net会获取当前vps的IP地址更新到dns记录。

三、Dynu.com、ChangeIP.com等

这种很简单,直接注册,然后根据官方提供的脚本更新DNS记录即可。

上面三种方法,都会有一个问题,DDNS生效时间和DNS缓存时间,会导致NAT更换IP后中断几分钟不等。比如cloudflare免费用户DNS TTL是1分钟,he.net是5分钟,dynu是30s。

所以就有了第四种方法,也是最优解决方案。

四、Cloudflare Tunnel

借助cloudflare tunnel实现内网穿透,不受ddns影响,而且完全免费。

cloudflare runnel功能很强大,具体参考官方教程:https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/

OpenWrt常用固件收集与下载

OpenWrt是开源的基于Linux的路由器系统。本文收集整理了市面上(主要是恩山论坛)较为流行、使用人数较多、且评价不错的固件。

update: 2025.7.15

新增 ImmortalWrt:https://github.com/immortalwrt/immortalwrt

口碑不错,开源,使用人数也很多。

openwrt.ai,这是一个自定义半定制的固件。

1、sirpdboy

sirpdboy openwrt固件应该是用户最多、反馈最好的固件了吧,在Github上开源。

Github项目地址:https://github.com/sirpdboy/openwrt

下载:【123云盘工具下载】链接: https://www.123pan.com/s/dS5A-Hoxqd 提取码:MwhD -【123云盘固件下载】链接: https://www.123pan.com/s/dS5A-nJxqd 提取码:nxFY

后台登陆192.168.8.1 密码无

2、eSir

使用人数多,更新快,每月一号更新,管理IP:192.168.5.1,密码:password

eSir固件分三个版本:精简版、高大全、佛跳墙。

下载地址如下,都是eSir自己的Google网盘地址。

eSir x86 精品小包:https://drive.google.com/drive/folders/1eyIxVfyzO4nyzaT1sSr6xWf50_5YJN7g

eSir的x86固件高大全版:https://drive.google.com/drive/folders/1PsS3c0P7a4A4KY8plQg4Fla8ZI-PGBb1

eSir的x86固件 佛跳墙版:https://drive.google.com/drive/folders/1ktbDgnnP8pTMERjpPuETNphzAjNA6hZ2

恩山网友整理的下载地址:

「夏季版本」https://www.aliyundrive.com/s/jxUNKMKQdiS 提取码: x20a

3、flippy的N1盒子固件

链接:https://pan.baidu.com/s/1kbvtyxpcmniLKN_ziH-kqQ 提取码:jla9

恩山:https://www.right.com.cn/forum/thread-4076037-1-1.html

4、小鸡过河

好评差评都有,请自行判断。

恩山地址:https://www.right.com.cn/forum/thread-8223107-1-1.html

Github:https://github.com/kiddin9/OpenWrt_x86-r2s-r4s-r5s-N1

5、SuLingGG

Github:https://github.com/SuLingGG/OpenWrt-Rpi

6、骷髅头

Github:https://github.com/DHDAXCW/OpenWRT_x86_x64

7、Lean的 Openwrt 项目

Github:https://github.com/coolsnowwolf/lede

2025补充:

iStoreOS: https://fw.koolcenter.com/iStoreOS/

iStoreOS N1固件:https://fw.koolcenter.com/iStoreOS/alpha/n1/

附软路由刷openwrt简单三步走教程:

  1. 下载写U盘工具:balenaEtcher,将固件写入U盘。
  2. 将N1盒子用网线跟电脑连接,浏览器192.168.1.1进后台 — 晶晨宝盒 — 安装OpenWrt。
  3. 等等安装完成,拔掉U盘和电源,重新接通并接入主路由网线。

N1旁路由网络设置:

在“基本设置”上,协议选择“静态地址”,“IPV4网关”和“使用自定义的DNS服务器”填写你的主路由的IP地址,“IPV4地址”是设置你的N1的IP地址。“IPV4地址”的前面三个字段要和你的主路由IP一样

Python错误:UnicodeEncodeError: ‘latin-1’ codec can’t encode

Python部署一个项目,运行的时候提示错误:

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-9: ordinal not in range(256)

网上查询说是环境变量问题,python默认编码是  latin1,更改下环境变量。运行以下代码顺利解决。

export PYTHONUTF8=1

顺便记录下Python安装、及过程。

Debian 10安装Python

Debain 10是包换python 2和 python 3的。只需要:

apt update && apt upgrade

查看python版本:

python --version
python3 --version

或者用 python -V查看。

安装pip

apt-get install python3-pip
继续阅读

关于dropshipping速卖通Aliexpress的替代

这篇文章是在blackhatworld看到的,挺好的分享,我就转载过来了,做了一些归纳和总结,原文链接在文章结尾。

Here other best AliExpress alternatives for dropshipping based on my knowledge which can ship the item fast and have good quality as your reference. 🙂

  1. Spocket: This company provides US and EU dropshipping suppliers. The product will be shipped from the US or EU, so you will not face a long shipping time, the quality product also great.
  2. Salehoo
  3. Printful & Printify: Print On Demand Manufactur base in the USA, EURO, JAP, and AUS. The company can fulfill the order fast with good quality. I myself using Printful and Printify to do Shopify Dropshipping POD by collaborating with an artist (Organic traffic). This allows me to ship good quality products fast from the US, EU, and AUS.
  4. eBay: We can approach several eBay sellers based in the USA as dropshipping suppliers by sending them a message and tell them that we’re interested in dropshipping from them.
  5. Etsy: There so many unique and craft products made in the USA that we can use to dropship. You can send messages to the sellers to ensure their quantity enough for you to dropship from them.
  6. Banggood USA: The product in Banggood is the same as AliExpress. The difference here the Bangood USA stored their product in a US warehouse for faster shipping
  7. US Brand (Wholesale): we can approach brand owners on their official site and apply as an authorized dealer (Wholesale Program) to promote their products through the dropshipping business model. One of them is thebabygiftbox.com and babybasket.com
  8. US Dropshipping Supplier Facebook group: Another alternative you can use to find US dropshipping suppliers by joining the US dropshipping supplier Facebook group. You can post something in the group to say that you’re looking for a supplier in a specific niche. The supplier will PM back to us with detailed information.
  9. CJ Dropshipping: Even though CJ dropshipping is a middle man like Oberlo, the company can provide a freight line shipping method through YunExpress or CJ packet for your dropshipping order as long as you sync your store with them. You can ship your packet from China faster using a special line which is considered more expensive than epacket.
  10. Sourcinbox: This sourcing agent can help you fulfill your order using a special line (freight line) such as Yun Express to ship the packet to the customer. You can use this company if you have consistent daily dropshipping orders. It works effectively if you have found your winning product and want to scale up.
继续阅读