Ubuntu

安装docker

# 阿里源 Ubuntu
# http://mirrors.cloud.aliyuncs.com
sudo apt update \
&& sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common lrzsz \
&& curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - \
&& sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" \
&& sudo apt update \
&& sudo apt-get install -y docker-ce docker-ce-cli containerd.io \
&& sudo usermod -aG docker $USER

sudo echo "deb https://mirrors.aliyun.com/nvidia-cuda/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list
# 阿里源 CentOS
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 \
&& sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo \
&& sudo yum makecache fast \
&& sudo yum -y install docker-ce \
&& sudo service docker start
# 官方源
sudo apt update \
&& sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - \
&& sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
&& sudo apt update \
&& sudo apt-get install -y docker-ce docker-ce-cli containerd.io \
&& sudo usermod -aG docker $USER
# 安装docker-compose & docker-machine
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& sudo chmod +x /usr/local/bin/docker-compose \
&& base=https://github.com/docker/machine/releases/download/v0.16.0 \
&& sudo curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/usr/local/bin/docker-machine \
&& sudo chmod +x /usr/local/bin/docker-machine

阿里源安装k8s

apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add - 
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y kubelet kubeadm kubectl

阿里云修改源

sed -i 's/archive.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list \
&& sed -i 's/security.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list \
&& apt update

修改pip源

# 清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/

安装ifconfig、ping、nethogs命令

apt install inetutils-ping net-tools nethogs -y

生成指定大小的文件

dd if=/dev/urandom of=onebox.test bs=1MB count=1
truncate -s 1M onebox.test
fallocate -l 1000000 onebox.test
head -c 1MB /dev/urandom > onebox.test
head -c 1MB /dev/zero > onebox.test

代理设置

# 设置HTTP代理
echo -e "export http_proxy=http://10.255.0.189:8008\nexport https_proxy=http://10.255.0.189:8008\nexport ftp_proxy=http://10.255.0.189:8008" >> .bashrc \
&& source .bashrc \
&& curl www.baidu.com \
&& sudo sed -i '/env_reset/a\Defaults env_keep+="http_proxy https_proxy ftp_proxy no_proxy"' /etc/sudoers \
&& sudo apt-get update

# 设置docker代理
sudo mkdir -p /etc/systemd/system/docker.service.d \
&& echo -e "[Service]\nEnvironment=\"HTTP_PROXY=http://10.255.0.189:8008\" \"HTTPS_PROXY=http://10.255.0.189:8008\" \"FTP_PROXY=http://10.255.0.189:8008\" \"NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com\"" | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf \
&& sudo systemctl daemon-reload \
&& sudo systemctl restart docker \
&& sudo docker pull hello-world

# 设置apt代理
echo -e "Acquire::http::Proxy \"http://172.16.22.250:8118\";\nAcquire::https::proxy \"http://172.16.22.250:8118\";" | sudo tee /etc/apt/apt.conf.d/10proxy

远程桌面xrdp

sudo apt-get install -y xrdp vnc4server xubuntu-desktop \
&& echo "xfce4-session" > ~/.xsession \
&& sudo service xrdp restart
# 如果连接报错 
# sudo vi /etc/xrdp/startwm.sh
# 在. /etc/X11/Xsession前一行插入
# xfce4-session

dash推流

docker run --rm -v /tmp/:/files jrottenberg/ffmpeg:4.1 \
  -re -stream_loop -1 -i /files/cfpl.mp4 \
  -c:v copy \
  -c:a copy \
  -f dash -use_timeline 1 -use_template 1 -seg_duration 5 -window_size 250 \
  -utc_timing_url "https://time.akamai.com/?iso" \
  -adaptation_sets "id=0,streams=0 id=1,streams=a" \
  /files/out.mpd

zerotier安装

docker build -f Dockerfile.release -t fleax/zerotier:1.10.1 --build-arg VERSION=1.10.1 .

docker pull fleax/zerotier:1.10.1
docker run -d --restart always --name zerotier --privileged --net host fleax/zerotier:1.10.1
docker exec zerotier zerotier-cli join XXXXXXXX

视频处理

# 获取视频帧场模式
ffmpeg -filter:v idet -frames:v 100 -an -f rawvideo -y stdout -i test.ts
# 获取视频信息
# 输出:n: 234 pts:  11344 pts_time:11.344  pos:  7161640 fmt:yuv420p sar:1/1 s:1920x1080 i:P iskey:0 type:B checksum:F65D4A07 plane_checksum:[95E7E098 9AD2A82F 1953C122] mean:[146 119 129] stdev:[60.9 5.1 4.5]
ffmpeg -i <FILENAME_HERE> -vf showinfo -f rawvideo -y /dev/null

ffprobe -select_streams v -of xml -show_entries frame=pkt_pts,pkt_dts,pkt_size,pkt_duration,pict_type /root/SD.ts
# 获取视频总帧数
ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 input.mp4

网络设置

ethtool, ifconfig, route, ip, nmcli, nmtui, mtr

# ubuntu18/20
$ sudo vi /etc/netplan/01-netcfg.yaml
sudo netplan try
sudo netplan apply
# ubuntu16
$ sudo vi /etc/network/interfaces

# 静态
auto eth0
iface eth0 inet static
address 192.168.0.120
gateway 192.168.0.1
netmask 255.255.255.0
up route add -host 39.97.247.202 gw 192.168.0.1 dev eno1

# 动态
auto eth0
iface eth0 inet dhcp

# IP
ifconfig eth0 192.168.1.3
nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.0.59/24

# 路由
route add –host 192.168.1.3 dev eth0:1
ip route add 172.16.0.0/24 via 192.168.122.1 dev ens3
ip route show
route -n
netstat -rn
traceroute

# 网关
route add default gw 192.168.1.1
nmcli connection modify eth0 ipv4.gateway 192.168.0.2

# DNS
$ sudo vi /etc/resolv.conf
nameserver 208.67.222.222
nmcli connection modify eth0 ipv4.dns 114.114.114.114
nslookup # 查询
systemd-resolve --set-dns '8.8.8.8' --interface ens3

# 主机名
hostname

# restart
sudo /etc/init.d/networking restart
service networking start|stop|restart
sudo service network-manager restart
nmcli connection reload 

# 启动网卡
ifup
ifconfig eth0 up
nmcli connection up eth0 
nmcli device connect eth0

# 关闭网卡
ifdown
ifconfig eth0 down
nmcli connection down eth0 

docker日志

# 清除日志
echo "" > $(docker inspect --format='{{.LogPath}}' <容器ID>)

# 修改配置文件daemon.json
{
  "log-driver": "json-file",
  "log-opts": {"max-size": "10m", "max-file": "3"}
}
systemctl reload docker

docker硬盘trim

fstrim /proc/$(docker inspect --format='{{ .State.Pid }}' <cid>)/root  

alpine修改源

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories

apt设置代理

vi /etc/apt/apt.conf.d/10proxy

Acquire::http::Proxy "http://10.190.8.127:8118";
Acquire::https::Proxy "http://10.190.8.127:8118";
Acquire::ftp::Proxy "http://10.190.8.127:8118";

centos修改源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
wget http://centos.ustc.edu.cn/CentOS-Base.repo

privoxy

listen-address 0.0.0.0:8888
forward *.*.*.*/ .

IP扫描

linux

#!/bin/bash
echo '请输入ip C段地址,如 192.168.1'
echo 'inputip:'
read inputip
tip=$inputip
for n in `seq 254`
do
	echo -n $n ': '
	res=`ping $tip.$n -c 1 | grep ttl | awk '{print $4}' | awk '{print $1}'`
	#ping $tip.$n -c 1 | grep ttl | awk '{print $4}' | awk -F: '{print $1}'
	if [ $res > 0 ]
	#if [ $? -eq 0 ]
	then
		echo "$tip.$n on"
	else
		echo "$tip.$n off"
	fi
#	echo ''
done

windows

@echo off
chcp 65001
echo.
echo ----------------输入当前电脑所属IP地址前三段。例如:192.168.1-------------------
set /p a=:
echo.
echo --------请输入IP地址 [ 起始 ] 后段。例如:1 (输入数字介于1---255之间)
echo.
set /p b=:
echo.
echo ------请输入IP地址 [ 结束 ] 后段。例如:255 (输入数字介于1---255之间)
echo.
set /p c=:
:p
ping -n 1 %a%.%b%
set /a b+=1
if %b% lss %c% goto p
echo.
echo.
echo.
pause

代码行数统计

find . -name "*.php" -print | xargs wc -l

定时记录内存占用最多的进程

watch -n 3 "date >> test.txt && ps aux | sort -k 4 -rn | head -n 5 | tee -a test.txt"

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐