第一次部署go项目,记录一下过程。
首先update一下:
apt update
apt upgrade
安装nodejs:
apt install nodejs
安装npm:
apt install npm
安装pm2:
npm install pm2 -g
将编译好的go项目文件上传到对应目录之后:
chmod +x golang
运行go项目:
pm2 start golang
查看:
pm2 ls
第一次部署go项目,记录一下过程。
首先update一下:
apt update
apt upgrade
安装nodejs:
apt install nodejs
安装npm:
apt install npm
安装pm2:
npm install pm2 -g
将编译好的go项目文件上传到对应目录之后:
chmod +x golang
运行go项目:
pm2 start golang
查看:
pm2 ls
以debian为例。
创建交换空间文件/swapfile,大小是1G:
fallocate -l 1G /swapfile
默认交换空间文件的权限只有root用户才能写入和读取交换文件的数据。因此我们需要修改交换空间文件的权限为600,并使用mkswap格式化文件。
chmod 600 /swapfile
mkswap /swapfile
启用交换空间:
swapon /swapfile
要在Linux系统启动时自动挂载分区,需要在/etc/fstab文件中定义挂载配置选项:
echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab
运行命令swapon或free命令验证交换空间是否处于活动状态:
swapon --show
free -h
Swappiness
Swappiness是一个Linux内核属性,用于定义系统使用交换空间的频率。Swappiness可以是0到100之间的值。
swappiness=0的时候表示最大限度使用物理内存,然后才是交换空间,swappiness=100的时候表示积极的使用交换空间。
Linux的初始默认设置为60,你可以运行命令cat /proc/sys/vm/swappiness命令查看当前swappiness值的大小。
如果你需要对swappiness的值作出更改,请运行sudo sysctl -w vm.swappiness=10命令。
sysctl命令用于在运行时配置Linux内核的参数,更改仅在当前会话中可用,即重启会恢复为默认值。
为让swappiness的值持久化,则需要将值写入到/etc/sysctl.conf文件中。sysctl.conf是Linux内核的配置文件。在Linux内核启动是将会次配置文件的参数。
运行以下命令持久化Linux内核参数swappiness的值:
echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/sysctl.conf
转载过来备用,原文链接见文章结尾。
#!/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
继续阅读
以nginx为例:
location /fonts {
# this will echo back the origin header
if ($http_origin ~ "168itw.com$") {
add_header "Access-Control-Allow-Origin" $http_origin;
}
}
或者:
location / {
if ($http_origin ~* "^https?://(168itw.com|www.168itw.com)$") {
add_header Access-Control-Allow-Origin "$http_origin";
}
}
在之前的网站uptime监控中提到过Prometheus+Grafana监控搭配,抽空自己部署了一遍,功能强大,达到了运维级。
Prometheus是主控程序,是监控的Server端。
Node exporter是client端,部署在被监控vps上,负责向Prometheus传输数据。
Grafana是开源的看板/面板程序,提供可视化图形界面。
三者相结合,提供了一套完整的运维级监控系统。如果需要监控警报,还需要加入Alertmanager。
Prometheus、Node exporter、Altermanager开源地址:
Grafana开源地址:https://github.com/grafana/grafana
下面记录下部署过程。
选择用docker部署,简单方便。注意映射9090端口,及prometheus.yml配置文件目录。我这里以/opt/config目录为例:
-v /opt/config:/etc/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
以下为最简单的默认配置文件
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。
以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,初次登录会要求修改默认的登录密码。
点击主界面的“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。搞定
在需要被监控的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
编辑Prometheus的prometheus.yml文件,添加以下代码,注意对齐:
- job_name: 'Linux'
static_configs:
- targets: ['xx.xx.xx.xx:9100']
labels:
instance: 168itw.com
重启docker Prometheus。
继续阅读首先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
1、生成密钥
ssh-keygen
或者:
ssh-keygen -t rsa
一路回车即可。在 root 用户目录中生成了一个 .ssh 目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。
2、在服务器上安装公钥
[[email protected] ~]$ cd .ssh
[[email protected] .ssh]$ cat id_rsa.pub >> authorized_keys
如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确:
[[email protected] .ssh]$ chmod 600 authorized_keys
[[email protected] .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 服务:
[[email protected] .ssh]$ service sshd restart
继续阅读
phpmyadmin经常爆出漏洞,而且装在服务器上会占用资源。
收集了一些常用到数据库管理软件,可以直接安装在本地Windows或者Mac。
收费,支持的数据库最全,不过可以教育邮箱学生版激活,网上也有注册机/注册码/破解版,GitHub上也有无限重置试用 navicat premium所有版本的脚本。
https://github.com/malaohu/reset-navicat-premium
https://github.com/yhan219/navicat_reset_mac
免费,支持的数据库也很全,我目前就是用的这个。
免费开源,用的人也很多。
收费,网上也能找到序列号。
前提条件:
登入Clooudflare查看:https://dash.cloudflare.com/profile/api-tokens
在Cloudflare DNS面板中新建A 记录,例如myddns 指向1.1.1.1 并关闭CF代理开关让云朵灰色。
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
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=你的二级域名
保存并退出编辑界面
chmod +x cf-v4-ddns.sh
./cf-v4-ddns.sh
##如果上面的步骤无误,您会看到Cloudflare DNS面板中。
##刚才您新建的A 记录IP已更新为VPS的公网IP
crontab -e
##有些系统会提示让您选择vi或nano编辑定时脚本,选择您熟悉的编辑工具即可
##插入下面一下,表示每分钟更新ddns
*/1 * * * * /root/cf-v4-ddns.sh >/dev/null 2>&1
保存退出。
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记录。
这种很简单,直接注册,然后根据官方提供的脚本更新DNS记录即可。
上面三种方法,都会有一个问题,DDNS生效时间和DNS缓存时间,会导致NAT更换IP后中断几分钟不等。比如cloudflare免费用户DNS TTL是1分钟,he.net是5分钟,dynu是30s。
所以就有了第四种方法,也是最优解决方案。
借助cloudflare tunnel实现内网穿透,不受ddns影响,而且完全免费。
cloudflare runnel功能很强大,具体参考官方教程:https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/
OpenWrt是开源的基于Linux的路由器系统。本文收集整理了市面上(主要是恩山论坛)较为流行、使用人数较多、且评价不错的固件。
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 密码无
使用人数多,更新快,每月一号更新,管理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
链接:https://pan.baidu.com/s/1kbvtyxpcmniLKN_ziH-kqQ 提取码:jla9
恩山:https://www.right.com.cn/forum/thread-4076037-1-1.html
好评差评都有,请自行判断。
恩山地址:https://www.right.com.cn/forum/thread-8223107-1-1.html
Github:https://github.com/kiddin9/OpenWrt_x86-r2s-r4s-r5s-N1
Github:https://github.com/SuLingGG/OpenWrt-Rpi
Github:https://github.com/DHDAXCW/OpenWRT_x86_x64
Github:https://github.com/coolsnowwolf/lede
附软路由刷openwrt简单三步走教程:
N1旁路由网络设置:
在“基本设置”上,协议选择“静态地址”,“IPV4网关”和“使用自定义的DNS服务器”填写你的主路由的IP地址,“IPV4地址”是设置你的N1的IP地址。“IPV4地址”的前面三个字段要和你的主路由IP一样