分类 linux 下的文章

方法一

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()

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)分析

查找

  • 方法一
    cp $(find . -type f -name '*.log') /tmp/log
  • 方法二
    find . -type f -name '*.log' | xargs -i cp {} /tmp/log
  • 方法三
    find . -type f -name '*.log' -exec cp {} /tmp/log \;
  • 方法四
    find . -type f -name '*.log' | xargs cp -t /tmp/log

查找后删除

  • 批量删除空文件夹
    find . -type d -empty -delete
  • 批量删除文件
    find . -type f -name '*.log' -delete
  • 批量强制删除文件夹
    find . -type d -name target -exec rm -rf {} \;

配置systemd服务

cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/usr/local/openresty/nginx/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

EOF

相关命令

systemctl daemon-reload
systemctl enable nginx
systemctl start nginx