Oct 11, 2018
辅助
#
快捷键
#
ctrl alt f1/f2/... # 终端切换
帮助
#
man
-f # 简要介绍
-k # 通配搜索
whatis # man -f
apropos # man -k
命令行
#
clear
pwd # 当前路径
bash
-c # 执行命令字符串
set -o # 设置快捷键模式,默认emacs
快捷键
<Tab> bash补全
<C-c> 中断
<C-d> eof
<C-tab> ls
<C-l> clean
<C-a> 移到行首
<C-e> 移到行尾
<C-u> 删除到行首
<C-k> 删除到行尾
<C-p> 上一个命令
<C-n> 下一个命令
<C-r> 查看历史 # <C-s> 向前查看历史
<C-s> 冻结
<C-q> 解冻
<C-t> 交换字符
<C-w> 删word
<C-z> 暂停到后台
<C-\> 中断
<C-/> 撤消
<C-_> 删除一行
<M-r> 取消历史变更
场景
禁用<C-s><C-q>, 以使<C-s>变为向前查看历史
stty -ixon -ixoff
stty STOP ^w # 把原<C-s>改成<C-w>
zsh
fish
tmux
session
window
pane
~/.tmux.conf
快捷键prefix <C-b>
系统
prefix
? # 帮助
: # 命令模式
[ # 复制模式
tmux
kill-server
source a
session
prefix
d # 脱离
D # 选择脱离
r # 重绘
s # 选择
~ # 信息历史
tmux
ls
attach a
# 返回session
-t name
rename-session a
switch -t a
window
prefix
c # 新建
& # 关闭
, # 命名
. # 编号
w # 选择
[0-9] # 切换
n # 向后切换
p # 向前切换
l # 置换
f # 所有window查找
pane
prefix
" # 横分
% # 竖分
x # 关闭
! # 移到新window
方向 # 切换
o # 切换到下一个
<C-o> # 向下旋转
<M-o> # 向上旋转
{ # 向前置换
} # 向后转换
<C-方向> # 调整size
<M-方向> # 5倍调整size
空格 # 切换布局
<M-[0-5]> # 选择布局
q # 显示编号
内置命令
source-file a
screen
-ls # 查看所有session
-r # 进入id
echo
watch -n 1 -d netstat -ant # 监视
forturn # 随机名言
toilet # 彩虹字
cowsay # 牛说
source # 当前shell执行
figlet # 大写字
sl # 火车
cal 9 1752 # 打印日历
date +%Y/%m/%d/%H:%M
bc
maxima # 符号计算
factor # 分解质因数
expect # 为运行的脚本预填表单
o-> 结束
#!/usr/bin/expect
spawn ssh outrun@192.168.1.103
expect "*password"
send "asdf\n"
expect eof
o-> 交互
#!/usr/bin/expect -f
spawn sudo /usr/local/mysql/bin/mysqld_safe --user=mysql
expect "*password:*"
send -- "asdf"
send -- "\n"
interact # interact留下交互, exit退出
o-> 后台执行 # 不要expect eof
if [fork]!=0 exit
disconnect
script/scriptreply # 终端录制
script -t 2>timing.log -a output.log
scriptreply timing.log output.log
jobs # 后台作业
fg # 后台作业调度到前台
bg # 继续执行后台作业
nohup
nohup *** > /dev/null 2>&1 &
文字处理
#
uniq # 删除重复列
cat file1 file2 # 上下拼接
paste file1 file2 # 左右拼接
-d '-' # 加分隔符
tac # 倒转行显示
wc # 统计行, 单词, 字符
grep
-v grep # 过滤掉grep
常用
grep -nr --exclude-dir={.git, res, bin} 'a' .
# 递归查找
xargs
-d "\t" # 定义分隔符
-t # -t打印执行的命令
-L 1 # 1行执行一次
-n 1 # 一次使用1项
-I arg1 sh -c 'echo arg1; mkdir arg1'
# 执行多命令
--max-procs 0 # 并行执行,不限数量
常用
代码行数
find -name "*.go" -or -name "*.py" |xargs grep -v "^$" |wc -l
复制最近修改的文件
ls -rt | tail -4 | xargs -i cp -r {} ~/sdb/work/ryxWork/架构/
awk
awk '{print $1}'
awk '{cmd="kubectl delete pvc "$1;system(cmd)}'
# 按行执行命令
sed
sed -i '1i\new line'
# 第一行前插入
常用
替换文本
sed -i "s/a/b/g" `grep -rl "a" ./`
sort
-r # reverse
-n # 显示行号
more
less
iconv
-l # 列出已知的编码
-f gbk -t utf-8 -c orig.txt -o tgt.txt # 转码
head -2
tail -2
-f
paste file1 file2 # 合并两个文件或两栏内容
-d '+' # 分隔符
nano
strings # 打印可打印字符
jq . a.json # 验证json格式
pv -qL 10 # 文件缓慢显示
aview # 图片文件化
媒体处理
#
convert # 转换图片
convert a.jpg a.png # 转格式
-resize 1024x768
convert -resize a.jpg a1.jpg
-sample 50%x50% # 缩略图
-rotate 270 # 顺时针旋转270度
-flip # 左右翻转
-paint 4 # 旋转角度
-draw # 加文字
convert -fill black -pointsize 60 -font helvetica -draw 'text 10,80 "A" ‘ a.jpg a1.jpg
# 用黑色, 60磅, helvetica字体, 在位置10,80 写A
-raise 5x5 # 右下增加
+raise 5x5 # 左上增加
-bordercolor red -border 5x5 # 红色边框
-mattecolor black -frame 5x5 # 黑色边框
-noise 3 # 油画
-monochrome # 噪声
-blur 80 # 高斯模糊
-flop # 底片
-negate # 黑白
-charcoal 2 # 炭笔
-spread 30 # 漩涡
-swirl 67 # 凸起
ffmpeg
系统
#
启动与任务
#
grub
/etc/default/grub # 设置文件
grub2-mkconfig -o /boot/grub2/grub.cfg # 使设置生效,update-grub 是debian下做的包装
upstart # 状态 waiting, starting, pre-start, spawned, post-start,running,pre-stop, stopping, killed, post-stop
systemv
systemd
systemctl
status
daemon-reload # 修改service文件后重载
systemctl list-units # list known units
systemctl list-unit-files # 已知的services
systemctl list-sockets # list socket units ordered by the listening address
systemctl enable NAME # 设置开机启动, 生成service脚本命令
systemctl disable NAME
systemctl start NAME
systemctl stop NAME
systemctl restart NAME
systemctl reload NAME
service
service start
service restart
service stop
service status
service --status-all
chkconfig iptables on/off # 设置服务启动
--level 2345 iptables off # 查看各level服务状态
--list iptables
at # 某时间运行一次
osmo # 计划任务软件
reap # 用于定时删除目录中文件,并打印日志
-h # 打印帮助信息
-t # 后台运行, 并设置时间间隔
-s # single 单次运行
cron
介绍
crond服务在systemd中被timer取代
使用
$ service crond start
$ service crond stop
$ service crond restart
$ service crond reload # 重载配置
$ crontab crontest.cron # 添加定时任务。打印的文件在用户根目录下
$ crontab -l # 列出用户目前的crontab
$ crontab -u # 设定某个用户的cron服务
$ crontab -r # 删除某个用户的cron服务
$ crontab -e # 编辑某个用户的cron服务
# crontab -u root -l 查看root的设置
/etc/crontab # 系统配置文件
/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly
/etc/cron.monthly # 每小时、天、周、月执行的脚本
定时格式
M H D m d cmd
M: 分钟(0-59)每分钟用*或者 */1表示
H: 小时(0-23)
D: 天(1-31)
m: 月(1-12)
d: 一星期内的天(0~6,0为星期天)
cmd: 如 ~/a.sh
例子
crontest.cron文件中
15,30,45,59 * * * * echo "aa.........." >> aa.txt
# 每15分钟执行一次打印
0 */2 * * * date # 每两个小时
日志
#
dmesg # 启动日志
rsyslog # 日志管理, syslog的实现, 在systemd中被systemd-journal取代
mcelog # machine check exception log
journalctl # 日志查看
-x # 显示解释
-e # 显示到底部
-u # 指定unit名, 如kubelet
--no-pager # 不输出到管道来分页
-f # 追加显示
-q # 只显示warn以上信息
--user-unit # 指定用户
--since "2018-03-26"
--until "2018-03-26 03:00"
场景
journalctl -f --user-unit onedrive
journalctl -xefu kubelet --no-pager
电源
#
poweroff # 立即关机
shutdown -h now
-h # 关机
-r # 重启
pm-suspend # 挂起电脑
halt
用户
#
w # 在线用户名, 终端号, 登录时间, 空闲时间, 终端连接所有进程时间, 当前进程时间, 当前命令
id outrun # 用户信息
su
常用
切换登录
sudo -i su outrun
sudo
id # 用户信息, 所在组
passwd # 修改密码
useradd outrun # 创建用户
-g outrun # 指定组
-r # 是系统用户
-d /home/outrun # 指定登录目录
-u 544 # 指定id
userdel -r user1 # 完全删除用户
groups user1 # 查看组
groupadd ftp # 创建组
usermod # 修改用户状态
-a -G root outrun # 加入组
-l newuser user1 # 改名
-L user1 # 锁定
-U user1 # 解锁
-d /home/ftp ftp # 改登录目录
-u 123 outrun # 修改id
内核
#
uname -a # 查看版本
modprobe vboxdrv # 内核
lsmod # 显示当前系统加载的模块,如systemctl中start了的模块
dkms
status
配置
#
env # 查看所有环境变量
envsubst # 编译文件中环境变量
envsubst '${THREAD_NUM}' < decoder.conf.template > decoder.conf
getent # 查看系统数据库中数据
group docker # 查看docker用户组
ulimit -s unlimited # 限制shell启动资源, 不限制堆栈大小
-a 显示各种限制
-u 10000 最大用户数
-n 102400 文件句柄数
-d unlimited 数据段长度
-m unlimited 内存大小
-t unlimited cpu时间
-v unlimited 虚拟内存
系统设备
#
接口查看
#
lspci
lsusb
显示器
#
xrandr
# 多显示器布局
-q # 列出所有屏幕
--verbose # 列出所有屏幕详情
--output eDP1 # 指定屏幕
--off # 禁用屏幕
--primary # 指定主显示器
--mode # 分辨率
--pos # 指定屏幕在背景板的位置, 根据各屏幕分辨率、位置算
--rotate # 旋转屏幕
normal
left
right
inverted
声卡
#
amixer set Master 100% # 调节音量
alsamixer # 调节声音
alsactl # 设置alsamixer
store # 保存
restore # 加载
aplay -l
/etc/asound.conf
defaults.pcm.card 1
defaults.pcm.device 1
defaults.ctl.card 1
pactl
场景
默认声卡
pactl list short sources
pactl list short sinks
pactl set-default-source alsa_input.pci-0000_00_1b.0.analog-stereo
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
系统监控
#
综合监控
#
uptime # 当前时间, 运行时间, 用户数, 系统负载
tload # 系统负载图(用字符画)
top
top -d 1 -p pid [,pid ...]
htop
按键
h # 帮助
atop
btop
nmon
glances
netdata
vmstat # 获得有关进程、swap、内存、cpu等系统信息
dstat # 定时收集系统信息
sar # 全面的系统活动情况
-u 3 5 # 查CPU负载, 3秒一次共5次
-d # 磁盘
-r # 内存
-W # SWAP
-n DEV # 网络接口
-n SOCK # socket连接信息
-n TCP # TCP连接
-b # I/O速率
-q # 平均负载
lxtask # GUI监控CPU、内存
sysdig
sysdig
-c
topprocs_cpu # 进程cpu top
evt.cpu=0 # 只统计cpu0
topprocs_net # 进程带宽 top
topprocs_file # 进程硬盘i/o top
topfiles_bytes # 文件读写 top
proc.name=httpd # 指定进程名
topfiles_time # 文件时间 top
topprocs_errors # 进程error top
topfiles_errors # 文件error top
topscalls_time # 系统调用时间 top
topscalls "evt.failed=true" # 系统调用出错 top
topconns # 网络连接 top
fdcount_by
proc.name "fd.type=file" # 进程文件描述符
fdbytes_by
fd.directory "fd.type=file" # 目录读写 top
fd.filename "fd.directory=/tmp/" # /tmp目录文件 读写top
fd.type # fd type i/o
echo_fds "fd.filename=passwd" # 所有名为passwd文件的i/o
stdout
proc.name=bash # 进程标准输出
fileslower 1 # 文件i/o 大于1ms
spy_users # 命令执行情况
-A # 只显示可读数据
-s 4096 # 指定 data buffer 字节
-r trace.scap # 指定trace file
-pc # 详情
csysdig # 交互式工具
-vcontainers # 容器资源
-pc # 详情
内存
#
slabtop # 内核片缓存信息
CPU
#
powertop # intel开发,找到高功率进程
mpstat # cpu统计信息
进程
#
pidstat -p 434 # 进程使用资源的情况
-u 1 # CPU
-r 1 # 内存
-d 1 # 磁盘
-w # 上下文切换
ps
aux # 用在unix style中, BSD格式显示
ef # 用在system v style中, 标准格式显示
pstree # 进程关系
pwdx [pid] # 查看进程工作目录
ll /proc/[pid]/cwd
pmap [pid] # 进程
kill 1024
-9
# 3 QUIT 退出(同ctrl + \)
# 1 HUP 终端断线
# 2 INT 中断(同ctrl + c)
# 9 KILL 强制终止
# 15 TERM 终止
# 18 CONT 继续(与STOP相反, 同fg/bg)
# 19 STOP 暂停(同ctrl + z)
-l # 列出所有信号名称和编号
常用
删除名字的进程
ps -ef|grep -v "grep"|grep aurora/app.js |awk '{print $2}'| xargs kill -9
pkill Xorg # kill 所有包含
killall Xorg # kill 所有包含
xkill # 运行后 在xwindow点击kill窗口
网络
#
配置
#
hostname
nmtui # 设置网卡
nmcli # 设置网络连接
sudo nmcli c mod 'Wired connection 1' ipv4.never-default false
# 解决manual ip不能设置路由的问题
wpa_supplicant
iwlist # 列出无线网
iwconfig # 无线网卡设置
wifi-menu
pppoe # 宽带
ifconfig
打开, 关闭网卡
ifconfig eth0 up
ifconfig eth0 down
临时修改ip
ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up
# up表示立即激活
临时mac
ifconfig enp0s20u6u3 hw ether 00:50:56:c0:00:02
虚拟网卡
ifconfig wlp7s0:1 ip netmask
# 共用一个ip
netctl # 配置网卡服务
route
-n # 查看路由表
//添加到主机的路由
route add –host 192.168.168.110 dev eth0
route add –host 192.168.168.119 gw 192.168.168.1
//添加到网络的路由
route add –net IP netmask MASK eth0
route add –net IP netmask MASK gw IP
route add –net IP/24 eth1
//添加默认网关
route add default gw IP
//删除路由
route del –host 192.168.168.110 dev eth0
arp -n # 显示局域网 ip mac表
-s ip mac # 设置ip mac表
ip # 网卡与ip信息
添加路由
ip route add 10.146.81.0/24 via 10.146.81.29
配置ip段互斥的宿主机转发
服务器
ip link set up dev tun0
sysctl net.ipv4.ip_forward=1
/etc/sysctl.d/30-ipforward.conf
net.ipv4.ip_forward=1
net.ipv6.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1
客户端
ip addr add 192.168.123.201/24 dev eth0 # 要转发的网段
ip link set up dev eth0
ip route add default via 192.168.123.100 dev eth0 # 服务器ip
hostapd # 无线热点
yum install hostapd
vi /etc/hostapd/hostapd.conf
wpa_passphrase=asdfasdf
ssid=myflowers
interface=p3p1
yum install dhcp
vi /etc/dhcp/dhcpd.conf
option domain-name-servers 192.168.0.1,8.8.8.8; # 自己的dns提供商
option routers 192.168.0.42; # 本机ip
option domain-name "mydhcp";
option domain-name-servers 192.168.0.1;
log-facility local7;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.160 192.168.0.170;
option broadcast-address 192.168.0.255;
}
测试工具
#
ab # 压测
ab -c 10 -n 100 https://www.baidu.com/
# 10并发100次, url结尾要有/
mtr # myTrace, 合并ping与traceroute,默认发送ICMP包, 做持续探测, 避免节点波动的影响
traceroute # 做一次探测, 默认UDP包, 发包TTL值逐渐增大
-I # 使用ICMP包
ping
telnet
nslookup # 查域名ip
dig # 域名解析
nmblookup -A ip # 查ip域名
nmap
-sP ip/24 # 查看网内所有ip
-p1-65535 # 扫描所有端口
常用
nmap 192.168.100.1/24 -p1-65535
nc # netcat, 功能全面
-U a.sock # 指定socket
-v # 显示详情
-z # 只测试连通
-u # 使用udp
o-> 测试udp端口
nc -vzu 127.0.0.1 1194
o-> 文件传输
nc -l -p 9999 | tar xf -
tar cf - $(find . -name "*") | nc -v 10.99.11.44 9999
rinetd # TCP端口转发
rinetd.conf
0.0.0.0 80 192.168.1.2 80
rinetd -c /etc/rinetd.conf
simplehttp
python -m SimpleHTTPServer 8080
请求工具
#
curl
curl -v # 详细头信息
curl -H "Cookie: foo=bar; baz=val" # 发送cookie
curl -X post -k http://localhost:9090/a -H "Content-Type: text/plain" -d '{"name": "a"}'
# post请求
curl -O http://104.223.142.166/isu80 # 抓文件
wget
-i filelist.txt # 下载一个文件中的所有url
-x # 强制创建目录
-P # 目录prefix
-r # 递归下载
-l # 最大递归深度, inf或0代表无限制
-k # 修改链接,指向本地文件
-p # 下载所有用于显示页面的资源, 如图片
-L # 只跟踪relative链接
-N # 只获取比本地新的文件
-np # 不追踪父目录
-m # 缩写-N -r -l inf --no-remove-listing
--no-remove-listing # 不删除listing文件
常用
爬网站
wget -x -P curSite -r -l 100 -k -L -np http://nodeapi.ucdok.com/api/
带cookie
wget --post-data="username=u1&password=asdf" --save-cookies=cookie --keep-session-cookies "http://www.abc.com/logging.php"
wget -x -P curSite -r -l 1 -k -L -np --load-cookies=cookie --keep-session-cookies "https://www.abc.com/display/1"
ssh
ssh 10.1.10.2 -L 9901:localhost:5901
# 用ssh建tunnel访问内部端口
ssh -t -L 5900:localhost:5900 remote_host 'x11vnc -localhost -display :0'
# 本机执行命令并端口映射
sshpass
sshpass -p asdf ssh root@47.74.230.238
sshfs -o allow_other root@ip:~ /mnt # 挂载远程目录
scp a.txt root@ip:~
w3m # 命令行浏览器
vnc # 远程桌面
Virtual Network Computing
相关文章
linux 自带远程桌面--VNC服务配置说明
安装
yum install vnc*
yum install *vnc-server*
启动
vncserver :1
登录
vncviewer # fedora 下gnome自带的vncviewer名为:Remote Desktop Viewer
输入192.168.0.62:1 # 实际端口号为5901, 如果服务号为2则为5902
或者浏览器java-plugin
localhost:5801 # 需要安装java
监控
#
iftop -n # 流量监控
ntop # 流量监控, web界面
# localhost:3000
-W 3001
# Loss%丢包率, Snt每秒包数, Last最近一次延迟, Avg平均值, Best最小值, Worst最大值, StDev标准差
-u # 使用udp包
--no-dns # 不对ip做域名反解析
-4 # 只用ipv4
-6 # 只用ipv6
结果
1,2,3,4 本地网络
5,6 运营商骨干网络
7,8,9,10 目标服务器本地网络
8 链路负载均衡
tcpdump
-v # verbose输出
-vvv # 最详细输出
-n # 网络地址显示数字
-nn # ip和端口显示
-i # 指定网卡
-c 100 # 100条后退出
-w file1 # 保存到文件
-r file1 tcp # 从文件读取,指定tcp协议
-G 5 -w /opt/capfile-%Y_%m%d_%H%M_%S # 滚动日志
greater 200 # 报文字节大于200
host 192.168.0.1 # 包含ip
port 80 # 包含端口
port !80
dst host 192.168.0.1 # 目标ip
dst port 80 # 目标端口
src host
src port
net 192.168.0.1/32 # 包含网段
udp/tcp/icmp/igmp/arp # 指定协议
ip # ip协议
ip proto ospf # 类型为ospf的ip包
ip[9]=6 # ip包头第10字节为6(tcp协议)
ether multicast # 二层类型为多播
ether src host 00:0c:29:9a:1f:4e # 二层mac
常用
tcpdump -i eth0 -vnn \(src host 8.8.8.8 and port 80 \) or \(src host 10.10.10.10 and dst port 443\)
tcpdump -n tcp port 8383 -i lo and src host 183.14.132.117
iotop # 实时监视io
p # 显示pid
o # 只显示活跃
iostat # 负载情况
lsof -i:8080 # 列出当前系统打开的文件,必须root运行才准确
-i # 端口
-P # 显示端口号而非名称
-n # 显示ip而非域名
-i -n -P # 查看进程句柄数
nicstat # 网络流量统计
netstat
-a # 显示所有
-n # 显示数字,而不是别名
-t # 仅显示tcp
-u # 仅显示udp
-p # 显示建立链接的程序名
-l # 仅列出listen的服务
-o # 显示timer, 如keepalive
-antpu # 端口
tapestat # 磁带驱动器信息
ss # 端口,性能高
-l # listening
防火墙
#
getenforce # 查看selinux状态
sestatus -v # 查看selinux状态
setenforce 0 # 临时关闭selinux
1 # 启用
ufw # ubuntu, 简化防火墙
iptables [-t 表] -命令 匹配 操作
参数
-t # 要操作的匹配表
命令
-P # 策略, INPUT等
-A # append, 添加
-I 1 # 在第2条前添加
-D 1 # delete, 删除
-R 1 # 替换
-L # list 显示
-n # 端口以数字显示
-v # verbose, 显示更多信息
-F # flush
-X # 清除自定chain
-Z # 清除统计数
规则
-p # 协议
-i # 指定网卡流入
-o # 指定网卡流出
-s # 来源ip, !表示排除
-d # 目标ip
--sport # 源端口
--dport # 目标端口
-m # 使用模块, 会根据-p选择模块
动作
-j # 跳转
ACCEPT
四表(table)
raw # 跟踪
mangle # 标记
nat # 修改ip、port
filter # 过滤, 默认
五链(chain)
PREROUTING
FORWORD # INPUT前转发到POSTROUTING
INPUT
OUTPUT
POSTROUTING
策略(policy)
ACCEPT # 通过
REJECT # 拒绝,返回数据
返回数据包
ICMP port-unreachable
ICMP echo-reply
tcp-reset
iptables -A INPUT -p TCP --dport 22 -j REJECT --reject-with ICMP echo-reply
DROP # 丢弃
REDIRECT # 导向端口(PNAT)
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT--to-ports 8081
MASQUERADE # 改写来源ip为本机ip, 可指定目标端口范围
iptables -t nat -A POSTROUTING -p TCP -j MASQUERADE --to-ports 21000-31000
LOG # 日志, 记在/var/log
iptables -A INPUT -p tcp -j LOG --log-prefix "input packet"
ULOG
SNAT # 改写源地址, 只适用POSTROUTING
iptables -t nat -A POSTROUTING -p tcp-o eth0 -j SNAT --to-source 192.168.10.15-192.168.10.160:2100-3200
DNAT # 改写目标地址, 只适用POSTROUTING
iptables -t nat -A PREROUTING -p tcp -d 15.45.23.67 --dport 80 -j DNAT --to-destination 192.168.10.1-192.168.10.10:80-100
TOS
MIRROR # 对调源ip与目标ip后返回
QUEUE # 封包入队列待处理,实现功能如:计算联机费用
RETURN # 退出当前规则链, 返回主规则链
TTL
MARK # 对包做标记数字
iptables -t mangle -A PREROUTING -p tcp --dport 22 -j MARK --set-mark 22
规则(rule) # 自定义的条件
配置文件
/etc/sysconfig/iptables
/usr/libexec/iptables/iptables.init
save
rules.v4 # 自定义配置
*filter
:INPUT ACCEPT [186:19951]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [71:11164]
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 23 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 24 -j ACCEPT
COMMIT
命令
systemctl enable iptables.service
service iptables save
service iptables restart
iptables-restore < rules.v4
# 导入配置
案例
关iptables
service iptables stop
chkconfig iptables off
查看
iptables -L -n -v --line-numbers
查nat表
iptables -t nat -L
flush, 生效
iptables -F
service命令
service iptables save
service iptables stop
service iptables start
service iptables restart
开机启动
/etc/network/if-pre-up.d/iptables
iptables-restore < rules.v4
插入规则
iptables -I INPUT 2 -s 202.54.1.2 -j DROP
删除规则
iptables -D INPUT 4
开放所有input/output
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
开放input/output tcp 22
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
vpn转发
iptables -t nat -A POSTROUTING -s 192.168.252.0/24 -j SNAT --to-source 10.171.83.146
屏蔽私有地址
iptables -A INPUT -i eth1 -s 192.168.0.0/24 -j DROP
iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP
屏蔽ip
iptables -A INPUT -s 1.2.3.4 -j DROP
iptables -A INPUT -s 192.168.0.0/24 -j DROP
iptables -A OUTPUT -d 192.168.1.0/24 -j DROP
iptables -A OUTPUT -o eth1 -d 192.168.1.0/24 -j DROP
屏蔽端口
iptables -A INPUT -p tcp -s 1.2.3.4 --dport 80 -j DROP
iptables -A INPUT -i eth1 -p tcp -s 192.168.1.0/24 --dport 80 -j DROP
记录并屏蔽
iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j LOG --log-prefix "IP_SPOOF A: "
iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP
mac屏蔽
iptables -A INPUT -m mac --mac-source 00:0F:EA:91:04:08 -j DROP
# *only accept traffic for TCP port # 8080 from mac 00:0F:EA:91:04:07 * ##
iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source 00:0F:EA:91:04:07 -j ACCEPT
屏蔽icmp
iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
iptables -A INPUT -i eth1 -p icmp --icmp-type echo-request -j DROP
开启范围端口
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 7000:7010 -j ACCEPT
开启范围ip
iptables -A INPUT -p tcp --destination-port 80 -m iprange --src-range 192.168.1.100-192.168.1.200 -j ACCEPT
nat
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to 123.4.5.100
# 改写来自192.168.1.0/24的包, 源ip为123.4.5.100
iptables -t nat -A PREROUTING -s 192.168.1.0/24 -i eth1 -j DNAT --to 123.4.5.100
# 改写来自192.168.1.0/24的包, 目标ip为123.4.5.100
iptables -t nat -A POSTROUTING -s 172.27.0.0/16 -d 10.0.0.1 -p tcp --dport 80 -j SNAT --to-source MASQUERADE
# 改写来自172.27.0.0/16去向10.0.0.1:80的tcp包, 源ip为本机ip
iptables -t nat -A PREROUTING -d 192.168.1.1 -p tcp --dport 80 -j DNAT --to-destination 10.0.0.1
# 改写去向192.168.1.1:80的tcp包, 目标ip为10.0.0.1
firewall
systemctl start firewalld
o-> ftp
firewall-cmd --zone=public --add-port=20/tcp --permanent
firewall-cmd --zone=public --add-port=21/tcp --permanent
firewall-cmd --permanent --add-port=1000-2000/tcp
firewall-cmd --complete-reload
o-> 8080
firewall-cmd --query-port=8080/tcp
--add-port=8080/tcp --permanent --zone=public
--reload
--get_active-zones
--list-all
--set-default-zone=public
o->
firewall-cmd --permanent --remove-port=8080/tcp
存储
#
硬盘
#
fdisk -l
cfdisk
sfdisk
parted
mkfs
mkswap
testdisk /dev/sdb1
e2fsck -a /dev/sdb1 # 修复ext2
ntfsfix -d -b /dev/sdb1 # 修复ntfs坏扇区和脏标记
fsck /dev/sda1 # 检查并修复
udisks --detach 设备编号 # 移除磁盘
mount /dev/sdb1 /mnt
-o acl # 打开acl功能
-o loop x.iso # 挂载文件
-o iocharset=utf8 # 指定编码
-t vfat # 指定类型
umount
-n # 执行umount却不写入
-l # lazy
-f # force
df -h # 已挂载分区列表
-T # 查看分区类型
blktrace # 磁盘访问情况
lsblk # 查看挂载的分区
lvs
LVM逻辑卷的创建流程如下:
将一个磁盘或分区格式化为物理卷:pvcreate /dev/sdb1
将物理卷添加到一个卷组中:vgcreate linuxcast-vg /dev/sdb1 /dev/sdb2
基于卷组创建一个逻辑卷mylv:lvcreate -L 10G -n mylv linuxcast-vg
格式化逻辑卷:mkfs.ext4 /dev/linuxcast-vg/mylv
挂载使用:mount /dev/linuxcast-vg/mylv /mnt
逻辑卷查看命令:
pvdisplay
pvs
vgdisplay
vgs
lvdisplay
lvs
删除一个逻辑卷:
lvremove /dev/linuxcast-vg/mylv
删除一个卷组:
vgremove linuxcast-vg
删除一个物理卷:
pvremove /dev/sda1
nfsiostat # nfs驱动器信息
cifsiostat # CIFS信息
growpart # 磁盘热扩容
文件操作
#
fuser # 查看文件被谁使用
-u # 列出使用者用户名
-uk # 终止文件的所有进程
-n tcp 8080 # 列出端口的进程号
ldd /bin/ls # 查看可执行文件动态引用模块
rename 's/\.bak$//' *.bak # 重命名
rm -rf
touch
-t 0712250000 file # 修改文件时间戳(YYMMDDhhmm)
ls *[0-9]*
-t # 时间排序
-R # 递归显示文件
-l # 详情
-S # 按大小排列
-r # reverse
-h # 自动大小单位
-F # 加后缀标识类型
-Z # 显示文selinux状态
tree
mkdir
rmdir
cd
~
-
cp
-r # 递归
-p # 带权限复制
-d # 保留链接
-a # -dpr
mv
whereis
which
find .
maxdepth 1
-name "*.go"
-type f
-atime +100 # 100天未使用过的执行文件
-mtime -10 # 10天内创建或修改的文件
-exec chmod +x # 对找到的文件执行命令
-xdev # 忽略块设备
file # 探测文件类型
file 可执行文件 # 可查看是否静态编译
ln
du -d 1 -h
-s # 只返回汇总情况
-k # 统一单位
tar xf
cfzv x.tar.gz x # 压缩
xfzv x.tar.gz # 解压
--exclude=/proc
gzip x # 压缩
-d x # 解压
unzip
常用
unzip中转码
unzip -P “$(echo 中文 | iconv -f utf-8 -t gbk)”
unzip-beta # 解压并转码中文
diff # 改变以匹配第二个文件
diff -y a b
diff dir1 dir2
diff -uN a b > b.patch
patch -p0 < b.patch
patch -RE -p0 < b.patch
diff -uNra a b > b.patch
cd a
patch -p1 < ../b.patch
patch -RE -p1 < ../b.patch
rsync -av --exclude=.git --exclude=logs/* ./* 192.168.0.14:/data/app/ext-marketing/
vimdiff a b
mucommander # 跨平台文件管理软件
shred # 文件粉碎
rclone # 云存储同步
config # 配置向导
ls [name]: # 显示文件
lsd [name]: # 显示文件夹
copy a [name]:a # 上传
cleanup # 只保留最新版本
sync # 本地向远程同步
mount # 双向一致同步
fusermount -u /path/to/local/mount
# umount
rclone-browser # rclone GUI
onedrive
onedrive --resync
常用命令
systemctl --user enable onedrive
systemctl --user start onedrive
journalctl --user-unit onedrive -f
权限
#
chmod ugo+rwx # u拥有者, g群组, o其他人, +添加, -删除, r读、w写、x执行
chmod a+rwx # a指所有人
chattr +i file # 改变属性
lsattr file
chown -R outrun:outrun .
chgrp -R outrun .
getfacl # 查看一个文件的ACL设置
setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ...
-b # 去掉所有acl设置
-m u:sudo:rwx filename # 配置用户权限
-m g:sudo:r-x filename # 配置组的权限
-x u:user1 filename # 删除一个ACL设置
-d -m g:sudo:rwx # 指定default
chcon # 修改文件安全上下文
-R # 递归
-t # type
-u # user
-r # role
--reference # 参照更新
chcon -R -t mysqld_db_t /data
chcon -R --reference=/var/lib/mysql /data
功能软件
#
包管理
#
snap
list # 列已安装
info # 查看仓库所有版本
find # 搜索
install
remove
refresh # 更新
refresh all
revert # 还原到上个版本
--revision # 指定版本
run # 运行命令
start # 运行service
--enable # 开机启动
stop # 停止service
save # 存配置快照
saved # 列出所有快照
rpm # 源 rpm fusion
-i 安装
-e 卸载
-qa 查看安装的包名
-ql 包名, 查看安装的文件
-qc 包名, 查看软件的配置文件
pacman
命令 pacman<操作> [选项] [目标]
操作
-Q # 查询
-S # 安装
-R # 删除
-D # 数据库
-F # 文件
选项
选项-S, -R, -U
-s
选项-S, -U
选项-Q
-s # 搜索
-e # 明确指定的
-n # 本地的
-q # 静默
-i # 详情, 两个i显示备份文件和修改状态, 显示依赖
-l # 列出文件
-o # 显示拥有此文件的包名
选项-R
-s # 递归
-c # 级联依赖此包的包
-n # 不记录备份信息
选项-S
-s # 搜索
-y # 刷新, 两个y强制升级所有包数据库
-q # 静默
-u # 系统升级
-c # 清理, 一个c清理未安装包, 两个c清理所有cache
选项-D
选项-F
目标
常用
-Qeq | pacman -S - # 重新安装所有包
-S $(pacman -Qnq) # 重新安装所有包
-Ss ^ibus-* # 通配search
-S $(pacman -Ssq fcitx*) # 通配安装
-R $(pacman -Qsq fcitx) # 通配删除
-Rcns plasma # 删除plasma
-Rns # 删依赖并删配置
-Scc # 清除缓存
-Qii zsh # 包信息
-Ql zsh # 查看安装的文件
-Qo /bin/zsh # 查看文件属于的包
-Qdt # 查孤儿包
源
mirrors.163.com
apt
源
阿里云mirror: https://developer.aliyun.com/mirror
ubuntu
sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
downgrade # 用于给pacman安装过后软件降级
yum
list # 列出所有包
updates # 列可更新的包
installed # 列已安装
extras # 已安装但不在yum repository的包
search
install
remove
info # 包详情
updates
installed
extras
provides # 包文件
whatprovides 'bin/isstat' # 查看命令属性哪个包
history
list
redo 序号 # 重新做序号
undo 序号 # 恢复历史中执行的动作
groups list # 查看安装的组
设置代理
/etc/yum.conf
proxy=http://XXX.XXX.XXX.XXX:XXXX
或
proxy=FTP://XXX.XXX.XXX.XXX:XXXX
proxy_username=你的用户名
proxy_password=你的用户名的密码
编译用包
build-essential # yum中基本编译依赖包
yum install make cmake apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch freetype-devel ncurses-devel libmcrypt libtool flex pkgconfig libevent glib libgnomeui-devel
dpkg # 管理deb包程序
-i # 安装
-r # 删除
pkgfile # 查看命令所需的包
编译
#
:() { :|:& };: # fork bombmake
make
注意
缩进只能用tab
命令
make
make install
make glide
条目里执行shell
@echo $(shell $(SHELL_PATH))
o->
TESTS = test/*.js
REPORTER = spec
TIMEOUT = 10000
MOCHA_OPTS =
test:
@NODE_ENV=test ./node_modules/mocha/bin/mocha \
--reporter $(REPORTER) \
--timeout $(TIMEOUT) \
$(MOCHA_OPTS)
$(TESTS)
test-cov
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov > coverage.html
test-all: test test-cov
.PHONY: test
o->
TESTS = $(shell ls -S `find test -type f -name "*.js" -print`)
TESTTIMEOUT = 5000
MOCHA_OPTS =
REPORTER = spec
install:
@$PYTHON=`which python2.6` NODE_ENV=test npm install
test:
@NODE_ENV=test ./node_modules/mocha/bin/mocha \
--reporter $(REPORTER) \
--timeout $(TIMEOUT) \
$(MOCHA_OPTS) \
$(TESTS)
test-cov:
@$(MAKE) test REPORTER=dot
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov > coverage.html
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=travis-cov
reinstall: clean
@$(MAKE) install
clean:
@rm -rf ./node_modules
build:
@./bin/combo views .
.PHONY: test test-cov clean install reinstall
cmake
makepkg # 创建软件包
调试
#
perf # 性能调优
strace # 跟踪系统调用
itrace # linux系统编程中跟踪进程的库函数调用
-S ./hello # 跟踪所有系统调用
dtrace # 应用程序动态跟踪
bpftrace # btrace2.0
gdb
SystemTap # 内核动态探针
图形程序
#
桌面
#
kde
xfce
gnome
#
启动
.xinitrc
exec gnome-session
startx
gnome3应用程序列表
/usr/share/applications
取消ctrl+alt+down/up
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-down "['']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-up "['']"
gnome-shell
alt + f2后输入lg
gnome terminate
ctrl + shift + c/v # 复制/粘贴
ctrl + shift + t/n # 打开新标签/新窗口
ctrl + w 或 alt + backspace # 删除最后的word
ctrl + shift + w/q # 关闭当前term/所有term
ctrl + shift + f/g/h # 搜索/搜索下一个/搜索上一个
ctrl + pageUp/pageDown # 切换标签
ctrl + shift + pageUp/pageDown # 移动标签
alt + 1/2/3/..../0 # 切换到第1/2/3/....../10个标签
系统快捷键
右键快捷键
shift + f10
i3
#
启动
.xinitrc
exec i3
awesome
#
启动
.xinitrc
exec /usr/bin/awesome >> ~/.cache/awesome/stdout 2>> ~/.cache/awesome/stderr
命令
awesome
awesome-client
配置
配置模板
/etc/xdg/awesome/rc.lua
.config/awesome/rc.lua
Variable definitions # 可定义布局优先级
Menu # 右键菜单
Wibar # 生成screen, 设壁纸
Mounse bindings # 鼠标键绑定函数
Key bindings # 快捷键
Rules # client规则, 如在哪个screen显示
Signals # client启动信号触发动作
自定义
API
文档地址
https://awesomewm.org/apidoc/
快捷键简写
modkey # win键
Mod1 # alt
gears # 工具组件
wibox # wibar
widget
layout
beautiful # theme
init(gears.filesystem.get_configuration_dir() .. "/themes/default/theme.lua")
# 主题
useless_gap = 5 # 窗口间隔
theme.lua文件
theme.wallpaper = "~/.config/awesome/themes/awesome-wallpaper.png"
# 背景
naughty
notify({ preset = naughty.config.presets.critical, title = "Oops, there were errors during startup!", text = awesome.startup_errors })
menubar
menu_gen
hotkeys_popup
awful
layout
tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
key({ modkey }, "F12", function () awful.spawn{ "xlock" } end)
# 快捷键
awful.key({ "Mod1" }, "Escape", function () awful.menu.menu_keys.down = { "Down", "Alt_L" } awful.menu.clients({theme = { width = 250 }}, { keygrabber=true, coords={x=525, y=330} }) end),
widget
rules
spawn("firefox", { tag = mouse.screen.selected_tag })
util.spawn_with_shell("~/.config/awesome/autorun.sh")
# 随桌面启动脚本
autorun.sh
#!/usr/bin/env bash
# nothing to use
function run {
if ! pgrep $1 ; then
$@&
fi
}
if randr | grep -q 'eDP1 connected' ; then
run xrandr --output VIRTUAL1 --off --output eDP1 --mode 1920x1080 --pos 0x720 --rotate normal --output DP1 --off --output DP2-1 --mode 2560x1080 --pos 3360x720 --rotate normal --output DP2-2 --off --output DP2-3 --off --output HDMI2 --off --output HDMI1 --primary --mode 2560x1440 --pos 1920x0 --rotate left --output DP2 --off
fi
run ibus-daemon -d -x
run nm-applet
插件
revelation # 全局client
shifty # 动态tag
naughty # 通知
vicious # widgets
obvious # widgets
bashets # widgets
小程序
#
cmatrix # 终端黑客帝国
screenfetch
import # 截图
import a.png # 选取区域
-pause 3 -frame a.png # 截窗口, 延迟3秒(为了选定)
xgamma -gamma .75 # 调整屏幕色值
display # 显示图片
display *.png # 幻灯片
-delay 5 # 5百分之秒切换
快捷键
空格 # 下一张
退格 # 上一张
h # 水平翻转
v # 垂直翻转
/ # 顺时针翻转90度
\ # 逆时针旋转90度
> # 放大
< # 缩小
f7 # 模糊
任务栏
#
nm-applet
# 联网
输入法
#
fcitx
ibus
ibus-daemon -d -x -r # ibus后台运行
模拟
#
wine
winetricks # 安装wine的各种依赖
cabextract # microsoft cabinet获取工具
资源管理
#
nautilus
快捷键
<Ctrl+L> # 路径编辑
<Ctrl+W> # 关闭tab
<Ctrl+Shift+W> # 关闭所有tab
<Ctrl+T> # 新建tab
<F9> # 侧边栏
Oct 11, 2018
基础
#
监控的方式
主动、被动、旁路(舆情)
监控类型
服务端监控、客户端监控
目标
全、块、准
指标
请求量、成功率、耗时
统计
#
指标
访问、访客
停留时长
跳出率
退出率
转化率
参与度
显示方式
选时间段
时序数据表
max、min、avg
埋点
通过可视化工具配置,非硬编码
第三方
友盟
百度移动
魔方
App Annie
talking data
神策数据
物理机
#
Load Average
#
介绍
数字n表示n倍
cpu
#
Usage: 100%
system
user
IO wait
Saturation: 1.0core
Max Core Usage: 1.0core
Interrupts and Context Switches: 10k
Processes: 10ops
create(Forks)
Runnable
Blocked
mem
#
Physical Memory: RAM(Random-Access Memory)存储器
used
free
buffers
Virtual Memory
介绍
映射到RAM或Disk
used
available
Swap Space
used
free
Swap Activity
swap in(read)
swap out(write)
disk
#
space
增长趋势
I/O Activity
read(page in)
write(page out)
File Descriptors: 1Milion
limit
allocated
I/O Latency: 5ms
write
read
I/O Load: 3
write
read
network
#
traffic: MB/s
inbound
outbound
Utillization Hourly: GB
sent
received
Local Network Errors: 0ops
transmit drop
receive drop
transmit errors
TCP Retransmission
segments retransmitted: 0ops
retransmit ratio: 0%
应用监控
#
Prometheus
# 监控, go实现
Grafana
# 监控
Zabbix
# 分布式监控
Nagios
# 监控
Ganglia
Zenoss
Open-falcon
emq
# mqtt broker, erlang开发, 管理控制台
APM
#
# Application Performance Management
SkyWalking
CAT
Jaeger
Pinpoint
Zipkin
Dapper
# C#
Mysql
#
总览
Services: 38
Min MySQL Uptime: 20 hours
Max MySQL Uptime: 2.4 years
Total Current QPS: 3.4k ops
Total InnoDB Buffer Pool Size: 431GiB
Top Service Used Connections: 800
Top Service Used Connections: 80%
Top Service Client Threads Connected: 60%
Top Service Active Client Threads: 99%
Top Service Threads Cached: 100%
单节点
#
总计
Uptime: 29 weeks
Version: 5.7.26
Current QPS: 32
InnoDB Buffer Pool Size: 3GiB
Buffer Pool Size of Total RAM: 10%
Connections
Connections
Max Connections
Max Used Connections
Connections
Aborted Connections
Aborted Connects(attempts): 0 ops
Aborted Clients(timeout): 0 ops
Client Threads
Clients Threads Activity
Peak Threads Connected: 22
Peak Threads Running: 2
Thread Cache
Thread Cache Size
Threads Cached
Threads Created
Temporary Objects & Slow Queries
Temporary Objects
Created Tmp Tables: 5
Created Tmp Disk Tables: 0.3
Created Tmp Files: 0
Slow Queries: 0 ops
Select Types & Sorts
Select Types
Select Scan: 14 ops
Select Range: 4 ops
Sorts
Sort Rows: 1 ops
Sort Scan: 0 ops
Sort Range: 0 ops
Table Locks & Questions
Table Locks Immediate: 0.6 ops
Table Locks Waited: 0 ops
Questions: 32
Network
Network Traffic
Outbound: 70 KBs
Inbound: 15 KBs
Newtwork Usage Hourly
Sent: 240 MiB
Received: 52 MiB
Memory
System Memory: 31 GiB
InnoDB Buffer Pool Data: 2 GiB
InnoDB Log Buffer Size: 32 MiB
Key Buffer Size: 8 MiB
Query Cache Size: 1 MiB
Command, Handlers, Processes
Top Command Counters
select: 25
set option: 4
rollback: 0.6
commit: 28
stmt_prepare: 28
stmt_execute: 28
stmt_close: 28
begin: 28
show variables: 0.2
alter_table: 0
delete: 0.2
insert: 3
replace: 0
update: 40
Top Command Counters Hourly: 100k
Handlers
read_md_next: 800ops
write: 150ops
read_key: 100ops
read_next: 100ops
external_lock: 60ops
read_first: 13ops
update: 2ops
delete: 1ops
read_prev: 0ops
read_md: 0ops
Transaction Handlers
commit: 25ops
rollback: 0.6
Process States
idle: 20
other: 1
executing: 1
sending data: 1
statistics: 0
preparing: 0
init: 0
Query Cache
Query Cache Memory
query cache size: 1 MiB
free memory: 1 MiB
Query Cache Activity
not cached: 25
queries in cache: 0
prunes: 0
Files and Tables
File Openings: 0.2
Open Files: 65k
Table Openings
Open Cache Status
Hits: 40ops
Misses due to Overflows: 17
Misses: 16
Open Tables
Table Open Cache: 2k
Open Tables: 2k
Table Definition Cache
Table Definition Cache Size: 1k
Open Table Definitions: 700
Opened Table Definitions: 0
Node Summary
#
总计
Node Name
Uptime: 1.4 years
Load Average: 0.6
RAM: 32GiB
Memory Available: 63%
Virtual Memory: 48GiB
Disk Space: 2.3TiB
Min Space Available: 26%
CPU Usage
iowait: 28%
user: 10%
system: 2%
CPU Saturation and Max Core Usage
Normalized CPU Load: 0.8
Max Cpu Core Utilization: 30%
Disk I/O and Swap Activity
Disk Writes(page out): 30 MBs
Disk Reads(page in): 30 MBs
Swap Out(writes): 0
Network Traffic
Outbound: 3MBs
Inbound: 330 kBs
InnoDB
#
总计
Buffer Pool Size: 16GiB
Buffer Pool Size of Total RAM: 52%
Total Redo Log Space: 900 MiB
Max Log Space Used
Max Transaction History Length: 300k
Data Bandwidth: 23MBs
Fsync Rate: 40ops
Row Lock Blocking: 0.02%
Activity
Row Reads: 20k
Row Writes: 100
Read-Only Transactions: 0
Read-Write Transactions: 0
Transactions Information(RW): 0
Misc Transactions Information: 0
Storage Summary
Tables: 1014
Data Buffer Pool Fit: 2%
Avg Row Size: 900B
Index Size Per Row: 700B
Space Allocated: 900GiB
Space Used: 900 GiB
Data Length: 500 GiB
Index Length: 400 GiB
Estimated Rows: 600 Mil
Indexing Overhead: 80%
Free Space Percent: 0.4%
Free: 4GiB
Disk IO
总计
InnoDB Page Size: 16 KiB
Avg Data Read Rq Size: 16 KiB
Avg Data Write Rq Size: 20KiB
Avg Log Write Rq Size: 4 KiB
Data Written Per Fsync: 70 KiB
Log Written Per Fsync: 20 KiB
Data Read Per Row Read: 27B
Data Written Per Row Written: 66 KiB
Auto Extend Increment: 64MiB
Double Write: ON
Fast Shutdown: OFF
Open Files: 2k
File Use: 100%
InnoDB Data I/O
Data Reads: 37 ops
Data Writes: 25 ops
InnoDB Data Bandwidth
Data Read: 10 MBs
Data Written: 10 MBs
InnoDB Log IO
Log Written: 40 kBs
Log Writes: 4 ops
InnoDB FSyncs
Data Fsyncs: 7 ops
Log Fsyncs: 2 ops
InnoDB Pending IO
Pending Data Reads: 0
Pending Data Writes: 0
Pending Log Writes: 0
InnoDB Pending Fsyncs: 0
IO Objects
Targets Bandwidth
Targets Load
Targets Read
Targets Read Load
Targets Write
Targets Write Load
Targets Read Latency
IO Targtes Write Latency
Reads by Page Type
Writes by Page Type
Buffer Pool
总计
Buffer Pool Size: 2GiB
Buffer Pool Size of Total RAM
NUMA Interleave
Buffer Pool Activity: 215 ops
BP Data
BP Data Dirty
BP Miss Ratio: 0.32%
BP Write Buffering: 4
Pool Chunk Size: 128 MiB
Buffer Pool Instances: 8
Buffer Pool Pages
data: 120k
free: 8k
misc: 2k
Buffer Pool Data
data total: 2GiB
Estimated Dirty Data Limit: 1GiB
Data Dirty: 5MiB
Buffer Pool Page Activity:
Pages Read: 40 ops
Pages Written: 20 ops
Pages Created: 3 ops
Buffer Pool Requests
read requests: 10k ops
wite requests: 200 ops
Read-Ahead
Pages Fetched by Linear Read Ahead: 3ops
Paged Fetched by Read Ahead but Never Accessed: 0.01 ops
Paged Fetched by Random Read Ahead: 0ops
Buffer Pool LRU Sub-Chain Churn
Buffer Pool - Replacement Management
Checkpointing and Flushing
Logging
Locking
Undo Space and Purging
Page Operations
Adaptive Hash Index
Change Buffer
Contention
Misc
Online Operations(MariaDB)
Defragmentation
Online DDL
Overview
#
I/O Thread Running
SQL Thread Running
Read Only
Connections
Service Used Connections: 750
Service Aborted Connections: 15
Threads
Service Client Threads Connected: 500
Service Active Client Threads: 25
Service Thread Cached: 55
Queries & Questions
总计
Top Service Queries: 9.3k ops
Top Service Questions: 3k ops
Top InnoDB I/O Data Reads: 99.9%
Top InnoDB I/O Data Writes: 100%
Top Data Fsyncs: 50%
Top Service Queries: 2.5k
Top Service Questions: 0.5k
InnoDB I/O
Top Service Data Reads: 2k rps
Top Service Data Writes: 1.5k wps
Top Service Data Fsyncs: 100 ops
Temporary Objects
Service Temporary Objects: 150
Top Service Selects
Sorts
Top Service Sorts: 50k
Locks
Top Service Table Locks: 3 ops
Network
总计
Top Service Incoming Network Traffic: 10 MBs
Top Service Outgoing Network Traffic: 30 MBs
Service Incoming Network Traffic: 2 MBs
Service Outgoing Network Traffic: 5 MBs
Query Cache
总计
Top Service Used Query Cache: 99%
Service Query Cache Size: 100 MiB
Files
总计
Top Percentage of File Openings to Opened Files: 100%
Top Percentage of Opened Files to the Limit: 0.25%
Service File Openings: 250
Service Opened Files: 160
Table Openings
总计
Top Open Cache Miss Ratio: 85%
Lowest Service Open Cache Hit Ratio: 60%
Open and Cached Table Definitions
总计
Min Service Opened Table Definitions: 0
Top Service Opened Table Definitions: 230 ops
Top Service Open Table Definitions 1.5k ops
Top Open Table Definitions to Definition Cache: 100%
Service Table Definition Cache: 1.5 KiB
Service Opened Table Definitions: 210 ops
Service Open Table Definitions: 1.4k
主从复制
#
Replication Delay: 10
Binlogs Size: 10GiB
Binlog Data Written Hourly
Binlogs Count: 30
Binlog Cache Use Hourly: 300k
Relay Log Space: 300MiB
Relay Log Written Hourly
Oracle
#
状态: alive
活动会话(user)
进程计数
执行计数、提交计数、回滚计数
等待时间
并发等待: 200ms
提交等待: 50ms
应用等待: 50ms
网络等待: 10ms
系统I/O等待: 100ms
用户I/O等待: 1s
组态等待: 2ms
scheduler等待: 500ms
表空间
表空间类型:持久、临时、重做
使用率
剩余空间: 100GB
资源利用率
branches
cmtcallbk
dml_locks
enqueue_locks
PostgreSQL
#
总览
services个数
Active Connections
Total Disk-Page Buffers: 32MiB
Total Memory Size for Each Sort: 16MiB
Total Shared Buffers: 128GiB
Services Autovacuum: 100%
Connections
Top5 Service Connections: 600
Top5 Service Active Connections: 5
Service Idle Connections
Service Active Connections
Autovacuum
Service Value: Yes
Tuples
总计
Total: 170M ops
Max Fetched: 6M ops
Max Returned: 6M ops
Max Inserted: 485 ops
Max Updated: 560 ops
Max Deleted: 371 ops
Service Fetched Tuples Rate: 2M ops
Service Returned Tuples Rate: 2M ops
Service Inserted Tuples Rate: 100 ops
Service Updated Tuples Rate: 100 ops
Service Deleted Tuples Rate: 50 ops
Transactions
总计
Total: 7.5k ops
Max Commits: 270 ops
Max Rollback: 0.2 ops
Max Duration: 55 s
Service Commits: 100 ops
Service Rollbacks: 0.05 ops
Service Duration of Active Transactions: 850 ms
Service Duration of Other Transactions: 760 ms
Temp Files
总计
Max Number of Temp Files: 17k
Max Size of Temp Files: 178GiB
Service Numbers: 17k
Service Size: 178GiB
Conflicts & Locks
总计
Total Locks: 6.5k
Total Deadlocks: 0
Total Conflicts: 0
Service Locks: 100
Service Deadlocks: 0
Service Conflicts: 0
Cache Hit
总计
Min Cache Hit Ratio: 97%
Max Cache Hit Ratio: 100%
Service Lowest Cache Hit Ratio: 100%
Canceled Queries
Service Canceled Queries: 0
Blocks Operations
总计
Total Blocks Operations: 0 ops
Max Blocks Writes: 0 ops
Max Blocks Reads: 0 ops
Servcie Blocks Reads: 0 ops
Service Blocks Writes: 0 ops
Buffers Operations
总计
Max Allocaetd Bufferes: 38
Service Allocated Buffers: 10 ops
Service Fsync Calls by a Backend: 0 ops
Service Written Directly by a Backend: 5 wps
Service Written by the Background Writer: 0 wps
Service Written During Checkpoints: 50 wps
Checkpoint Stats
总计
Total Written Files to Disk: 140k
Total Files Synchronization to Disk: 27
Service Files Synchronization to Disk: 0.1 ops
Service Written Files to Disk: 400 wps
Oct 11, 2018
编译
#
--with-features=tiny # 只包含最基本功能。small, normal, big, huge, :h feature-list查看
命令
#
vim -u NONE -N # -u NONE 不加载配置文件和插件,并进入vi兼容模式
-u code/essential.vim # 加载指定配置文件
-N set nocompatible # 不进入vi兼容模式
--version # 可查看特性
mode
#
普通模式
插入模式
可视模式
v/V # 面向字/面向行 可视模式
<C - v> # 面向块 可视模式
gv # 重选上次选区
o # 切换到选区的开头, 再按切换回尾端
替换模式
R
命令行模式(Ex命令)
: # 可视模式中选定范围,切换到命令行时,自动输入range'<,'>代表选中区
操作符待决模式 # operator 与 motion之间的空闲时期
# 两个字符的operator, 字符间的空闲时期不是该模式,是命名空间,是普通模式的扩充
# 有了这个模式,能创建自定义映射项来激活或终结操作符待决模式,就可以自定义operator和motion
选择模式 # 类似windows中选中
<C - g>在可视和选择模式切换
历史
q: # 命令历史
q/ # 搜索历史
operate
#
思想
{operator}{motion}
{operator}{text-objects}
shortcut key
ctrl + c # 同Esc
motions
. # 重复前一次修改, 目标做到一键移动,一键执行。修改是指: 一个normal模式下的按键, 插入内容, <ESC>; 或一组normal模式下按键
K # 当前单词的:h 手册
ga # 当前字符的unicode码
Ex command # 可视模式下选中行, : 时前面有'<,'> 表示对选中的行执行操作
:h e 或 :help e # 查看e的帮助
vimtutor 查看教程
operator 查看operator
map-operator 查看自定义operator
omap-info 查看自定义motion
digraphs-default
digraphs
digraphs-table 查看二合字符表
ex-cmd-index 查看所有Ex命令
vi-differences vim 相对vi的特性
:version # 查看版本和支持的功能
:! command # 执行某shell命令(CR返回)
!! 执行前一个命令
r!command 执行结果插入当前位置
w!command 当前文件作为输入执行
:cd directory # 修改工作目录
:sh # 跳到shell, 再执行exit返回
:map bbc ia # 定义命令序列ia的别名为bbc
:pwd # 显示当前目录
:normal A; # 执行普通模式命令A;, 添加分号到行尾
系统命令
:grep t * # 在当前所有文件中匹配t, 自动加-n参数(显示行号)
:ls
locate oper
#
motion
^/$/0/<home>/g_/h/l/j/k/w/W/e/E/b/B/ge/gE/gg/G/[[/]]/(/)/{/}/nH/M/nL/点鼠标
# 移动motion
ge同b, 停在单词尾部
<home>同0, 到行开始, ^则到本行第一个字符
gg同[[,G同]],10G跳到第10行
fx 移动到下一个x, F反向查找, tx 移动到x的前一个字符
nG 跳到第n行
f/F/t/T # 行搜索motion 重复查找(以相反方向重复搜索)
; # 重复移动上次f/F/t/T的字符
, # 撤销上次f/F/t/T移动
* # 查找当前词
nzz/nz- # 跳到指定行, 显示在屏幕中间/底部
zz 当前屏幕到中间
可视模式
$ # 块可视模式中,表示所有行尾
i/a # 块可视模式中有不同含义
operator
3G # 跳到第3行
/text # 查找text,按n健查找下一个,按N健查找前一个。
?text # 查找text,反向查找,按n健查找下一个,按N健查找前一个。
*或# # # *相当于/,#相当于?
g* 搜索子串
gd 同* 但跳到第一个匹配序列
% # 搜索对应括号
o-> marks
`` # 跳回
`" 最后编辑的位置
`[ 最后修改的开始位置
`] 最后修改的结束位置
'. `. 跳到上次编辑位置
'' # 跳回到第一个非空白字符
marks # 显示系统全部书签
ma # mark当前光标位置为a,小写字母不同文件标记不同行, 大写字母全局标记,但webstorm中ideaVim不行
`a # 跳到a的位置
Ex command
:10 # 跳到第10行, 同10G, 0位于第一行上方
:jumps # 输出能跳往的位置列表,可跳转多个文件
:$ # 文件结尾
:. # 当前位置
:% # 文件中的所有行
:'< # 选中区开始
:'> # 选中区结尾
:'m # 位置标记为m的行
:/<html>/,/<\html>/ # 模式匹配范围
: 1+1, 5-1 # 开始向下偏移一行,结尾向上偏移一行
:vim[grep] abc test # 在test文件中grep匹配abc
shortcut key
<c - e>/y # 向下/上滚动一行
<c - d>/u # 向下/上滚动半屏
<c - f>/b # 向下/上滚动一屏
<c - i>/o # 到下个/上个跳动过的位置
edit oper
#
shortcut key
<C - r> # 撤销的撤销
<C - a>/x # 数字增加/减少1, 对0开关数字进行八进制操作, 0x进行十进制操作。可以设置nrformats改变
插入模式/命令模式
<C - h> # 删除前一个字符
<C - w> # 命令模式可用,删除前一个单词
<C - u> # 命令模式可用,删至行首
<C - [> # 返回普通模式
<C - o> # 到插入-普通模式
<C - v> # 命令模式可用,插入编码对应的字符
065 # 两位的编码
u00bf # 超过3位的unicode码
非数字 # 直接插入, 如expandtab开启后插入tab
<C - k>{char1}{char2} # 命令模式可用,插入以二合字母表示的字符
12
<<
?I
<C - r>{register} # 命令模式可用,插入寄存器内容
补全
<C - n>/p # 自动补全下/上
<C - x> 接着按如下
<C - L> # 整行补全
<C - N> # 根据当前文件里关键字补全
<C - K> # 根据字典补全
<C - T> # 根据同义词字典补全
<C - I> # 根据头文件内关键字补全
<C - ]> # 根据标签补全
<C - F> # 补全文件名
<C - D> # 补全宏定义
<C - V> # 补全vim命令
<C - U> # 用户自定义补全方式
<C - S> # 拼写建议
operator # num + operator 来多次操作, 合并命令如A(同$a), 是为了普通模式下一个按键进行插入,这样能够在.命令中重复
@: # 重复Ex命令
& # 重复substitute命令
x/X # 删除当前字符/删除前一个字符, x等于dl,X 等于dh
u/U # 撤销(Undo)/撤销对整行的操作
r/R # 替换一个字符/持续替换字符,tab是一个字符
gR # 一个tab由tabstop个字符才能替换
gr
y/yy/Y # yank 复制/复制一行/同yy
:y
p/P # 粘贴/前面粘贴
:p
a/A # s当前字符后插入
A同$a, 行尾插入
o/O # 向后插入行
o同A<CR>
O同ko, 向前插入行
s/S # 替换当前字符/替换当前行
s同cl
S同^C
i/I # 当前字符前插入/行首插入
I同^i
c/cc/C # 替换/替换一行/同cc
:0,10c 与 :c
C同c$
d/dd/D # 删除/删除一行/删到行尾
dd 同 :d
10d表示删除10行
D同d$
:0,10d 与 :d
<</>>
可视模式下 </>
命令下 1>>2 表示从1行开始, 作用2行>>, 可以1>>>>2
1,2> 表示 1到2行>>, 可以1,2>>
>G 缩进当前到最后一行
= # 自动缩进
== 自动缩进当前行
! # 用外部命令过滤指定行
如!j, 自动进入命令模式, 选定了指定行进行!
!!当前[count]行
J # 与下行合并
g # :[range]global/{pattern}/{command}
global命令在[range]指定的文本范围内(缺省为整个文件)查找{pattern},然后对匹配到的行执行命令{command},如果希望对没匹配上的行执行命令,则使用global!或vglobal命令。
g/^/m 0 倒序文件行
g_ # 到本行最后一个不是blank字符的位置
gd # 智能跳到当前变量定义的位置
gu/gU # 转换到小写/大写, 如gUw
gugu / guu / gUgU / gUU
g~ # 大写转小写,小写转大写
g~g~ / g~~ 转换一行
可视模式下
U/u # 大写/小写
ex command
:1,10 co 20 # 将1-10行插入到第20行之后。
:1,$ co $ 复制整个文件添加到尾部
:1, 10 m 20 # 第1-10行移动到第20行之后
:ab attr attribute # 缩写, 输入模式中输入attr,再输入非字母字符(空格, 点等),自动补全
ab查看所有缩写
una/unab attr 取消缩写
:! # 执行外部命令
:[range]copy{address} /:t /:co # 复制range到address后, :t 2 表示复制当前行到第2行后
:[range]move{address} # 移动
:[range]join # 连接
:[range]delete[x] # 删除指定范围内的行到寄存器中
:[range]yank[x] # 复制
:[line]put[x] # 指定行后粘贴寄存器中内容
:[range]normal{commands} # 指定范围执行命令
:[range]print / p # 在vim下方回显指定行的内容
text-object
i"
" 表示 光标所在""的内容
'
`
) 表示 ()的内容
( 同上
]
[
>
<
}
{
B 表示 {}的内容
t 表示 tag之间的内容,如<h2>aaaa</h2>
w 表示 光标所在word
s 表示 光标所在句子
p 表示 段落
a" # 包括外围,命令同i
视图模式下
vit # 在可视模式下选中标签内容,如<a>xxx</a>的xxx
patterns oper
#
operator
& # 重复:s上次执行的命令, 不包含g
g& 全局重复:s上次的命令
n/N # 查找下一个/上一个
Ex command
:[range]substitude/{pattern}/{string}/[flags]
:s 用new替换old,替换当前行的第一个匹配
前面是正则, 用()分组,后面用\1引用分组
:s/old/new/g 作用到整行
:%s/old/new/ 作用到每行第一个
:10,20 s/^/ /g 作用到10到20行的每一个
:%s/old/new/g 作用到全文
:s/old/new/gc 每次修改前询问
:[range]global/{pattern}/[cmd]
:g 查找text的行执行命令,如:g/text/s/old/new/g
v/text/command 查找到行不执行命令,其它行执行
:& # 同operator中&
registers oper
#
register # 寄存器
:reg # 查看所有寄存器 或 :reg 1 查看寄存器1的内容
"0p # "0<operator> 粘贴寄存器0的内容
"0y 复制到寄存器0
:pu 0 # 同上
:pu! 0 同 "0P
:y a # 复制当前行到"a寄存器
:5,10y m 复制5到10行到"m寄存器
分类
"" # unamed 缓存最后一次操作内容
"0 # numbered 范围0 - 9 。"0缓存最近一次复制的内容
"1到"9缓存最近9次删除的内容, "9向后则丢弃
第2次删除时,缓存1转存到缓存2, 新的删除内容存到缓存1
"- # small delete 缓存行内删除内容
"a # named 范围a - z 与 A - Z
": # read-only
如 ": 最近命令 ". 最近插入文本 "% 当前文件名 "# 当前交替文件名
"= # expression 用于执行表达式命令,只读
"* # selection and drop
如 "* "+ "~ 存取GUI选择文本,可用于与外部交互,要求系统剪切板(clipboard)可用
"_ # black hole 表示不缓存,干净删除
"/ # last search pattern 缓存最近的搜索模式
shortcut key
<C - r>0 # 插入寄存器缓冲区内容, 原理是vim插入模式模拟打入
<C - p>0 # 保持格式不变
<C - r>=6 * 35<CR> # 计算结果
宏
qa ... q # 录制宏a,存到寄存器中,可以用"ap粘贴出来
@a # 运行宏a
let @a = "" # 用let @a 在.vimrc设置文件中设置宏a
内置宏
: # 上次的Ex命令
file oper
#
shell
$ vim file1 file2..
$ vimtutor # vim的教程
operator
o-> 折叠
zf # 创建折叠
zf% 创建括号折叠
zf56G 创建从当前行起到56行代码的折叠
zo/zO # 展开当前/递归展开当前(folding open, z这个字母看上去比较像折叠的纸)
zc/zC # 再折叠/递归再折叠(folding close)
[z # 到折叠的开始处
z] # 到折叠的结束处
zk # 向上移动到前一个折叠的结束处
zd/zD # 删除当前光标下的折叠/嵌套删除折叠
o-> 文件对比
vim -d file1 file2
diffsplit file2
diffthis
diffupdate
[c # 跳到前一个不同点
]c # 跳到后一个不同点
dp # 合并增加另一个 (diff put)
do # 合并增加当前 (diff get)
Ex command
:help # 显示帮助, 同F1
帮助文件中位于||之间的内容是超链接,可以用Ctrl+]进入链接,Ctrl+o(Ctrl + t)返回
:help tutor 显示vimtutor的教程
:help xx 显示某个帮助, 如help CTRL-[
:help 'number' 显示vim选项的帮助
:help <Esc> 显示特殊键的帮助
:help -t 显示vim启动参数的帮助
:help i_<Esc> 插入模式下Esc的帮助,某个模式下的帮助用 模式_主题的模式
:r/nr filename # 插入一个文件的内容/插入到第n行
:f # 显示当前文件状态
:.= # 打印当前行号
:= 打印总行号
:open file # 新窗口打开文件
:saveas filename # 另存为并切换到文件
:tabnew # 新建标签页
:split file/:new # 屏幕分割
:vsplit 纵向打开窗口
:q # q! 强制退出
:w/:write # :w filename 写入新文件
:x # 有改动时保存并退出, 无改动只退出
ZZ
:e/:edit # 重新打开文件, e! 放弃所有修改重新打开文件
e filename 当前窗口打开另一个文件
:bn/:bp # 切换上个/下个文件
:saveas <path/to/file> # 另存为到 <path/to/file>
:!command # 执行shell命令,如 :!ls
:!perl -c script.pl 检查perl脚本语法,可以不用退出vim,非常方便。
:!perl script.pl 执行perl脚本,可以不用退出vim,非常方便。
:suspend # 挂起vim,回到shell,命令fg返回vim。
:buffers/:ls # 缓冲区列表
:bprev # 上一缓冲区
:bnext # 下一缓冲区
o-> 多视窗
:vert # 横向打开
:vsplit # 横向打开
:split
:prev # 上一个文件
:next # 下一个文件
:close # 最后一个窗口不能使用此命令,可以防止意外退出vim。
:only # 关闭所有窗口,只保留当前窗口
o-> 标签窗口 # 启动 Vim 时用 "vim -p filename ..."
:tabe[dit] # 打开文件到标签
:tabnew # 在当前标签页之后打开带空窗口的新标签页。
:tabc[lose][!]{count} # 关闭当前标签页。 {}表示关闭第count个标签
:tabo[nly][!] # 关闭所有其它的标签页。
:tabn[ext] {count} # 切换到后面的标签页
:tabp[revious] {count} # 切换到前面的标签页
:tabr[ewind] # 回卷跳转
:tabfir[st] # 转到第一个标签页。
:tabl[ast] # 转到最后一个标签页。
:tabm[ove] [N] # 重排标签页
把当前标签页移到第 N 个标签页之后。用 0 使当前标签页成为首个标
签页。如果没有 N,当前标签页成为最后一个。
:tabs # 列出标签页和它们包含的窗口信息。
当前窗口显示 ">"。
修改过的缓冲区显示 "+"。
:tabd[o] {cmd} # 对每个标签页执行 {cmd}
shortcut keys
ctrl - z # 同 :suspend
ctrl + g # 同 :f
o-> 多视窗
ctrl + w + hljk
ctrl + w + w # 跳到下一个
ctrl + w + p # 跳到前一个
settings
#
设置文件
/etc/vimrc
~/.vimrc # vim的配置文件, 优先于.exrc
~/.exrc # vi的配置文件
命令
:set
all # 打印所有set选项
nocompatible # 不设置vi兼容
ruler? # 查看是否设置了ruler,在.vimrc中,使用set命令设制的选项都可以通过这个命令查看
shell :/usr/bin/sh # 使用SystemⅤ中的shell来执行vi中以!或 :!开头的shell命令
nrformts # 设置进制, <c - a> <c - x>时对八进制有用,如07
encoding=utf-8 # 程序显示编码
enc # 同上
fileencodings=ucs-bom,utf-8,cp936 # 设置读取文件支持的编码
fencs # 同上
fileencoding=utf-8 # 当前文件编码
fenc # 同上
termencoding=utf-8 # 设置终端编码
tenc # 同上
list # 显示非打印字符,如tab,空格,行尾等。
nolist # 取消显示非打印字符, 如果tab无法显示,请确定用 set lcs=tab:>- 命令设置了.vimrc文件
number # 显示行号
nu # 同上
nonumber # 不显示行号
nonu # 同上
reprot=2 # 用户做2行以上修改时显示统计信息
hlsearch # 设置查找高亮
hls # 同上
incsearch # 查找高亮所有(增量高亮)
smartindent # 括号补全
sm # 同上
ignorecase # 查找时忽略大小写
ic # 同上
noignorecase # 查找时不忽略大小写
noic # 同上
expandtab # 存起来的文件, 用space替换tab
shiftwidth=4 # 换行时缩进长度
sw # 同上
softtabstop=4 # 插入模式tab长度
tabstop=4 # 识别和显示tab时,转换成space的长度
autoindent # 启用自动缩进
ai # 同上
foldmethod=indent # 设置折叠
fdm # 同上
indent 缩进折叠
syntax 语法高亮折叠
expr 表达式定义折叠
diff 对没有更改的文本折叠
marker 对文中的标志折叠
:scriptnames # 脚本文件位置,如.vimrc文件、语法文件、plugin
:syntax clear # 列出已经定义的语法项
clear 清除已定义的语法规则
case match 大小写敏感,int和Int将视为不同的语法元素
case ignore 大小写无关,int和Int将视为相同的语法元素,并使用同样的配色方案
配置
inoremap <C-]> <C-X><C-]> # 插入模式下映射
nnoremap # 在normal模式下映射
fileType plugin on # 激活内置插件, 检测文件类型
filetype on # 同上
plugins
#
netrw
介绍
自带插件
edit ./ # 查看目录树
Ex # 同上
Se # 下面弹出目录树 好用
Ve # 左面弹出目录树 好用
<cr> netrw 进入目录或读入文件 |netrw-cr|
<del> netrw 试图删除文件/目录 |netrw-del|
- netrw 往上走一层目录 |netrw--|
a 在以下三种方式间切换: 正常显示,|netrw-a|
隐藏 (不显示匹配 g:netrw_list_hide 的文件) 和
显示 (只显示匹配 g:netrw_list_hide 的文件)
c 使浏览中的目录成为当前目录 |netrw-c|
d 建立目录 |netrw-d|
D netrw 试图删除文件/目录 |netrw-D|
i 在瘦、长、宽和树形的各种列表方式间切换 |netrw-i|
<c-l> netrw 刷新目录列表 |netrw-ctrl-l|
o 打开新浏览窗口,进入光标所在的目录。使用水平分割。|netrw-o|
p 预览文件 |netrw-p|
P 在前次使用的窗口里浏览 |netrw-P|
r 反转排序顺序 |netrw-r|
R 给指定的文件/目录换名 |netrw-R|
s 选择排序方式: 按名字、时间或文件大小排序 |netrw-s|
S 指定按名字排序的后缀优先级 |netrw-S|
t 在新标签页里打开光标所在的文件/目录 |netrw-t|
v 打开新浏览窗口,进入光标所在的目录。使用垂直分割。|netrw-v|
ctags
将ec57w32.zip解压,在解压后文件夹中找到ctags.exe,将其复制到C:\ProgramFiles\Vim\vim72下,并编辑_vimrc文件,添加以下内容:
set tags=tags;
set autochdir
打开cmd命令行,切换到你要查看的源代码的根目录处,运行
ctags -R
将会在此目录处生成一个tags文件。
用gvim打开一个代码文件,将光标放到某一函数名上,如下图的UpdateViewByPosNo(),按下"ctrl+]",光标会自动跳转到定义处。按下"ctrl+T"会跳回到原来的位置。
变量、结构体、宏等等,都可以这样做。
当你的源文件有更新时,只能重新运行ctags -R命令,来更新tags文件。
taglist
将taglist_45.zip解压,解压后包含一个doc文件夹和一个plugin文件夹,将其中内容分别复制到C:\Program Files\Vim\vim72下的doc及plugin中。
在_vimrc文件中加入以下内容:
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
用gvim打开代码文件(已生成过tags文件),:Tlist,TagList窗口即出现在左侧。
visual-star
Qargs
nerdTreeToggle
介绍
目录显示插件
方案
#
加分号
jA;
j.
批量执行
选中多行, :normal .
批量前缀
选中多行, I
括起文字
ci" # 替换内容""
ca" # 替换所有
di" # 删除内容
cit # 替换标签
执行python
选中代码, :!python
缩进全文
gg=G
替换到"
cf"
esc
<C-[>
目录窗口
:Sex
console输出乱码
language messages utf-8
set termencoding=utf-8
设置文件编码
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
Oct 11, 2018
基础
#
介绍
基于linux LXC,可以实现虚拟化
优点
低成本、高利用率、充分灵活、动态调度
核心网的最终形态
目录
/var/lib/docker
配置
#
镜象网站
https://hub.docker.com/
阿里云个人仓库
入口: cr.console.aliyun.com
docker login -u 934260428@qq.com registry.cn-qingdao.aliyuncs.com
docker tag java/device:1.0 registry.cn-qingdao.aliyuncs.com/mrs-iot/device:1.0
docker push registry.cn-qingdao.aliyuncs.com/mrs-iot/device:1.0
docker pull registry.cn-qingdao.aliyuncs.com/mrs-iot/device:1.0
/etc/sysconfig/docker
# /etc/init.d/docker.conf
OPTIONS='--selinux-enabled --log-driver=journald --insecure-registry 45.55.56.16:5000 --dns 8.8.8.8'
DOCKER_CERT_PATH=/etc/docker
命令
#
常用系统命令
#
systemctl daemon-reload
systemctl restart docker
docker
#
-h
version
login
docker login -u outrun -p asdf
search mysql # 搜索镜像
pull centos:7 # 下载镜像
centos:latest
outrun11/test:nginx1
image
ls
pull
rm
images centos # 本地镜象列表
rmi centos:latest # 删除镜象
container
run # 新建容器
--user root
--name a
--privileged
--name # 显示名
-t # 伪tty, -i 交互的
-rm=true # 执行完后删除
-v /etc/:/opt/etc/ # 挂载本机/etc到容器/opt/etc, /etc/:/opt/etc/:ro 只读挂载, /etc/ 对外共享/etc
-p 1234:80 # 端口映射本机1234端口到容器80
--volumes-from etc_share # 使用另一个容器对外共享的磁盘
-d # 后台运行
--link redis_server:redis # 连接容器的redis命令
-w /var/node # 当前工作目录
-e NODE_ENV='' # 环境变量
--net=bridge # 网络模式,bridge使用虚拟网桥docker0, host共享主机命名空间, container与已存在的一个容器共享命名空间, none关闭网络功能, overlay
--name nsqd -p 4150:4150 nsqio/nsq /nsqd
# 端口
-it centos /bin/bash
# 启动容器, 执行bash
b15 /bin/echo 'hello'
# 启动容器
-it --rm=true --name=ls-volume -v /etc/:/opt/etc/ centos ls /opt/etc
# 创建共享
-it -p 1337:1337 --name=etc_share -v /etc/ centos mkdir /etc/my_share && /bin/sh -c "while true; do echo hello; sleep 1; done"
# 持续运行
-it --rm=true --volumes-from etc_share --name=ls_etc centos ls /etc
# 使用共享
exec # 已有容器中运行
-i
-t
ls
start 026 # 启动已建立的容器, id可以只输入前几位
cp 026e:/docker/file /local/file
stop 026
restart 026e
attach 026 # 进入容器运行命令行, 可显示日志
kill 026e
prune
ps -a # 容器列表
rm # 移除容器
docker rm docker ps -aq
# 移除所有未运行的容器
rm -f 026
build . # 用当前目录Dockerfile创建新镜像
-t="nginx/test" # target
--no-cache # 不用cache
-f a.dockerfile # 指定文件
tag nginx/test:test1 outrun11/test:nginx1
# 远程docker基站创建repository, 名字test
push outrun11/test:nginx1
logs beae3392
swarm # 一个或多个docker组成
init
node # swarm节点
ls
service # 运行于swarm的服务
create
ls
ps
rm
inspect # 详情
scale # 加减副本
update # 变更属性
logs # 查日志
system
prune # 清理所有container, network, image, cache
network # 网卡
ls
rm
prune # 删除全部未使用
inspect # 详情
create
-d nat # 指定驱动
volume # 卷标, 默认挂载到/var/lib/docker/volumes
create
ls
rm
prune # 删除全部未使用
inspect
stack # 单文件定义多服务
deploy
ls
ps
rm
常用
docker inspect 45370 # 详情
--format "{{.State.Pid}}"
docker login a.com -u outrun -p asdf
docker build -t java/gateway:1.0 .
docker push java/gateway:1.0
docker images|grep none|awk '{print $3}'|xargs docker rmi -f
# 删除none镜像
docker image inspect 4de
docker system prune -a
docker exec -it -u root ef2 /bin/bash
docker run --name gateway --rm -d java/gateway:1.0
docker run -it ubuntu
docker restart ef2
docker logs -f -t ef2
docker status 45370 # 显示资源占用
docker save -o a.tar.gz a
docker load < a.tar.gz
nsenter
#
# 指定pid, 不需ssh进入容器运行shell
docker inspect --format {{.State.Pid}} nginx
nsenter -t4629 -n
场景
#
查看镜像内文件
docker run -it --entrypoint sh nginx:latest
查看/var/lib/docker/overlay2/id文件对应container
docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.Id}}, {{.Name}}, {{.GraphDriver.Data.WorkDir}}' | grep bff250
Dockerfile
#
指令
FROM nginx # 基于镜像
MAINTAINER outrun # 指定维护者信息
EXPOSE 80 # 内部服务开启的端口
ENV NODE_ENV test # 环境变量
WORKDIR /src # 指定工作目录
COPY ./bin /data/a # 复制外部文件到内部
VOLUME ["/data/log"] # 创建挂载点
ENTRYPOINT ["/data/a/a"] # 启动命令,只有一个
CMD ["-config", "config.toml"] # docker run 时运行
RUN echo 'test' # build过程中执行的命令
docker-compose
#
docker-compose
-h # 帮助
-f # 指定模板
version
up # 所有模板创建容器
-d # 后台
down # 删除容器、网络、卷、镜像
rm # 删除容器
create # 创建容器
stop # 停止容器
start # 启动容器
restart
pause # 暂停容器
unpause
kill # 强制停止容器
scale # 指定容器个数
ps # 列出所有容器
logs # 查日志
port # 显示容器映射端口
run # 容器中执行命令
exec
config # 查看配置
build # (重)构建容器
pull # 拉依赖镜像
push # 推送镜像
配置
version: '3'
services:
dokuwiki:
restart: always
image: bitnami/dokuwiki:latest
ports:
- 8004:80
environment:
- DOKUWIKI_FULL_NAME=outrun
- DOKUWIKI_EMAIL=934260428@qq.com
- DOKUWIKI_WIKI_NAME=Wiki
- DOKUWIKI_USERNAME=outrun
- DOKUWIKI_PASSWORD=asdfasdf
volumes:
- ./data:/bitnami # 本地:镜像
仓库
#
habor
#
registry
#
htpasswd -Bbn outrun asdf > auth/htpasswd
客户端使用
/etc/docker/daemon.json
{"insecure-registries":["127.0.0.1:5000"]}
sudo systemctl daemon-reload
sudo systemctl restart docker
docker login 127.0.0.1:5000
docker tag java/device:1.0 127.0.0.1:5000/java/device:1.0
docker push 127.0.0.1:5000/java/device:1.0
curl --user outrun:asdf 127.0.0.1:5000/v2/_catalog
# v2表示版本 registry:2
docker pull 127.0.0.1:5000/java/device:1.0
常用API
curl --user outrun:asdf -X GET registry:5000/v2/_catalog
# 列表
curl --user outrun:asdf -X GET registry:5000/v2/ubuntu/tags/list
# tags
curl --user outrun:asdf -X GET registry:5000/v2/ubuntu/manifests/latest
# tag
curl --user outrun:asdf -X GET -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" registry:5000/v2/ubuntu/manifests/latest 2>&1 | grep Docker-Content-Digest | awk '{print ($3)}'
# digest
curl --user outrun:asdf -X DELETE -v --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" registry:5000/v2/ubuntu/manifests/sha256:134c7fe821b9d359490cd009ce7ca322453f4f2d018623f849e580a89a685e5d
# 删除
docker exec -it 4ebff4cdc646 /bin/registry garbage-collect /etc/docker/registry/config.yml
# 删除后, 运行垃圾回收
方案
#
查容器pid
docker container top ea1
docker inspect -f '{{.State.Pid}}' ea1
批量删除镜像
docker rmi $(docker image ls -a |grep jncloud |awk '{print $3}')
进入容器
docker exec -it mysql bash
制作镜像并运行
make
docker build -t search:v1 .
docker images
docker run -p 50088:80 -d search:v1
docker ps -a
docker logs ea1
docker rmi bc8
提交镜像到官方
docker -ps -a
docker login
docker commit d79 outrun11/node_pm2
# 把容器提交为镜像
docker images node_pm2
docker push outrun11/node_pm2
代理
/etc/systemd/system/docker.service.d/http-proxy.conf # 没有时创建
Environment="HTTP_PROXY=http://127.0.0.1:8123"
"HTTPS_PROXY=http://127.0.0.1:8123"
"NO_PROXY=192.168.1.1,localhost"
systemctl daemon-reload
换源
/etc/docker/daemon.json # 没有时创建
{
"registry-mirrors": ["https://nmp74w3y.mirror.aliyuncs.com"]
}
systemctl daemon-reload
systemctl restart docker
登录运行容器
docker exec -it --user root 8ce /bin/sh
工具
#
harbor
企业级register镜像服务器
pipwork
shell写的docker网格配置工具
Oct 11, 2018
常用
#
查看
#
系统日志
journalctl -u kubelet | tail
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -nmdw
日志
kubectl logs -f --since=5m --all-containers=true -lapp=[svcName] -o wide
kubectl get pod [podName] -o yaml
kubectl get pods -nmdw-log -l app=logstash-logstash -w # 等待启动
kubectl describe pods [podName]
kubectl rollout status deploy/[deployName] # 查升级记录
kubectl get events -njnc
-oyaml
--field-selector=type=Normal # Normal, Warning
查ns所有资源
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -nairflow
查节点详情
kubectl get nodes -o json
查扩缩状态
kubectl rollout status deploy/[deployName]
查所有nodeport
kubectl get svc --all-namespaces -o go-template='{{range .items}}{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}{{end}}'
操作
#
进容器
kubectl exec -it [podName] -- /bin/bash
kubectl attach [podName] # 进入主进程IO
用busybox运行命令
kubectl run -it --image busybox -n [nameSpace] [name] --restart=Never --rm
监控
#
kubectl top node -l app=app1
kubectl top pod -nmdw --containers
kubectl describe PodMetrics p1 -njnc-dev
编辑
#
kubectl apply -f a.yml
envsubst < jnc.yml |kubectl apply -f -
kubectl label ns jnc istio-injection=enabled --overwrite
kubectl label ns jnc istio-injection-
亲和性
#
kubectl get nodes --show-labels
kubectl label nodes node1 deploy=mdw
kubectl taint nodes node1 key=value:NoSchedule # NoSchedule、PreferNoSchedule、NoExecute
调试
#
kubectl proxy --port=8080 &
# 以非https形式暴露api
kubectl debug a1 -it --image=yauritux/busybox-curl --share-processes --copy-to=a1-debug
# 嫁接
kubectl run -it --rm test --image=a:0.1.0 --command -- /bin/bash
# 改镜像命令
kubectl run -it --rm busybox1 --image=yauritux/busybox-curl -- /bin/bash
# 同环境busybox
kubectl cp dir1 ns1/po1:/dir1 -c c1
清理
#
删除Evicted/OutOfmemory pod
kubectl get po -njnc-dev | grep OutOfmemory |awk '{print$1}' | tr '\n' '' | xargs kubectl delete pod -njnc-dev
强制删除pod
kubectl delete po -nmdw --force --grace-period=0
删除pv/pvc
kubectl patch pv mdw-mysql-data -p '{"metadata":{"finalizers":null}}'
重建pv
kubectl get pvc p1 -o yaml > a.yml
编辑a.yml
kubectl apply -f a.yml
删除node
kubectl drain node1
维护node不可调度与恢复
kubectl cordon node1
kubectl uncordon node1
强制删除ns
kubectl get ns n1 -o json >tmp.json
删除finalizers列表
kubectl proxy
curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/n1/finalize
操作
#
升级镜像
kubectl set image deploy/[deployName] [imageName]=[imageName:Version]
kubectl edit deploy/[deployName]
扩容
kubectl scale deployment [deployName] --replicas=3
kubectl patch deployment [deployName] -p '{"spec":{"replicas":3}}'
重启
kubectl rollout restart deploy xxx
回滚
kubectl rollout undo deploy xxx
打污点
kubectl taint nodes node1 key1=a:NoExecute
# 添加
kubectl taint nodes --all key1-
# 删除
打标签
kubectl label nodes node1 a=b
容器配置
#
HTTPS
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout tls.key -out tls.crt -subj "/CN=my-domain.com"
kubectl create secret tls my-domain-com-tls --cert=tls.crt --key=tls.key --namespace=allure-docker-service
ingress.yml
spec:
tls:
- secretName: my-domain-com-tls
hosts:
- my-domain.com
部署.docker/config.json成secret
kubectl create secret generic regcred --from-file=.dockerconfigjson=<path/to/.docker/config.json> --type=kubernetes.io/dockerconfigjson
配置私有仓库
kubectl delete secret local
kubectl -n iot create secret docker-registry local1 \
--docker-server=192.168.99.1:5000 \
--docker-username=outrun \
--docker-password=asdf \
--docker-email=934260428@qq.com
连阿里云k8s
kubectl config set-cluster mrs --server=https://106.14.49.217:6443 --certificate-authority=/home/outrun/scripts/work/mrs-k8s/crt --embed-certs=true
kubectl config set-context 297351062922226746-cdf45d630b2284f8ab79bea186c161d9f --cluster=mrs --user=297351062922226746 --namespace=lora-app
kubectl config use-context 297351062922226746-cdf45d630b2284f8ab79bea186c161d9f
kubectl config set-credentials 297351062922226746 --user=297351062922226746 --client-key=/home/outrun/scripts/work/mrs-k8s/297351062922226746.key.pem --client-certificate=/home/outrun/scripts/work/mrs-k8s/297351062922226746.crt --embed-certs=true
集群配置
#
设置当前集群namespace
kubectl config set-context $(kubectl config current-context) --namespace=default
配置DNS解析
kubectl edit configmap coredns -n kube-system
apiVersion: v1
data:
Corefile: |
.:53 {
errors
hosts {
192.168.1.107 a.b.com
}
}
kubectl rollout restart deploy coredns -n kube-system
文件目录
#
/etc/kubernetes
/etc/resolve.conf
命令
#
kubeadm
#
kubeadm init
kubectl
#
全局参数
--help # -h
--output="jsonpath={.data.\.dockerconfigjson}"
--output=yaml
--context=iot
--namespace=iot
--all-namespaces=true
-n [namespace]
--all # 如匹配所有deploy文件
Other Commands
api-resources # 查所有resource
namespace/ns
endpoints/ep
nodes/no
configmap/cm
replicationcontrollers/rc
deployments/deploy
statefulsets/sts
service/svc
ingresses/ing
persistentvolumes/pv
persistentvolumeclaims/pvc
storageclasses/sc
pods/po
cronjobs/cj
daemonset/ds # 每个node运行一个
certificatesigningrequests/csr # csr证书
api-versions # 所有可用的apiVersion
config # 设置集群
config set current-context c1
plugin # 设置插件
version
Basic Commands:
create
-f y1.yml
expose # 修改端口
expose deployment/[deployName]
--target-port=8080
--type=NodePort
run
run [deployName]
--image=gcr.io/google-samples/hello-app:1.0
--port=8080
set # 更新配置
set image deploy/[deployName] *=image1:1.1
# 所有镜像更新为image1:1.1
explain # 查resource文档
pv
get
-o # 格式
yaml
wide
jsonpath='{.items[0].metadata.name}'
-l app=a1 # select label
-c gateway
--show-labels
--selector app=a1
--all-containers=true
edit # 修改配置
edit ingress ingress1
delete
--force
--grace-period=0
Deploy Commands:
rollout
history deploy/deploy1
pause deploy/deploy1
restart
resume deploy/deploy1
status
undo deploy/deploy1 # 回滚到上一版本
scale
scale deploy/deploy1
--replicas=1
autoscale
autoscale deploy/deploy1
--min=1
--max=3
--cpu-percent=80
Cluster Management Commands:
certificate
approve [csrName] # 手动签发证书,/etc/kubernetes/ssl/*
deny
cluster-info # 集群信息
dump
top # cpu 内存负载
node
pod
cordon [nodeName] # node不可调度
uncordon # node可调度
drain [nodeName] # 移除node
taint # node污点
taint nodes node1 key1=val1:NoSchedule
Troubleshooting and Debugging Commands:
describe
logs
attach # 当前终端成为entrypoint
exec
-it device-7b8965d85d-xz4qm bash
-it device-7b8965d85d-xz4qm --container device -- /bin/bash
port-forward # 端口映射
port-forward [podName] 本地端口:pod端口
proxy # 映射ApiServer到本地端口
--port=8080
cp # copy容器文件
cp [namespaceName]/[podName]:[filePath] .
auth
can-i list pods # judge权限
reconcile -f rbac.yaml # 应用权限配置
--dry-run # 仅测试,列出变更
--remove-extra-subjects # 删除除外subject
--remove-extra-permissions # 删除除外权限
debug # pod调试模式, alpha版功能,需要--feature-gates="EphemeralContainers=true"
-it pod1
--image=image1 # 排错工具镜像
--share-processes # 共享进程
--copy-to=pod1-debug
Advanced Commands:
diff
diff -f a.yml # dry run 找出将实行的变更
apply # 升级
-f y1.yml
-k overlays/
patch # 更新属性
patch deploy/deploy1
-p '{"spec":{"unschedulable":true}}'
replace # 替换resource
replace -f a.yml
wait # 等待直到满足条件
-f a.yml
--for=condition=Available
--timeout=1h
kustomize # 多环境部署的overlays补丁
kustomize [dir with kustomization.yml]
Settings Commands:
label
label pods/pod1 a=b
--overwrite # 覆盖更新
--resource-version=1 # 匹配没修改过的情况
annotate
annotate pods/pod1 a='b'
--overwrite
completion # 生成终端命令补全配置
completion bash > /etc/bash_completion.d/kubectl
Helm
#
目录
charts/
Chart.yaml
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: nginx-test
version: 0.1.0
requirements.yaml
requirements.lock
values.yaml
replicaCount: 1
templates/
_helpers.tpl
deployment.yaml
helm命令
查看
ls/list
--all-namespaces
get values a1 # 查看已部署的values变更
history a1 # 查看历史版本
get manifest a1 # 查看已安装模板
template # 查看编译后内容
--debug
search repo a1
--versions
安装
repo
update
install [deployName] [packageName|packageFile|packagePath]
-f values.yaml
--values=values.yaml
--set a=b
upgrade # 热更新部署文件
--debug --dry-run # 只输出编译结果
-i # 没有时执行install
--disable-openapi-validation
uninstall
插件
plugin
install --version master https://gitee.com/mirrors_sonatype-nexus-community/helm-nexus-push.git
ls
运维
rollback a1 1 # 回滚到1版本
打包
create a1
lint --strict a1 # 校验
package a1 # 打包成a1-0.1.0.tgz
相关命令
minikube
#
docker login --username=934260428@qq.com registry.cn-hangzhou.aliyuncs.com
命令
minikube
start --vm-driver=virtualbox \
--memory=4096 \
--cpus=2 \
--log_dir=/home/outrun/logs \
--insecure-registry=192.168.99.1:5000 \
--insecure-registry=registry.cn-qingdao.aliyuncs.com \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
--kubernetes-version v1.17.0
--docker-env=HTTP_PROXY=$HTTP_PROXY \
--docker-env=HTTPS_PROXY=$HTTPS_PROXY \
--docker-env=NO_PROXY=$NO_PROXY \
--image-mirror-country=cn \
--registry-mirror=https://registry.docker-cn.com \
--extra-config=kubelet.MaxPods=5.
# registry一定是minikube容器ip, 可用ifconfig查看
# --insecure-registry修改需要minikube delete
stop
delete
status
docker-env
ip # 得到单机集群ip
service -n iot mosquitto --url
# 得到service的nodePort
ssh
dashboard
addons
list
enable heapster
enable ingress
服务
kube-system
coredns
etcd-minikube
kube-addon-manager-minikube
kube-proxy
kube-scheduler-minikube
nginx-ingress-controller
storage-provisioner
kubernetes-dashboard
dashboard-metrics-scraper
kubernetes-dashboard
平台
#
HPE Container Platform
OpenShift
VMware VSphere
Minikube
Rancher
KubeSphere
Google Cloud Platform(GCP)
Oct 10, 2018
持续集成(CI/CD)
#
# Continuous Integration(持续集成), Continuous Delivery(持续部署)
Jenkins
容器
#
docker
containerd
虚拟化
#
vagrant
# 自动化虚拟机配置
parallels desktop
# 苹果
xen
gnome boxes
hyper-v
# 微软
KVM
#
介绍
kernel-based virtual machine, 使用linux自身的调度器进行管理,所以代码较少
# 又叫qemu-system或qemu-kvm
虚拟化需要硬件支持(如 intel VT技术或AMD V技术),是基于硬件的完全虚拟化
原理
包含一个可加载的内核模块kvm.ko, 由于集成在linux内核中,比其他虚拟机软件高效
使用
检查系统是否支持硬件虚拟化
egrep '(vmx|svm)' --color=always /proc/cpuinfo
VMware
#
安装
安装后会创建两个虚拟网卡
设置
edit -> preferences -> Hot Keys 设置退出快捷键
网络连接方式
1.vm9自带的virtual network editor中选择桥接到有线网卡
2.vm -> setting -> network adapter选项设置
bridged(桥接):与主机平等,可以设置为同一个网段相互访问
nat:通过虚拟网卡连接主机,共享网络
host-only:单机模式
VirtualBox
#
网络连接
|
NAT |
Bridged Adapter |
Internal |
Host-only Adapter |
虚拟机->主机 |
√ |
√ |
× |
默认不能,需设置 |
主机->虚拟机 |
× |
√ |
× |
默认不能,需设置 |
虚拟机->其他主机 |
√ |
√ |
× |
默认不能,需设置 |
其他主机->虚拟机 |
× |
√ |
× |
默认不能,需设置 |
虚拟机间 |
× |
√ |
同网络可以 |
√ |
方案 |
|
|
|
|
linux安装增强iso |
|
|
|
|
iso位置 |
|
|
|
|
/usr/share/virtualbox |
|
|
|
|
编译环境 |
|
|
|
|
kernel-devel |
|
|
|
|
gcc |
|
|
|
|
共享剪切板与拖拽文件
虚拟机启动后devices下设置
共享文件夹
linux下挂载
mount -t vboxsf 共享名 /mnt/share
windows下挂载
我的电脑 右键 映射网络驱动器
clone
clone 时选择更新mac,并在虚拟机中网络连接设置中重写mac与ip
配置主机间ssh免登录,远程ssh与所有主机免登录
PaaS
#
OpenStack
DevOps
#
自动化运维
#
tty.js
# 浏览器运行命令
jenkins
# java实现的持续集成工具
saltstack
# 部署, 自动化运维
puppet
# 自动化运维
selenium
# 自动化运维
chef
Ansible
#
# python实现的自动化部署工具
模式
ad-hoc # 批量命令
playbook # 任务编排,执行yml文件
安装
pip install ansible
配置
优先级
export ANSIBLE_CONFIG=/etc/ansible.cfg
~/.ansible.cfg
/etc/ansible.cfg
ansible.cfg
inventory = /etc/ansible/hosts
library = /usr/share/ansible
forks = 5
sudo_user = root
remote_port = 22
host_key_checking = False
timeout = 60
log_path = /var/log/ansible.log
hosts
[mysql_test]
192.168.0.1
192.168.0.2
命令
ansible
通配符
10.1.1.113
'*'
all
-m
command # 执行命令
-a 'uptime'
file # 操作文件
-a "dest=/tmp/t.sh mode=755 owner=root group=root" # 改属性
-a "src=/etc/resolv.conf dest=/tmp/resolv.conf state=link" # 软链接
-a "path=/tmp/resolv.conf state=absent" # 删除软连接
copy
-a "src=/a.cfg dest=/tmp/a.cfg owner=root group=root mode=0644"
cron # 定时任务
-a 'name="custom job" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate 172.16.254.139"'
group # 操作组
-a 'gid=2017 name=a' # 创建组
user # 操作用户
-a 'name=aaa groups=aaa state=present' # 创建用户
-a 'name=aaa groups=aaa remove=yes' # 删除用户
yum
-a "state=present name=httpd"
service
-a 'name=httpd state=started enabled=yes' # 开机启动
ping
script
-a '/root/test.sh'
shell
-a 'ps aux|grep zabbix'
raw # 同shell
get_url
-a 'url=http://10.1.1.116/a.ico dest=/tmp' # 下载
synchronize
-a 'src=/root/a dest=/tmp/ compress=yes' # 推送
o-> 例子
ansible '*' -m command -a 'uptime'
ansible-doc # 文档
ansible-galaxy # 上传/下载模块
ansible-playbook # 任务编排
ansible-pull # 拉配置
ansible-vault # 文件加密
ansible-console # REPL
资源管理
#
文档管理
#
Confluence
Git Wiki
版本
#
mercurial
# 简称hg,分布式版本控制系统,比git好
clearQuest
# IBM Rational提供的缺陷及变更管理工具。它对软件缺陷或功能特性等任务记录提供跟踪管理。提供了查询定制和多种图表报表。
clearcase
# 配置管理的工具,只是SCM管理工具其中的一种。是RATIONAL公司开发的配置管理工具
spm
# 构建sea.js项目
bower
# 构建前端
redmine
Gradle
#
介绍
基于dsl(Groovy)声明项目自动化构建
环境
命令
gradle
-q # --quiet, 只显示error
init
--type pom # 转换maven项目
wrapper # 生成可独立运行的打包脚本gradlew和gradlew.bat
配置
build.gradle
task hello {
doLast {
println 'Hello world!'
}
}
task hello << {
println 'Hello world!'
}
buildscript{}
allprojects{}
subprojects{}
settings.gradle
rootProject.name = 'choice-scm'
include 'choice-scm-dao'
gradle.properties
org.gradle.parallel=true # 开启并行编译
org.gradle.daemon=true # 守护线程,在第一次编译时开线程并保持
org.gradle.configureondemand=true # 用新的孵化模式,加快编译
org.gradle.caching=true # 启用缓存
org.gradle.warning.mode=none # 屏蔽warning
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Git
#
目录结构
.git
branches
config # 存放版本库git地址
规定
HEAD
# HEAD的版本号, HEAD^^ 表示HEAD之前两个的版本, HEAD~n 表示之前n个版本
buffered stage branch head
# buffered表示当前修改所在的版本,stage是buffered中文件add之后到的版本,branch是stage commit后到的分支(版本),head是远程仓库的最新版本
工作流程
fork + pull / merge request 更新代码
commit message, pr messsage 提交说明
pr是功能展示,前面加"WIP:"
user.name, user.email用公司的
pr必需有人review, assign到人, 推动review
pr不要大
命令
git [command] --help
git help submodule
设置
config
--global http.proxy 'http://127.0.0.1:8123'
仓库
clone
checkout # 切换到分支。检出原有文件替换
-b # 创建并切换到分支
branch # 创建并切换到分支
-r # 指定操作远程分支
-r origin/dev
-a # 本地远程所有分支
dev ef71 # 从ef71创建分支dev
dev
-d dev # 删除
-D dev # 强制删除
remote
remove origin
show # 显示仓库
prune origin # 删除远程没有而本地缓存的远程分支
add origin git@bitbucket.org:outrun/www2.git
# 设置仓库
set-url origin git@github.com:outrun/jeky
# 设置仓库url
fetch # pull加merge
pull origin master
--allow-unrelated-histories
# 本地有已存文件时,强行pull并检查冲突
merge dev # 合并dev到当前分支
--squash dev-bak # dev-bak改动写到stash
push origin master
-u origin master # 设定git push 默认参数
origin :dev
# origin +dev:dev
# 强制替换掉原来版本
commit # stage 提交到branch
-a # 提交删改,忽略增加
-m # 注释
--amend # 合并到上次commit
revert
git commit -am 'revert'
git revert revertid1 取消上次revert
# ideaIDE操作 - local history - revert
示例
revert -m 1 ea1 # 舍弃最近一次commit
rebase master # 相当于当前改动代码之前merge master
reset
--hard ea1 # 回退
stash # 暂存buffered
list # 显示stash
drop # 删除暂存
pop # 恢复并删除暂存
apply stash@{0} # 恢复暂存
tag
-a tag1 # 添加tag1
-m 'a' # 注释
-d tag1 # 删除tag1
示例
git tag -a v1.0.1 -m 'a' e67
show tag1 # 查看tag1的信息
文件
add
-A # 递归
mv a b # 重命名
rm # buffered和stage中都删除
--cached # 只删除git stage中文件, 不实际删
log # HEAD到指定版本号之前的log
--oneline # 每个记录显示一行
--stat # 文件名差异
-p # 细节差异
-2 # 文件最近2次差异
reflog # 包括reset前的版本号
diff master dev # 对比分支差异,可指定到文件。默认对比buffered和stage的差异
--cached # 对比stage和branch的差异
ls-files
-u # 显示冲突文件
-s # 显示标记为冲突已解决的文件
--stage # stage中的文件
submodule
init # 初始化本地配置文件
update
--init --recursive # 同步项目中的submodule
设置
.gitignore
.git/config
~/.gitconfig
[commit]
template=/t.txt
# 每次commit会打开模板
代理
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
git config --global --unset http.proxy
git config --global --unset https.proxy
子模块
.gitmodules
[submodule "a"]
path = a
url = ssh://a.git
git submodule update --init --recursive
方案
回退commit
git reset --hard ea1
# 进行回退
git push -f
# 强制提交
git clean -xdf
# 一般配合git reset使用, 清除已有的改动
补充commit
git commit --amend
git push origin +a:a
合并commit
git rebase -i cf7e875 # 合并Head到cf7e875 commit
修改rebase记录
pick xxxx
s yyyy
s zzzz
git status # 查看冲突
git add . # 解决冲突提交
git rebase --continue
修改commit记录
远程回退
git revert id
忽略文件
git add 逆操作
git rm --cached a
远程保留,忽略本地
git update-index --assume-unchanged a
恢复 git update-index --no-assume-unchanged a
远程删除,忽略本地
git rm --cached a
恢复 git add -A a
远程不论,忽略本地
.gitignore
删本地分支
git branch -D test
删除远程分支
git push origin --delete test
或
git branch -r -d origin/test
git push origin :test
恢复历史版本文件
git reset ba5798aff7778c95252b9e01e924dddb5811bcd7 courseModel.js
git checkout -- courseModel.js
git push origin +master:master # 提交回退版本到远程
查看修改的内容
git show
# 与上个commit 比较
git whatchanged
git log --stat --date=relative
删除历史
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch .idea' --prune-empty --tag-name-filter cat -- --all
git push origin main --force
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
合并commit历史
git branch test-bak
git reset --hard ea1
git merge --squash test-bak
git push origin test -f
git branch -D test-bak
打tag
git tag # git tag -l 'v1.*' 通配查找
git tag -a v1.0 -m "a" # git tag -a v1.0 ba1 给commit打标签
git tag -a v1.0 -m "a" ea1 # 指定commit
git show v1.0
git checkout v1.0
git push origin v1.0 # git push origin -tags 将本地所有标签提交
git tag -d v1.0
git push origin --delete tag v1.0
# git push origin :refs/tags/v1.0c
查tag的commit
git show 1.4.1
git log --pretty=oneline 1.4.0 1.4.1
fork跨网站git
git remote add upstream git@github.com:xuyuadmin/xxljob.git
git fetch upstream
git merge upstream/master --allow-unrelated-histories
文件损坏错误error object file is empty
find .git/objects/ -type f -empty | xargs rm
git fetch -p
git fsck --full
统计某人代码
git log --author="$(git config --get user.name)" --pretty=tformat: --numstat | gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines : %s total lines: %s\n",add,subs,loc }' -
统计所有人代码
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done
共添加或修改行数
git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/'
pr
介绍
fork与pull request
fork后本地
git clone git@github.com:chenduo/auth.git
git remote add upstream git@github.com:Meiqia/auth.git
git merge upstream/main
git push origin main
本地合并更新
git checkout master
git fetch upstream
# fetch远程仓库
git rebase upstream/master
# 合并远程master
git push
git checkout branch1
git rebase master
pr追加
git commit --amend
# 更新本地的本次commit,不产生新的commit
git push origin +branch1:branch1
# 使用本地的commit覆盖远程分支的有问题的commit
处理pr
git fetch origin
git checkout -b pr1 origin/pr1
git checkout master
git merge --no-ff pr1
git reset --hard
git revert -m 1 ea1
# 舍弃pr
git commit -am 'revert'
git revert revertid1 取消上次revert
# intellji - local history - revert
git push origin master
开发
提交
git pull eoecn dev
# 等于git fetch加git merge
git diff
# buffer与HEAD的差异(不包括新建文件)
git add -A .
# 添加到stage
git status
# stage与HEAD的差异
git diff --cached/--stage
# stage与HEAD的详细差异
git diff HEAD
# buffer, stage与HEAD的详细差异
git commit -am 'a'
git push origin dev
网站上点pull request
代码审查
git blame -L 60,60 [filename]
git blame -L 60,60 --reverse 5534e1b4b..HEAD [filename]
# 版本范围内某行代码提交记录
git show [commit id]
github
ssh -T git@github.com
# 检查github ssh是否设置成功
插件
octotree # 树形显示
SVN
#
linux下移植的版本控制器
默认端口: 3690
## 目录结构
conf:配置文件
db:数据库
hooks:勾子(自定义功能)
locks:文件锁
## 命令
### 服务器
svn --version
svnadmin create c:\svn # 创建仓库
## hooks勾子 locks锁 conf db
svnserve -h
svnserve -d -r c:\svn # 启动服务(-d是后台运行,windows不支持,需要创建服务)
## --listen-port 3691 指定监听端口
windows 下注册服务
sc create 服务名 binPath= "d:/suversion/bin/svnserve --service -r c:\svn" displayName= "显示名"
# 注意双引号前面要有空格
sc delete 服务名
使用多个仓库
svnadmin create d:\svn2 创建仓库以后
svnserve -d -r d:\svn2 --listen-port 3691 配置用另一个服务端口启动该仓库 # svn默认启动端口是3690
svn://192.168.10.3:3691 来访问该仓库
#### 客户端
添加项目
svn add test/
svn ci -m "first" # svn commit -m "fisrt"
## ci是checkin
检出
svn checkout svn://192.168.0.2/framework
显示所有分支(目录)
svn ls svn://192.168.0.2/fr --verbose
创建分支
svn copy svn://192.168.0.2/repo/trunk/ svn://192.168.0.2/repo/branches/try-sth -m 'make branch try-sth'
# 注意trunk后面要有/
更换本地分支
svn switch svn://192.168.0.2/repo/branches/try-sth
## 配置
conf/svnserve.conf
anon-access = read # 匿名用户权限
auth-access = write # 登录用户权限
# write权限包括read权限
# none没有验证无权限(匿名权限)
password-db = passwd # 加载conf/passwd文件(中的用户帐户)
authz-db = authz #开启权限控制
同目录authz文件中配置权限
[/] # 对根目录设置权限
* = r # 所有人都可读
outrun = rw # 配置所有版本库只读,outrun可读可写
@admin = rw # @组名 对组进行引用
realm = aa
# 认证域名称, 本svn路径为 svn://192.168.0.2/aa
conf/authz
conf/passwd
[groups]
admin = outrun
例子
authz
[groups]
admin = a1, a2
[/]
@admin = rw
a3 = rw
* = r
passwd
[users]
a1 = 123
a2 = 123
a3 = 123
svnserve.conf
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = trunk
force-username-case = none
## 工具
tortoiseSVN
下载
右键 svn checkout 选择版本 下载 (show log 查看日志)
上传
第一次提交 右键 tor.../import
svn://192.168.10.188 # 输入用户名、密码登录
第二次提交 右键 commit
还原
右键 tor.../Revert 还原其中的文件
多人
右键 svn update ,更新另一个人提交的文件内容
新建文件的提交
tor../add 或 commit的时候选择该文件
tor./Repo-browser,浏览仓库
加锁文件 # 只有自己在不提交更改的前提下才可以解锁
tor../get lock # 不会改变版本
tor../release lock # 解锁,但是新下载的工程不可以再解锁,如果删除原工程则无法解锁
冲突
当前版本已经有人修改后commit的话提示版本已经过时
update:下载所有版本,右键 tor../edit conflicts -> mark as resolved确定解决
# 避免冲突:减少公共修改时间,重写前更新
使用经验
TortoiseSVN -> Setting -> Saved Data 可以清空自动登录
svn的myeclipse插件:
# eclipse6中不能用,eclipse7每次报错,能用,eclipse8报错一次,能用 eclipse10不报错
1.复制插件文件夹features与plugins到/myeclipse 10/dropins/文件夹中
2.创建目录/myeclipse 10/my_plugin/svn/
复制插件文件夹features与plugins到/myeclipse 10/my_plugin/svn/文件夹中
/myeclipse 10/dropins/添加svn.link文件 ,内容为:path=my_plugin\\svn # 这里写相对路径
3.使用:重启myeclipse,弹出确认窗口(也可以从window -> show view中找到svn的视图)
项目:右键->share project 上传项目到svn(bug 第一次只上传空文件夹,再右键Team/提交 时上传项目文件)
再右键就可以对该项目进行一系列的操作了
导入项目:file -> import -> svn
rapidsvn
Ant
#
功能
js压缩
自动发布
build.xml
示例
<?xml version="1.0" encoding="UTF-8"?>
<project default="execute">
<target name="compile">
<javac destdir="." srcdir="."/>
</target>
<target name="execute" depends="compile">
<java classpath="." classname="HelloWorld"/>
</target>
</project>
Maven
#
仓库
mvnrepository.com
依赖范围
compile # 默认,对编译、测试、运行有效
test # 对测试有效
runtime # 对测试和运行有效
provided # 编译和测试有效
system # 本地仓库
import
源
阿里云maven: https://maven.aliyun.com/mvn/view
mvn # 相当于mvn compile
全局
-version # 版本
-e # 错误详情
help:describe # help插件的describe
-Dplugin=help # 显示help插件的详情
-Dfull # 显示完整参数
help:effective-pom # 显示默认设置
生成
archetype:create # 创建java项目
-DgroupId=com.outrun
-DartifactId=erp
-Dversion=0.0.1-SNAPSHOT
-DarchetypeArtifactId=maven-archetype-webapp # 指定模板为webapp
archetype:generate # 向导创建项目
site # 产生html文档
source:jar # 源码打包
generate-sources # 生成源码, 如xdoclet
eclipse:eclipse # 生成或转化成eclipse工程
eclipse:clean # 清除eclipse设置
idea:idea # 生成idea项目
install # compile, package后, 保存到本地仓库
-X # 显示依赖
-Dmaven.test.skip=true # 跳过测试
-rf 模块名 # 从指定模块从新开始
执行
validate # 项目验证
verify # 验证包
compile # 编译
exec:java # 编译完成后,执行java main方法
test-compile # 编译测试代码
test # 运行测试
-skipping # 跳过
compile # 不编译
test-compile # 不编译测试
integration-test # 集成测试
package # 打包
-Dmaven.test.skip=true # 跳过单元测试,不编译
-DskipTests # 跳过单元测试,编译
clean # 清除编译
install-U # 强制更新
package # 编译成jar包
deploy # install后, 上传
jar:jar # 打jar包
插件
jetty:run # 引入jetty-plugin后, 运行jetty
tomcat:run
分析
dependency:list # 列出依赖
dependency:tree # 列出依赖树
dependency:analyze # 依赖分析, 未使用的做标记
dependency:resolve # 列出已解决的依赖
dependency:sources # 下载源码
dependency:copy-dependencies # 得到jar包
常用
分析包依赖
mvn dependency:tree -Dverbose -Dincludes=org.apache.commons:commons-lang3
清理打包文件
mvn clean package -DskipTests
idea工具
打包了带main方法的jar不能引用
在父项目运行mvn package, model中运行会找不到其它model
model运行前先mvn package
手动添加依赖
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar -Dfile=ojdbc7.jar
配置
<groupId> # 包名
<artifactId> # 项目名
<version>
<packaging> # 打包方式, war, jar
<parent> # 父模块
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
</properties>
<dependencies> # 子模块继承
<dependency>
<groupId>
<artifactId>
<version>
LATEST
${spring-cloud.version} #引用properties中定义的变量
<scope> # 何时使用
compile
provided # 类似compile
runtime
test
system
</dependency>
</dependencies>
<dependenciesManager> # 子模块不继承, 继承时需要声明
<dependencies>
</dependenciesManager>
<build>
<plugins>
<plugin>
<groupId>
<artifactId>
</plugin>
</plugins>
</build>
插件
介绍
按顺序执行,完成maven生命周期
无配置时调默认插件
生命周期(lifecycle)顺序
clean # 清除target目录
resources # 复制resources下文件到target/classes
complie # 包含resources, 编译java下文件到target/classes
testResources # 复制test/resources下文件到target/test-classes
testCompile # 包含testResources, 编译test/java下文件到target/test-classes
test # 包含resources, compile, testResources, testCompile, test
package
jar # 打包class文件, 配置文件, 不打包lib
install
maven-clean-plugin
maven-resources-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>src/main/${deploy.env}/applicationContext.xml</directory>
<excludes>
<exclude>WEB-INF/*.*</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
<inherited></inherited>
</execution>
</executions>
</plugin>
maven-compiler-plugin
maven-surefire-plugin # 对应test, 单元测试
maven-dependency-plugin # 打包lib
maven-jar-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.xxx.xxxService</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin> # 单独打包lib
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
maven-assembly-plugin # 打包lib, 有bug缺失spring xds文件, 同级jar会冲突
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.xxx.xxxService</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
maven-shade-plugin # 打包lib, 同级jar会冲突, 提示SF,DSA,RSA冲突,排除META-INF相关文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.tooling</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.xxx.xxxInvoke</mainClass>
</transformer>
</transformers>
<minimizeJar>true</minimizeJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
</configuration>
</execution>
</executions>
</plugin>
maven-install-plugin
spring-boot-maven-plugin
gradle-maven-plugin
protobuf-maven-plugin
build-helper-maven-plugin # 用于指定自定义目录
dockerfile-maven-plugin # root用户直接打包到docker images
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<configuration>
<repository>${project.artifactId}</repository>
<contextDirectory>./</contextDirectory>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>mqtt/target/*.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
./Dockerfile
FROM primetoninc/jdk:1.8
#ADD mqtt/target/*.jar app.jar
ARG JAR_FILE
COPY ${JAR_FILE} /opt/app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
mvn package dockerfile:build
方案
新项目安装
mvn clean install -DskipTests
mvn install -rf :模块名 -DskipTests # 指定模块开始
ojdbc14本地加载
# oracle是收费的,所以不能直接下载到驱动
o-> mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=ojdbc14-10.2.0.4.0.jar
o-> 把ojdbc14-10.2.0.4.0.jar复制到目录下: /home/outrun/.m2/repository/com/oracle/ojdbc14/10.2.0.4.0/
o-> /home/outrun/.m2/repository/com/oracle/ojdbc14/下会产生maven-metadata-local.xml文件存放maven引入依赖
o-> 项目中引入本地依赖
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
代理
复制$M2_HOME/conf/settings.xml到.m2/
settings.xml
<proxies>
<proxy>
<id>my-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>localhost</host>
<port>8123</port>
<!--
<username>admin</username>
<password>admin</password>
<nonProxyHosts>repository.mycom.com|*.google.com</nonProxyHosts>
-->
</proxy>
</proxies>
代码
#
github
bitBucket
gitee.com
# 码云
sentry
# 产品error tracing
gerrit
# code review 工具
coverallx
# github上项目的coverage测试覆盖率条目由它提供服务
circleCI
# github代码测试
travis-ci
# 利用github hook测试
fitness
# 自动单元测试
coverity
# 代码静态检查
www.webpagetest.org
# 测试网站性能
GitLab
#
仓库
#
Nexus
#
# maven, npm, go, docker, yum等
JFrog
#
# 全语言二进制仓库
CMDB
#
# configuration management database
Bt-Panel
#
# 宝塔面板,服务器运维面板
JumpServer
#
# 跳板机
功能
#
认证
#
SSH(Secure Shell)
#
特点
1.加密和压缩:http与ftp都是明文传输
2.ssh有很多子协议,实现不同功能:如sftp,scp
3.端口:22
配置
修改ip地址:
有虚拟机时:先设置虚拟机的连接方式是桥接
图形界面直接修改(或重启到root用户的图形界面修改)
命令修改
/etc/network/interfaces
auto eth0
iface eth0 inet static
address ip地址
netmask 子网掩码
gateway 网关
broadcast 广播地址
dns-nameservers DNS
重启网络服务:/etc/init.d/networking restart,
/etc/ssh/sshd_config
PasswordAuthentication no
# 关闭密码登录
PermitRootLogin no
# 关闭root登录
命令
ssh outrun@10.1.1.1
# -p 22 端口
# PubkeyAuthentication=no 不公钥登录
免登录
ssh-keygen -t rsa
# 一直回车,生成~/.ssh/id_rsa 与 id_rsa.pub两个文件
ssh-copy-id -i 192.168.56.11
# 这样就可以免登录访问192.168.56.11了
## ssh-copy-id -i localhost 免登录自己
或
把A机下的1中生成的id_rsa.pub的内容复制到B机下,在B机的.ssh/authorized_keys文件里,这样可以多个主机对B机进行免登录
sshpass
介绍
命令行密码登录
命令
sshpass -p zlycare@123 ssh zlycare@10.162.201.58
OpenVPN
#
安装
yum install openvpn easy-rsa lzo lzo-devel openssl openssl-devel -y
或编译安装openvpn
mkdir –p /usr/local/openvpn && cd /usr/local/openvpn/
./configure --with-lzo-headers=/usr/local/include --with-lzo-lib=/usr/local/lib
make
make install
生成证书
目标
服务器: ca.crt、server.key、server.crt、dh.pem
客户端: ca.crt、client.key、client.crt
查找模板
find / -name "vars.example" -type f # vars文件
find / -name "server.conf" -type f # server.conf文件
进入目录easy-rsa
cd /usr/local/openvpn/openvpn-2.0.9/easy-rsa/2.0/
cd /usr/share/easy-rsa/3.0.3/
设置vars
cp vars.example vars
vars文件
set_var KEY_COUNTRY="CN"
set_var KEY_PROVINCE="BJ"
set_var KEY_CITY="Beijing"
set_var KEY_ORG="linux"
set_var KEY_EMAIL="test@example.net"
# set_var EASYRSA_NS_SUPPORT "yes" # 客户端配置ns-cert-type server时配置
生成server文件
# 配置文件在/etc/easy-rsa或 .../openvpn/easy-rsa
rm -rf pki
./easyrsa init-pki # pki目录
./easyrsa build-ca nopass # 回车过, 生成ca.crt
./easyrsa gen-req vpnserver nopass # 回车过, 生成vpnserver.key, vpnserver.req(密钥对、证书请求文件)
./easyrsa sign server vpnserver # 生成vpnserver.crt(ca.crt与vpnserver.req签名)
./easyrsa gen-dh # 生成dh.pem(diffie hellman)
cp -r ../3.0.3/ ~
生成client文件
rm -rf pki
./easyrsa init-pki
./easyrsa gen-req client nopass # 回车过, 生成client.key, client.req
cp pki/reqs/client.req ~/3.0.3/pki/reqs/
cp pki/private/client.key ~/3.0.3/pki/private/
cd ~/3.0.3
./easyrsa sign client client # 生成client.crt(ca.crt与client.req签名)
移动server文件到openvpn配置目录
cp pki/{ca.crt,dh.pem} /etc/openvpn/server/
cp pki/private/vpnserver.key /etc/openvpn/server/
cp pki/issued/vpnserver.crt /etc/openvpn/server/
cp server.conf /etc/openvpn/server
下载client文件
pki/ca.crt
pki/private/client.key
pki/issued/client.crt
server.conf
cp -p ../../sample-config-files/server.conf /etc/openvpn
o-> server.conf
;local 172.21.223.196
port 1194
proto udp
dev tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key
dh /etc/openvpn/dh1024.pem
server 192.168.200.0 255.255.255.0
ifconfig-pool-persist ipp.txt
;client-config-dir "C:\\Program Files\\OpenVPN\\ccd" # 支持TLS client
push "route 0.0.0.0 0.0.0.0"
keepalive 10 120
cipher AES-256-CBC
comp-lzo # 减少带宽
persist-key
persist-tun
status openvpn-status.log
log /var/log/openvpn.log
verb 3
explicit-exit-notify 1 # 只能udp协议使用
sudo openvpn --config /etc/openvpn/server.conf --daemon
netstat -anulp | grep 1194
linux配置
iptables
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1 # 开启路由转发
sysctl -p
iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -j SNAT --to-source 45.55.56.16
firewall
firewall-cmd --add-service=openvpn --zone=public --permanent
firewall-cmd --reload
client配置
o-> client.ovpn
client
dev tun
proto udp
remote 45.55.56.16 1194
resolv-retry infinite
nobind
ca ca.crt
cert client.crt
key client.key
;ns-cert-type server
cipher AES-256-CBC
comp-lzo
persist-key
persist-tun
verb 3
mute 20
sudo openvpn --config client.ovpn
# --user outrun
# --auth-nocache
# askpass pass.txt 放密码到文件
o-> 免密码连接
#!/usr/bin/expect -f
spawn sudo openvpn --config /home/outrun/.openvpn/meiqia-vpn-ldap.ovpn
# match_max 100000
expect "*?assword*:*"
send -- "1234\n"
expect "*Username:*"
send -- "outrun\n"
expect "*Password:*"
expect "#"
案例
代理http上网 # tcp连接国内服务器会被reset
server.conf
dev tap
proto tcp
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 114.114.114.114"
push "dhcp-option DNS 8.8.8.8"
client-to-client
;explicit-exit-notify 1
client.ovpn
dev tap
proto tcp
改成用户名密码认证
服务器
server.conf
auth-user-pass-verify /etc/openvpn/server/checkpsw.sh via-env
verify-client-cert none
username-as-common-name
tls-auth /etc/openvpn/server/ta.key 0
script-security 3
checkpsw.sh
#!/bin/sh
PASSFILE="/etc/openvpn/server/user/psw-file"
LOG_FILE="/etc/openvpn/server/log/openvpn-password.log"
TIME_STAMP=`date "+%Y-%m-%d %T"`
if [ ! -r "${PASSFILE}" ]; then
echo "${TIME_STAMP}: Could not open password file \"${PASSFILE}\" for reading." >> ${LOG_FILE}
exit 1
fi
CORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}' ${PASSFILE}`
if [ "${CORRECT_PASSWORD}" = "" ]; then
echo "${TIME_STAMP}: User does not exist: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
exit 1
fi
if [ "${password}" = "${CORRECT_PASSWORD}" ]; then
echo "${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE}
exit 0
fi
echo "${TIME_STAMP}: Incorrect password: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
exit 1
chmod 645 checkpsw.sh
mkdir user
mkdir log
user/psw-file
outrun asdfasdf
openvpn --genkey --secret ta.key
客户端
下载ta.key
client.ovpn
;cert client.crt
;key client.key
auth-user-pass
tls-auth ta.key 1
Shadowsocks
#
安装
sudo yum -y install epel-release
sudo yum -y install python-pip
sudo pip install --upgrade pip
sudo pip install shadowsocks
服务器
server.json
{
"server":"0.0.0.0",
"server_port":443,
"local_address":"127.0.0.1",
"local_port":1080,
"password":"asdfasdf",
"timeout":300,
"method":"aes-256-cfb",
"fast_open":false,
"workers":5
}
ssserver -c server.json -d start
中继代理
client.json
{
"server":"47.74.230.238",
"server_port":443,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"asdfasdf",
"timeout":300,
"method":"aes-256-cfb"
}
sslocal -c client.json
协议转换
安装polipo
/etc/polipo/config
logSyslog = false
logFile = "/var/log/polipo/polipo.log"
socksParentProxy = "127.0.0.1:1080"
socksProxyType = socks5
chunkHighMark = 50331648
objectHighMark = 16384
serverMaxSlots = 64
serverSlots = 16
serverSlots1 = 32
proxyAddress = "0.0.0.0"
proxyPort = 8123
polipo -c /etc/polipo/config
客户端
switchOmega
SOCKS5 127.0.0.1 1080
http 127.0.0.1 8123
环境变量
export http_proxy=http://127.0.0.1:8123
export https_proxy=http://127.0.0.1:8123
OpenDJ
#
介绍
open source directory services for the java platform
LDAPv3的认证系统
OpenSSL
#
使用
openssl genrsa -out server.key 1024
# 生成私钥
openssl rsa -in server.key -pubout -out server.pem
# 生成公钥
openssl req -new -key ca.key -out ca.csr
# 通过私钥生成csr(certificate signing request, 证书签名请求)文件
openssl x509 -req -in ca.csr -signkey ca.key -out ca.crt
# 通过csr生成自签名ca证书,用来颁发证书
openssl x509 -req -CA ca.crt -CAkey ca.key -CAcreateserial -in server.csr -out server.crt
# 向自己的ca机构申请签名,需要ca.crt, ca.key, server.csr, 得到带有CA签名证书。用来给客户端验证公钥属于该域名
# 客户端发起安全连接前会获取服务器端的证书, 并通过ca证书验证服务器端证书的真伪,并对服务器名称, IP地址等进行验证
openssl s_client -connect 127.0.0.1:8000
# 测试证书是否正常
应用控制
#
Forever
#
openvpn --config openvpn.conf
# 连接
## --user outrun
## --auth-nocache
# askpass pass.txt 放密码到文件
Supervisor
#
介绍
监视重启
命令
supervisord
# 启动后台服务
supervisorctl
status # 查看所有
update # 重载配置
reload #
start
stop
restart
start all
stop all
restart all
配置
/etc/supervisor/supervisord.conf
[include]
files = /etc/supervisor/conf.d/*.conf
/etc/supervisor/conf.d/app.conf
[program:tri]
command=/data/apps/tri/bin/tri --config /data/apps/tri/conf/config.tri.toml
directory=/data/apps/tri
autostart=true
autorestart=true
startsecs=10
startretries=3
stdout_logfile=/data/logs/supervisor/tri/access.log
stdout_logfile_maxbytes=100MB
stdout_logfile_backups=20
stderr_logfile=/data/logs/supervisor/tri/stderr.log
stderr_logfile_maxbytes=100MB
stderr_logfile_backups=2
environment=ASPNETCORE_ENVIRONMENT=Production # 环境变量
user=root # 执行的用户
PM2
#
介绍
带有负载均衡功能的node应用进程管理器
内建负载均衡(使用node cluster模块)
后台运行
热重载
停止不稳定进程,如无限循环
安装
npm install -g pm2
命令
pm2 start app.js
pm2 stop
pm2 restart
pm2 status
pm2 info 1
pm2 logs 1
个人操作
#
Ngrok
#
# 内网穿透
VSFTP
#
介绍
默认端口21
用户
匿名用户
默认为ftp或anonymous
目录在/var/ftp
只能下载不能上传
本地用户
用户名和密码与本地用户相同
目录为该用户的登录目录
虚拟用户
文件配置名字和密码
要生成认证文件
文件
/usr/sbin/vsftpd # 主程序
/etc
/rc.d/init.d/vsftpd # initd启动脚本
/vsftpd.conf # 主配置
/vsftpd.ftpusers # 用户黑名单, 一行一名字
/vsftpd.user_list # 用户黑/白名单, 一行一名字
/pam.d/vsftpd # pam认证文件
/var
/ftp # 匿名用户主目录
/ftp/pub # 匿名用户的下载目录
默认用户与组
用户
adduser -d /var/ftp -g ftp -s /sbin/nologin ftp
组
ftp
命令
systemctl start vsftpd
最小可用配置
/etc/vsftpd.conf
listen=YES
local_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
pam_service_name=vsftpd
seccomp_sandbox=NO
# Enable upload by local user.
write_enable=YES
# Enable read by anonymous user (without username and password).
secure_chroot_dir=/var/empty
anonymous_enable=YES
anon_root=/srv/ftp
no_anon_password=YES
使用
/etc/vsftpd.conf
anonymous_enable=YES # 允许匿名用户
local_enable=YES # linux用户可登录, 虚拟用户可登录
write_enable=YES # 可写
local_umask=022 # user文件权限, 默认077
dirmessage_enable=YES # 显示目录信息
xferlog_enable=NO # 记录上传/下载日志
connect_from_port_20=YES # 确保用20端口传输
ls_recurse_enable=NO # 允许ls -R
allow_writeable_chroot=NO
listen=NO
listen_ipv6=YES # 包含ipv4,和listen只能有一个YES
pam_service_name=vsftpd
local_root=/home/outrun/Downloads # linux用户默认目录。会先登录到用户目录,再切换到这里
ftp_username=ftp # 匿名用户名,默认ftp
tcp_wrappers=NO # 结合tcp_wrapper限制ip登录
/etc
/hosts.allow # 允许地址
/hosts.deny # 拒绝地址
useradd -d /home/ftp ftp
mkdir /home/ftp && chown ftp /home/ftp && chgrp ftp /home/ftp
systemctl restart vsftpd
打开tcp, udp端口21, 20
用户
匿名登录
/etc/vsftpd/vsftpd.conf
anonymous_enable=YES
anon_root=/home/outrun/Downloads # 匿名用户默认目录
anon_upload_enable=YES # 匿名可写,要求write_enable=YES
anon_mkdir_write_enable=YES # 匿名创建文件夹
anon_other_write_enable=YES # 匿名可删除、重命名
anon_umask=000 # 如创建077文件,anon_umask=022时,则为055
chmod 777 dir1
本地用户登录
/etc/vsftpd/vsftpd.conf
anonymous_enable=NO
userlist_enable=YES
userlist_deny=YES # YES时user_list为黑名单
userlist_file=/etc/vsftpd/user_list
chroot_local_user=YES # 默认可以chroot到用户home。YES时, chroot_list_file指定黑名单
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_file # 名单用户只能访问自己home
allow_writeable_chroot=YES # 不限制chroot目录可写
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
注释root
虚拟用户
SimpleHTTPServer
#
pythom -m SimpleHTTPServer 8080
Pyshark
#
介绍
包嗅探
项目用工具
#
知识库
#
confluence
# 收费
NextCloud
# 私有网盘
tiddlyWiki
# 可在线定义目录树
github
# 用wiki页面
gitbook
mediaWiki
# 维基百科样式,只有单页目录树
dokuWiki
# 只有网站地图
xwiki
# 目录树, acl
语雀
hdwiki
# 百科, 已停更
notion
# 任务管理
minidoc
# 原smartWiki(php), 改成golang开发的minidoc
有道云笔记
幕布
石墨
etherpad.org
# 在线协作无缝编辑
dropbox
# 文档协作
坚果云
# 文档协作
网盘
#
google drive
百度云
沟通
#
Mattermost
# 开源
team
# 微软, 聊天
slack
# 聊天
hipChat
# Atlassian, 聊天
企业微信
钉钉
倍洽
飞书
瀑布IM
邮件
#
gmail
阿里云邮箱
腾讯企业邮
zoho
网易企业邮
原型
#
zeplin
# 设计和前端协同工具
蓝湖
# 免费
团队协作
#
jira
# 进度管理跟踪, 敏捷开发
microsoft Project
# 瀑布式开发
rational
# IBM, 进度管理
teambition
# 进度管理
basecamp
# 进度管理
testlink
# 测试收集, 进度管理
redmine
# 开源, ror开发, 项目管理, 把成员、任务、文档、讨论等资源整合在一起。支持git, svn, cvs等
youtrack
# jetbrains, 项目管理
禅道
# 项目管理, 开源
trac
# wiki, issue
tapd
# 腾讯项目管理
优势
打通企业微信
功能
worktile
# microsoft项目管理
notion
明道云
云之家
eteams
今目标
tower
masterlab
# 开源
openProject
# 开源
peerProject
# 开源
trello
# 进度管理
代码管理
#
github
gitee
coding
bitbucket
gitea
# 开源
gitlab
gogs
# 开源
测试
#
semaphore
codeClimate
文档
#
swagger
镜像
#
harbor
nexus
部署
#
drone
Travis-CI
CircleCI
GitLab-CI
集群
#
kuboard
prometheus
grafana
zabbix
日志
#
ElasticStack