diff --git a/details/使用truenasseeker.py脚本自动扫描nfs服务并挂载.md b/details/使用truenasseeker.py脚本自动扫描nfs服务并挂载.md index 214722f..38d3619 100644 --- a/details/使用truenasseeker.py脚本自动扫描nfs服务并挂载.md +++ b/details/使用truenasseeker.py脚本自动扫描nfs服务并挂载.md @@ -13,28 +13,28 @@ apt install -y nmap pip install scapy python-nmap pyfunctional ``` -3.将truenasseeker.py脚本拷贝至`/opt/aquar/src`路径下。 +3.将[truenasseeker.py](../files/truenasseeker.py)脚本拷贝至`/opt/aquar/src`路径下。 你可以尝试执行`python3 /opt/aquar/src/truenasseeker.py`命令运行一次看是否会出错,正常情况下它会输出"truenas seeker is no need to do anything." 4.创建`/usr/lib/systemd/system/trunas-scan.service`配置文件,配置内容如下: ``` -# [Unit] -# Description=scan local network for truenas -# After=docker.service opt-aquar-storages-aquarpool.mount -# -# [Service] -# Type=simple -# User=root -# ExecStart=python3 /opt/aquar/src/truenasseeker.py -# -# [Install] -# WantedBy=multi-user.target +[Unit] +Description=scan local network for truenas +After=docker.service opt-aquar-storages-aquarpool.mount + +[Service] +Type=simple +User=root +ExecStart=python3 /opt/aquar/src/truenasseeker.py + +[Install] +WantedBy=multi-user.target ``` 5.执行`systemctl daemon-reload`重载系统服务。 6.执行`systemctl enable trunas-scan.service`将脚本设置为开机启动。 -7.执行`systemctl status trunas-scan.service`查看服务状态是否为enabled。如果是,则代表脚本正常部署了。 \ No newline at end of file +7.执行`systemctl status trunas-scan.service`查看服务在loaded那一行是否为enabled。如果是,则代表脚本正常部署了。 \ No newline at end of file diff --git a/details/把pve配置成DHCP.md b/details/把pve配置成DHCP.md index 75ef596..c8eb6a4 100644 --- a/details/把pve配置成DHCP.md +++ b/details/把pve配置成DHCP.md @@ -35,6 +35,9 @@ iface enp0s31f6 inet manual auto vmbr0 iface vmbr0 inet dhcp +bridge-ports enp0s31f6 + bridge-stp off + bridge-fd 0 iface enp3s0 inet manual ``` \ No newline at end of file diff --git a/files/ipupdater.py b/files/ipupdater.py index b04b3f4..9e52dfa 100644 --- a/files/ipupdater.py +++ b/files/ipupdater.py @@ -1,8 +1,5 @@ #! /usr/bin/env python # vim: set fenc=utf8 ts=4 sw=4 et : -# -------------环境安装---------------- -# apt-get install python3-netifaces -# # -----------/lib/systemd/system/ipupdater.service systemd配置--------------- # [Unit] # Description=update ip config when system start @@ -17,25 +14,36 @@ # WantedBy=multi-user.target -import netifaces as ni -import os -import getopt +# import netifaces as ni +# import os +# import getopt import socket import shutil import re -from ipaddress import IPv4Network -import time +# from ipaddress import IPv4Network +# import time NTERFACE_PATH = '/etc/network/interfaces' HOSTS_PATH = '/etc/hosts' ISSUE_PATH = '/etc/issue' def getRealNetInfo(): - defaultGateWay, defaultInterface = ni.gateways()['default'][ni.AF_INET] - addressInfo = ni.ifaddresses(defaultInterface)[ni.AF_INET][0] - ip = addressInfo['addr'] - maskBits = IPv4Network('0.0.0.0/'+addressInfo['netmask']).prefixlen - return ip, defaultGateWay, maskBits + # defaultGateWay, defaultInterface = ni.gateways()['default'][ni.AF_INET] + # addressInfo = ni.ifaddresses(defaultInterface)[ni.AF_INET][0] + # ip = addressInfo['addr'] + # maskBits = IPv4Network('0.0.0.0/'+addressInfo['netmask']).prefixlen + # return ip, defaultGateWay, maskBits + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.settimeout(0) + try: + # doesn't even have to be reachable + s.connect(('10.254.254.254', 1)) + ip = s.getsockname()[0] + except Exception: + ip = '127.0.0.1' + finally: + s.close() + return ip def checkIfIpChanged(ip, defaultGateWay): shutil.copy(INTERFACE_PATH, INTERFACE_PATH + '.bak') @@ -79,14 +87,14 @@ def updateHosts(ip): shutil.copy(HOSTS_PATH, HOSTS_PATH + '.bak') targetFile = open(HOSTS_PATH, "r+") configText = targetFile.read() - splitRes = re.split("\n.+ peng.py peng\n", configText) + splitRes = re.split("\n.+ pve\n", configText) print(splitRes) prepart = splitRes[0] postpart = splitRes[1] - updateConfig = "\n%s peng.py peng\n" % ip - print("host updateConfig: %s" % updateConfig) + updateConfig = "\n%s pve\n" % ip + print("----host updateConfig----\n %s" % updateConfig) newConifg = prepart + updateConfig+ postpart - print("host newConifg:%s" % newConifg) + print("----host newConifg----\n%s" % newConifg) targetFile.seek(0) targetFile.write(newConifg) @@ -101,9 +109,9 @@ def updateIssue(ip): prepart = splitRes[0] postpart = splitRes[1] updateConfig = " https://%s:8006/\n" % ip - print("issue updateConfig: %s" % updateConfig) + print("----issue updateConfig----\n%s" % updateConfig) newConifg = prepart + updateConfig+ postpart - print("issue newConifg:%s" % newConifg) + print("----issue newConifg----\n%s" % newConifg) targetFile.seek(0) targetFile.write(newConifg) @@ -113,8 +121,8 @@ def updateIssue(ip): if __name__ == "__main__": print('ipupdater start.') - ip, defaultGateWay, maskBits = getRealNetInfo() - print("ip:%s defaultGateWay: %s" % (ip,defaultGateWay)) + ip = getRealNetInfo() + print("ip:%s" % ip) updateHosts(ip) updateIssue(ip) # if checkIfIpChanged(ip, defaultGateWay):