2023年11月

删除镜像

docker rmi $(docker images | grep -E 'harbor.xxx.com/(qa|dev|prod)/' | awk -v OFS=":" '{print $1,$2}')

删除k8s中Evicted状态的pod

kubectl get po -A | grep 'Evicted' | awk 'NR>0 {print "kubectl delete po -n " $1,$2}' | bash

查看docker space

# overlay2无thin pool,devicemapper有thin pool。
docker info | grep Space

查看镜像和容器的空间

docker system df -v 或 docker system df -v | grep GB

方法一

test.py内容
mm="%s,%s,%s"%("aabbcc1",333,"cccc")
print(mm)

def retobj2 = "/usr/bin/python /data/script/test.py".execute().text.readLines()
retobj2.each{println it}

def retobj2 = "/usr/bin/python /tmp/11.py".execute().text.readLines()
return retobj2

方法二

test.py内容
jj = json.dumps({"name":"fulei.sssyang","age":"18"})
print(jj)

def respText = "/usr/local/python3/bin/python3 /data/script/py/test.py".execute().text
def slurper = new groovy.json.JsonSlurper() 
def branchs = slurper.parseText(respText) //parseText将json字符串转换为Map对象;JsonOutput类用于将Groovy对象转换为JSON字符串

方法三

python返回\n换行的字符串

"".execute().text.readLines()

方法4)
def html = "http://xxxxxx".toURL().text
def list = html.readLines()

升级pip到最新的版本

python -m pip install --upgrade pip
或
python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip

镜像地址

清华镜像源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

豆瓣镜像源
pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com some-package

阿里云镜像源
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com some-package

中国科学技术大学镜像源
pip install -i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host=pypi.mirrors.ustc.edu.cn some-package

settings.xml

<server>
  <id>nexus-releases</id>
  <username>admin</username>
  <password>你的密码</password>
</server>
<server>
  <id>nexus-snapshots</id>
  <username>admin</username>
  <password>你的密码</password>
</server>

<repositories>
    <repository>
        <id>nexus</id>
        <name>Nexus Repository</name>
        <url>http://172.16.3.100:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>nexus</id>
        <name>Nexus Plugin Repository</name>
        <url>http://172.16.3.100:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>

配置上传jar包项目的pom.xml

<distributionManagement>  
  <repository>  
    <id>nexus-releases</id>  
    <name>Nexus Release Repository</name>  
    <url>http://172.16.3.100:8081/repository/maven-releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>nexus-snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://172.16.3.100:8081/repository/maven-snapshots/</url>  
  </snapshotRepository>  
</distributionManagement>

上传jar包到nexus

mvn deploy:deploy-file
  -DgroupId=坐标
  -DartifactId=坐标
  -Dversion=版本
  -Dpackaging=jar
  -Dfile=jar本地路径
  -Durl=http://172.16.3.100:8081/repository/3rdparty/
  -DrepositoryId=nexus-releases

docker启动nexus

cd /opt && mkdir nexus-data && chmod 200 nexus-data && chown nexus nexus-data
docker run -d -p 8081:8081 --name nexus --ulimit nofile=65536:65536 -v /opt/nexus-data:/nexus-data sonatype/nexus3:3.24.0

docker run -dti \
        --net=host \
        --name=nexus \
        --privileged=true \
        --restart=always \
        --ulimit nofile=65536:65536 \
        --ulimit memlock=-1 \
        --memory=16G \
        --memory-swap=-1 \
        --cpuset-cpus='1-7' \
        -e INSTALL4J_ADD_VM_PARAMS="-Xms4g -Xmx4g -XX:MaxDirectMemorySize=8g" \
        -v /etc/localtime:/etc/localtime \
        -v /data/nexus:/nexus-data \
        sonatype/nexus3:latest

查询是否安装tcpdump

rpm -ql tcpdump

安装tcpdump

yum install tcpdump

指定网卡信息

tcpdump -i eth0 udp port 694 -n

指定端口

tcpdump -i eth0 tcp port 8088 -n 
tcpdump -i eth0 port 8080 -vvne -w /tmp/tcpdump.pcap

指定抓包数量

tcpdump -i eth0 port 8088 -c 3 -t -w /tmp/tcpdump.pcap

两台主机之间通信抓包

tcpdump host 192.168.0.204 and 192.168.0.205

根据来源和目标地址抓包

tcpdump -i eth0 src host 192.168.0.235 # src指定来源
tcpdump -i eth0 dst net 192.168.0.0/24 # dst指定目标地址,net指定网段
tcpdump tcp -i eth1 -t -s 0 -c 100 and dst port ! 22 and src net 192.168.1.0/24 -w ./target.cap

在K8S宿主机上抓包

docker ps | grep xxx 
docker inspect 容器ID | grep Pid 
nsenter -t Pid值 -n tcpdump -i eth0 host 127.0.0.1 and port 80 -vvne -w /tmp/tcpdump.pcap 

参数:

(1)tcp: ip icmp arp rarp 和 tcp、udp、icmp这些选项等都要放到第一个参数的位置,用来过滤数据报的类型
(2)-i eth1 : 只抓经过接口eth1的包
(3)-t : 不显示时间戳
(4)-s 0 : 抓取数据包时默认抓取长度为68字节。加上-S 0 后可以抓到完整的数据包
(5)-c 100 : 只抓取100个数据包
(6)dst port ! 22 : 不抓取目标端口是22的数据包
(7)src net 192.168.1.0/24 : 数据包的源网络地址为192.168.1.0/24
(8)-w ./target.cap : 保存成cap文件,方便用ethereal(即wireshark)分析