linux 常用

查看filename中含有abc所在行后4行内容

 

cat filename | grep abc -A4

 

查看filename中含有abc所在行前4行内容

cat filename  | grep abc  -B4

 

2种方法打印匹配行的前后5行

grep -5 '关键字' 文件名
grep -C 5 '关键字' 文件名




jq案例:
docker inpect xxxxx | jq ".[0].Mounts[1]"



docker java 日志:
ls -R /var/lib/docker/volumes/*/_data/*.log



 

docker打印的formatter

例如docker images:

docker images --format "{{.ID}} {{.Repository}} {{.Size}}"
6327bd7315cf rancher/rancher-agent 280MB
3ce97e5c7e3a rancher/hyperkube 1.05GB
89a4afe7e17e rancher/rke-tools 130MB
2b37f252629b rancher/nginx-ingress-controller 569MB
2817cb463960 rancher/kube-api-auth 149MB
eb516548c180 rancher/coredns-coredns 40.3MB
a89b45f36d5e rancher/calico-node 75.9MB
d531d047a4e2 rancher/calico-cni 75.4MB
643c21638c1c rancher/coreos-etcd 39.5MB
33813c948942 rancher/cluster-proportional-autoscaler 45.8MB
b5af743e5984 rancher/nginx-ingress-controller-defaultbackend 5.13MB
61a0c90da56e rancher/metrics-server 40.8MB
da86e6ba6ca1 rancher/pause 742kB

 

root@rancherm2:~# docker images --format "{{.Repository}}:{{.Tag}}"
rancher/rancher-agent:v2.2.7
rancher/hyperkube:v1.14.5-rancher1
rancher/rke-tools:v0.1.40
rancher/nginx-ingress-controller:0.21.0-rancher3
rancher/kube-api-auth:v0.1.3
rancher/coredns-coredns:1.3.1
rancher/calico-node:v3.4.0
rancher/calico-cni:v3.4.0
rancher/coreos-etcd:v3.3.10-rancher1
rancher/cluster-proportional-autoscaler:1.3.0
rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1
rancher/metrics-server:v0.3.1
rancher/pause:3.1

 

保存上面输出为txt

for i in `cat txt`;do docker tag $i `echo $i | sed "s#rancher#registry.cn-shanghai.aliyuncs.com/alexhjl#"`;done

这样就把rancher/pause:3.1 改成了registry.cn-shanghai.aliyuncs.com/alexhjl/pause:3.1

验证一下:

docker images --format "{{.Repository}}:{{.Tag}}"| grep regis
registry.cn-shanghai.aliyuncs.com/alexhjl/rancher-agent:v2.2.7
registry.cn-shanghai.aliyuncs.com/alexhjl/hyperkube:v1.14.5-rancher1
registry.cn-shanghai.aliyuncs.com/alexhjl/rke-tools:v0.1.40
registry.cn-shanghai.aliyuncs.com/alexhjl/nginx-ingress-controller:0.21.0-rancher3
registry.cn-shanghai.aliyuncs.com/alexhjl/kube-api-auth:v0.1.3
registry.cn-shanghai.aliyuncs.com/alexhjl/coredns-coredns:1.3.1
registry.cn-shanghai.aliyuncs.com/alexhjl/calico-node:v3.4.0
registry.cn-shanghai.aliyuncs.com/alexhjl/calico-cni:v3.4.0
registry.cn-shanghai.aliyuncs.com/alexhjl/coreos-etcd:v3.3.10-rancher1
registry.cn-shanghai.aliyuncs.com/alexhjl/cluster-proportional-autoscaler:1.3.0
registry.cn-shanghai.aliyuncs.com/alexhjl/nginx-ingress-controller-defaultbackend:1.5-rancher1
registry.cn-shanghai.aliyuncs.com/alexhjl/metrics-server:v0.3.1
registry.cn-shanghai.aliyuncs.com/alexhjl/pause:3.1

 

 

上传到阿里云:

for i in `docker images --format "{{.Repository}}:{{.Tag}}"| grep regis`;do docker push $i;done

 


 docker login --username=hi31790387@aliyun.com registry.cn-shanghai.aliyuncs.com 

 

从阿里云下载:

docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/rancher-agent:v2.2.7
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/hyperkube:v1.14.5-rancher1
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/rke-tools:v0.1.40
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/nginx-ingress-controller:0.21.0-rancher3
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/kube-api-auth:v0.1.3
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/coredns-coredns:1.3.1
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/calico-node:v3.4.0
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/calico-cni:v3.4.0
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/coreos-etcd:v3.3.10-rancher1
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/cluster-proportional-autoscaler:1.3.0
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/nginx-ingress-controller-defaultbackend:1.5-rancher1
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/metrics-server:v0.3.1
docker pull registry.cn-shanghai.aliyuncs.com/alexhjl/pause:3.1

 

重新打回rancher的tag

for i in `docker images --format "{{.Repository}}:{{.Tag}}"`;do docker tag $i `echo $i | sed "s#registry.cn-shanghai.aliyuncs.com/alexhjl#rancher#"`;done

 


 sed 更改zabbix

sed -i -e 's/Server=127.0.0.1/Server=10.10.10.80/g' -e 's/ServerActive=127.0.0.1/ServerActive=10.10.10.80/g' /etc/zabbix/zabbix_agentd.conf  && /etc/init.d/zabbix-agent restart

 


 ubuntu rc.local和自动挂接nfs

ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

 

echo "
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
" >> /etc/systemd/system/rc-local.service

 

 echo '#!/bin/bash

mount.nfs4 10.10.10.80:/nfs /log' >>/etc/rc.local

chmod +x /etc/rc.local

 


 

批量更改boss conf

sed -i 's/10.10.10.214:5432/10.10.10.33:5432/' */*.yaml

 


 

批量查找 k8s的host

for i in `kubectl get deployments -n only-appuat|cut -d " " -f1 | grep -v NAME`;do echo ;echo;echo $i;kubectl get deployments/$i -o json -n only-appuat|jq .spec.template.spec.hostAliases;done

 


 

快速找env

 for i in `kubectl get deployments -n bossprod|cut -d " " -f1 | grep -v NAME`;do echo ;echo;echo $i;kubectl get deployments/$i -o json -n bossprod|jq .spec.template.spec.containers[].env;done


 

快速缩减镜像

for i in `kubectl -n bossprod get deployments| cut -d " " -f1| grep -v NAME`;do kubectl -n bossprod scale --replicas=1 deployments/$i;done

 


 

快速换镜像

for i in `kubectl -n bossprod get deployments| cut -d " " -f1| grep -v NAME`;do kubectl -n bossprod set image deployment/$i $i=ubuntu:16.04;done

for i in `kubectl -n bossprod get deployments| cut -d " " -f1| grep -v NAME`;do kubectl -n bossprod set image deployment/$i $i=ubuntu:xenial;done


 快速查找文件挂载:

for z in `kubectl get ns |cut -d " " -f1 |grep -v Name`;do for i in `kubectl get deployments -n $z|cut -d " " -f1 | grep -v NAME`;do echo ;echo;echo $i;kubectl get deployments/$i -o json -n $z|jq .spec.template.spec.volumes[0].hostPath;done;done

 


 

查看哪些进程用了swap:

grep VmSwap /proc/*/status| sort -k2 -n

 

posted @ 2019-11-12 11:14  alexhe  阅读(188)  评论(0编辑  收藏  举报