stunnel

stunnel

客户端

client = yes
cert=D:\Soft\stunnel\config\stunnel.pem
[squid]
accept = 9002
connect = 10.0.0.3:8000

服务端

cert = /etc/stunnel/stunnel.pem
client = no
[squid]
accept = 8000
connect = 127.0.0.1:9000

证书

openssl genrsa -out key.pem 2048
openssl req -new -x509 -key key.pem -out cert.pem -days 36500
cat key.pem cert.pem >> /etc/stunnel/stunnel.pem
发布日期:
分类:Linux

Linux网络抓包

tcpdump

yum install -y tcpdump

截取本机(192.168.31.147)和主机114.114.114.114之间的数据

tcpdump -n -i eth0 host 192.168.31.147 and 114.114.114.114

截取全部进入服务器的数据

tcpdump -n -i eth0 dst 192.168.31.147

抓取全部进入服务器的TCP数据包

tcpdump -n -i eth0 dst 192.168.31.147 or 192.168.31.157 and tcp

发布日期:
分类:Linux

rsync通过ssh备份

备份

rsync -ave ssh /home/test/ root@192.168.1.100:/home/test/

发布日期:
分类:Linux

Socks服务器

socks


import socketserver, struct

class MyTCPHandler(socketserver.BaseRequestHandler):

def handle(self):

self.request.recv(3)

self.request.send(b'\x05\x00')

data = self.request.recv(200)

host = data[5:-2]
port = struct.unpack('H', data[-2:])[0]

self.request.send(b'\x05\x00\x00\x01\x00\x00\x00\x00\x10\x10')

buffer = []

while True:
d = self.request.recv(2048)
buffer.append(d)
if len(d) < 2048:
break

data = b''.join(buffer)

print(data)

self.request.sendall(b'HTTP/1.1 200 OK\r\n\r\nhello')

print(data)

if __name__ == "__main__":
HOST, PORT = "0.0.0.0", 9999
server = socketserver.ThreadingTCPServer((HOST, PORT), MyTCPHandler)
server.serve_forever()

发布日期:
分类:Linux

SS命令

安装

yum install iproute

查看网络连接统计

ss -s

 
查看所有打开的端口

ss -l

查看所有socket连接

ss -a
发布日期:
分类:Linux

KVM

CentOS 7

yum makecache

yum install -y kvm qemu-kvm libvirt python-virtinst

service libvirtd start

chkconfig libvirtd on

virsh iface-bridge eth0 br0

ethtool -K br0 gso off

ethtool -K br0 tso off

iptables -I INPUT -s 10.0.1.1 -p tcp -m tcp --dport 5900:5909 -j ACCEPT

# Create Linux KVM Host

virt-install --name doc --vcpus 1 --ram 1024 --cdrom /www/kvm/iso/CentOS-7-x86_64-Minimal-1810.iso --disk /www/kvm/disk/doc.img,size=10 --autostart --network bridge=br0 --noautoconsole --graphics vnc,listen=0.0.0.0,password=123456

# Create Win KVM Host

virt-install --name test --vcpus 2 --ram 4096 --cdrom /www/kvm/iso/cn_windows_7_ultimate_with_sp1_x64_dvd_u_677408.iso --disk /www/kvm/disk/test.img,size=100 --autostart --network bridge=br0 --noautoconsole --graphics vnc,listen=0.0.0.0,password=wenbor

###################################################

# 创建虚拟硬盘

qemu-img create -f qcow2 /www/vps/centos.qcow2 20G

# 快照

virsh snapshot-create-as centos centos_1

# 迁移

qemu-img create -f qcow2 /www/vps/redis.qcow2 100G

virsh migrate --live --persistent --undefinesource --verbose kvm qemu+ssh://192.168.1.10/system

# 压缩镜像文件

qemu-img convert -c -O qcow2 /www/old.qcow2 /www/new.qcow2

# 描述

virsh desc nginx2 --config --new-desc "IP : 1.1.1.1"

# 添加硬盘

virsh attach-disk win \
--source /www/kvm/image/win-disk.img \
--target vda \
--persistent

# 硬盘扩容
qemu-img resize test.img +100G

# 修改 CPU 数量

virsh setvcpus vps 2 --maximum --config
virsh setvcpu2 vps 2 --config

# 修改虚拟机内存

virsh setmaxmem vps 2097152 --config
virsh setmem vps 2097152--config

# 管理虚拟机文件

yum install -y libguestfs-tools

# 查看虚拟机文件

virt-cat -d vps /etc/hosts
virt-ls -d vps /etc
virt-copy-out -d vps /etc/hosts .
virt-copy-in -d vps /tmp/01 /tmp/02

CentOS 8

yum install -y qemu-kvm libvirt

systemctl start libvirtd

virsh iface-bridge enp3s0f0 br0

nmcli c add type bridge con-name br0 ifname br0 autoconnect yes

发布日期:
分类:Linux

MySQL主从复制

MySQL主从复制

 



FLUSH TABLES WITH READ LOCK;
UNLOCK TABLES;

server-id=1
log-bin=mysql-bin
binlog_do_db=test

GRANT REPLICATION SLAVE ON *.* to 'test'@'10.0.0.6' identified by '123456';

change master to master_host='10.0.0.7',
master_port=3306,
master_user='slave',
master_password='XeDUMevzoigvx3c7',
master_log_file='master-bin.000001',
master_log_pos=0;

start slave

show slave status

 
发布日期:
分类:Linux

CentOS自定义yum源


cp /etc/yum.repos.d/CentOS-Base.repo CentOS-Base.repo.bak
echo "[ftp]
name=CentOS-6 – LocalFTP
baseurl=ftp://192.168.150.252/
gpgcheck=1
enable=1
gpgkey=ftp://192.168.150.252/RPM-GPG-KEY-CentOS-6" &gt; /etc/yum.repos.d/CentOS-Base.repo

发布日期:
分类:Linux

CentOS设置代理

编辑/etc/yum.conf,在最后加入

# Proxy

proxy=http://username:password@proxy_ip:port/
发布日期:
分类:Linux