首页
统计信息
友情链接
壁纸
Search
1
【更新】CommentToMail typecho2017&v4.1& Mailer三版本,支持php5.6/7,插件详解
158,185 阅读
2
【90APT开源免费】第三代哈弗H6、哈弗大狗、H6经典版、坦克300车机开启无线ADB、升级地图、安装软件全流程
18,076 阅读
3
CentOS 7安装bbr教程
12,923 阅读
4
纯小白10分钟变身linux建站高手?宝塔linux面板全体验
12,517 阅读
5
深信服超融合架构测试介绍
11,980 阅读
技术相关
ACG相关
胡言乱语
数码杂烩
登录
Search
标签搜索
进击的巨人
漫画
宝塔
php
typecho
diy
vps
折腾
动漫
优酷路由宝
ubuntu
路由器
QQ
KMS
王忘杰
累计撰写
287
篇文章
累计收到
179
条评论
首页
栏目
技术相关
ACG相关
胡言乱语
数码杂烩
页面
统计信息
友情链接
壁纸
搜索到
287
篇与
的结果
2023-08-08
0基础上手python3编程,多进程交换机配置自动备份软件
架构图 通过多线程telnet备份交换机配置并企业微信通知备份结果,生成log日志,速度飞快;配置文件均通过json定义预览 系统组成 由两个文件组成 swnetmiko.py swnetmiko.jsonnetmiko项目主页http://ktbyers.github.io/netmiko/如H3C交换机telnet代码为"device_type" : "hp_comware_telnet"代码 swnetmiko.pyfrom multiprocessing import Pool import os,json,time,requests,redis,multiprocessing,codecs from netmiko import ConnectHandler def get_config(): config = json.loads(open("swnetmiko.json", encoding='utf-8').read()) #读取配置文件 return config def post_weixin(stats): #发送微信 url = swnetmiko_config['weixin']['url'] body = { "msgtype": "news", "news": { "articles": [ { "title": swnetmiko_config['weixin']['title'], "description": tianqi()+yiyan()+stats, "url": swnetmiko_config['weixin']['url2'], "picurl": swnetmiko_config['weixin']['picurl'] } ] }} response = requests.post(url, json=body) print(response.text) print(response.status_code) def yiyan(): try: url = 'https://v1.hitokoto.cn/?c=d&c=k' response = requests.get(url) res = json.loads(response.text) text1 = res['hitokoto'] if res['from'] == None: text2 = "" else: text2 = res['from'] if res['from_who'] == None: text3 = "" else: text3 = res['from_who'] return text1 + " " + text2 + " " + text3 + "\n\n" except: return "一言API故障\n\n" def tianqi(): try: response2 = requests.get(swnetmiko_config['weatherapi']) data1 = json.loads(response2.text) data2 = json.dumps(data1['now']) data2 = json.loads(data2) data3 = "环境温度" + data2['temp'] + " 体感温度" + data2['feelsLike'] + " 天气状况 " + data2[ 'text'] + "\n风向 " + data2['windDir'] + " 风力等级" + data2['windScale'] + " 风速" + data2[ 'windSpeed'] + " 湿度" + data2['humidity'] + " 能见度" + data2['vis'] + "公里\n\n" return data3 except: return "天气API故障\n\n" dirpath = os.path.abspath('.') # 配置运行目录为当前目录 nowtime = time.strftime("%Y%m%d", time.localtime()) # 获取当前日期 try: os.mkdir(dirpath + "/" + nowtime) print("创建当日目录") except: print("当日目录已存在") nowdir = (dirpath + "/" + nowtime) print(nowdir) swnetmiko_config = get_config() # 读取配置文件 readredis = redis.Redis(connection_pool=redis.ConnectionPool(host=swnetmiko_config['redis']['host'], port=swnetmiko_config['redis']['port'], password=swnetmiko_config['redis']['password'], decode_responses=swnetmiko_config['redis']['decode'])) def sw_save(swconfig): #保存交换机配置 try: net_connect = ConnectHandler(**swconfig) output = net_connect.send_command("dis cu") print(swconfig['ip']+" OK") readredis.set(swconfig['ip'], "success") saveconfig = codecs.open(nowdir +'/'+ swconfig['ip'] +".conf", 'w+', encoding='utf-8') saveconfig.write(output) saveconfig.close() except: print(swconfig['ip'] + " NO") readredis.set(swconfig['ip'], "fail") if __name__ == '__main__': total = 0 fail = 0 weixindata = "" readredis.flushall() print("初始化redis数据库") #multiprocessing.freeze_support() #防止windows无限创建进程 multi_process = int(swnetmiko_config["multi-process"]) with Pool(multi_process) as p: p.map(sw_save, swnetmiko_config["data"]) for key in swnetmiko_config["data"]: if readredis.get(key["ip"]) == "fail": weixindata = weixindata + (key["ip"]+" 网络或账号密码错误\n") fail = fail + 1 total = total + 1 weixinpost = "总计巡检:"+str(total)+"台"+",故障交换机:"+str(fail)+"台\n"+weixindata post_weixin(weixinpost) flog = codecs.open(nowdir + "/" + nowtime + ".log", 'w', encoding='utf-8') flog.write(weixinpost) flog.close() print("程序执行完成")config.json{ "multi-process" : "4", "weatherapi" : "qweather.com申请api", "weixin" : { "url" : "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=用自己的", "title": "交换机巡检多线程版", "url2": "90apt.com", "picurl": "用自己的图片" }, "redis" : { "host": "自己的redis数据库IP", "port": "端口", "password": "密码", "decode": "True" }, "data" : [ {"device_type" : "hp_comware_telnet" , "ip" : "172.16.1.1" , "username" : "admin" , "password" : "passwd" , "port" : "23"}, {"device_type" : "hp_comware_telnet" , "ip" : "172.16.1.2" , "username" : "admin" , "password" : "passwd" , "port" : "23"} ] }配置定时任务crontab 每天早上7:30巡检30 7 * * * cd /root/swbackup/;python3.11 /root/swbackup/swnetmiko.py总结 简单
2023年08月08日
543 阅读
0 评论
4 点赞
2023-08-07
0基础上手python3编程,多进程监控摄像头巡检平台
架构图 读取配置文件;通过rtsp连接摄像头,保存一张截图;发送企业微信通知;记录log日志;多线程运行,速度起飞!预览 系统组成 rtsps.py rtsp.json代码 由于代码在windows平台运行,因此使用绝对路径C:\\jiankong\,文件放置在此目录下。rtsps.pyfrom multiprocessing import Pool,Value,Manager import cv2,os,json,time,requests,codecs,sys,redis,multiprocessing from func_timeout import func_set_timeout def get_config(): config = json.loads(open("C:\\jiankong\\rtsp.json", encoding='utf-8').read()) #读取配置文件 return config rtsp_config = get_config() path1 = ("C:\\jiankong\\") nowtime = time.strftime("%Y%m%d", time.localtime()) try: os.mkdir(path1 + "\\" + nowtime) print("创建当日目录") except: print("当日目录已存在") nowdir = (path1 + "\\" + nowtime) rtsp_config = get_config() readredis = redis.Redis(connection_pool=redis.ConnectionPool(host="IP地址", port="端口", password="密码",decode_responses=True)) #redis连接信息 #企业微信机器人 def post_weixin(stats): url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=用你自己的' body = { "msgtype": "news", "news": { "articles": [ { "title": "监控摄像头自动巡检多进程版", "description": stats, "url": "90apt.com", "picurl": "https://www.hikvision.com/content/dam/hikvision/cn/product/network-camera/fixed-ipc/%E7%BB%8F%E9%94%80%E7%B3%BB%E5%88%97/%E7%BB%8F%E9%94%80%E7%B3%BB%E5%88%97%E5%AF%BC%E8%88%AA%E7%9B%AE%E5%BD%95.jpg" } ] }} response = requests.post(url, json=body) print(response.text) print(response.status_code) @func_set_timeout(5) #连接失败超时时间5秒 def linkvideo(link): video = cv2.VideoCapture(link) return video def dayin(rtspconfig): video1 = "rtsp://" + rtspconfig['name'] + ":" + rtspconfig['password'] + "@" + rtspconfig['ip'] + rtsp_config[rtspconfig['brand']] #拼接rtsp参数 try: cap = linkvideo(video1) i = 0 for i in range(5): i = i + 1 ret, frame = cap.read() if ret == False: # 若没有帧返回,则重新刷新rtsp视频流 print("重新获取图像") print(i) if i == 5: readredis.set(rtspconfig['ip'], "fail") print("重新连接5次失败") else: cv2.imwrite(nowdir + "\\" + rtspconfig['ip'] + ".jpeg", frame) #保存图像 print("图像保存成功") readredis.set(rtspconfig['ip'], "success") cap.release() #关闭摄像头 break except: print("连接失败,网络或用户名密码错误") readredis.set(rtspconfig['ip'], "fail") if __name__ == '__main__': total = 0 fail = 0 weixindata = "" readredis.flushall() print("初始化redis数据库") multiprocessing.freeze_support() #防止windows无限创建进程 with Pool(8) as p: #8进程 p.map(dayin, rtsp_config["rtsp"]) for key in rtsp_config["rtsp"]: if readredis.get(key["ip"]) == "fail": weixindata = weixindata + (key["ip"]+" 网络或账号密码错误\n") fail = fail + 1 total = total + 1 weixinpost = "总计巡检:"+str(total)+"台"+",故障摄像头:"+str(fail)+"台\n"+weixindata post_weixin(weixinpost) flog = codecs.open(nowdir + "\\" + nowtime + ".log", 'w', encoding='utf-8') flog.write(weixinpost) flog.close() print("程序执行完成") rtsp.json yushi指宇视品牌摄像头,haikang指海康威视{ "haikang" : ":554/h264/ch1/main/av_stream", "yushi" : ":554/video1", "rtsp" : [ {"ip" : "172.16.1.1","hostname" : "摄像头1","brand" : "yushi","name": "admin","password": "admin"}, {"ip" : "172.16.1.2","hostname" : "摄像头2","brand" : "yushi","name": "admin","password": "admin"}, {"ip" : "172.16.1.3","hostname" : "摄像头3","brand" : "haikang","name": "admin","password": "admin"} ] }总结 有点困难哦
2023年08月07日
453 阅读
0 评论
3 点赞
2023-08-07
docker一键部署redis
红帽系系统默认为podman替代dockerpodman pull redis podman run --restart=always -p 6379:6379 --name myredis -d redis --requirepass passwd@123
2023年08月07日
282 阅读
0 评论
0 点赞
2023-08-04
VLAN非常规实验,给你带来一个不一样的VLAN2
查看本文前请先查看第一篇VLAN非常规实验,给你带来一个不一样的VLAN1https://90apt.com/2901本期为大家带来两个VLAN非常规实验1、傻瓜网络网管改造2、VLAN串联一、傻瓜网络网管改造 1、项目需求此需求来源真实,监控网络全部为傻瓜式连接交换机,需求逐步进行网管改造,改造应减小对监控网络的影响,监控网络可临时中断数分钟,不允许完全停机进行改造。2、改造前简化拓扑交换机均无配置,硬盘录像机与摄像头互通3、改造思路监控网络配置为vlan10,监控交换机管理网络配置为vlan20SW1 SW2 SW3 IP配置为192.168.20.1 192.168.20.2 192.168.20.3为保证监控不完全停机,需要用到trunk与pvid技术4、监控汇聚交换机改造将1-24口划入vlan10,将25-28划入trunk,配置vlan1 10 20通过,配置pvid10,为vlan20配置ip,最后测试硬盘录像机与摄像头是否互通[SW1]vlan 10 [SW1-vlan10]vlan 20 [SW1-vlan20]qu [SW1]int range g1/0/1 to g1/0/24 [SW1-if-range]port access vlan 10 [SW1-if-range]qu [SW1]int range g1/0/25 to g1/0/28 [SW1-if-range]port link-type trunk [SW1-if-range]port trunk permit vlan 1 10 20 [SW1-if-range]port trunk pvid vlan 10 [SW1]int vlan 20 [SW1-Vlan-interface20]ip add 192.168.20.1 24使用硬盘录像机ping摄像头[H3C]ping 192.168.1.2 Ping 192.168.1.2 (192.168.1.2): 56 data bytes, press CTRL_C to break 56 bytes from 192.168.1.2: icmp_seq=0 ttl=255 time=1.658 ms 56 bytes from 192.168.1.2: icmp_seq=1 ttl=255 time=2.110 ms5、技术解析在此改造中,为什么可以使用trunk接口对接无配置交换机并且不影响监控网络运行?此配置重点在于对vlan的理解,access接口为出撕标签入打标签,trunk接口默认不处理标签,当trunk接口配置pvid时,trunk接口对于此pvid的vlan同样具备access的作用,即出撕标签入打标签,因此trunk pvid vlan10可以与傻瓜交换机的access接口通讯,保证监控网络运行。6、其他监控交换机改造,测试监控交换机之间是否互通,测试硬盘录像机与摄像头是否互通[SW2]vlan 10 [SW2-vlan10]vlan 20 [SW2]int range g1/0/1 to g1/0/24 [SW2-if-range]port access vlan 10 [SW2-if-range]int range g1/0/25 to g1/0/28 [SW2-if-range]port link-type trunk [SW2-if-range]port trunk permit vlan 1 10 20 [SW2-if-range]port trunk pvid vlan 10 [SW2-if-range]qu [SW2]int vlan 20 [SW2-Vlan-interface20]ip add 192.168.20.2 24[SW3]vlan 10 [SW3-vlan10]vlan 20 [SW3-vlan20]qu [SW3]int range g1/0/1 to g1/0/24 [SW3-if-range]port access vlan 10 [SW3-if-range]int range g1/0/25 to g1/0/28 [SW3-if-range]port link-type trunk [SW3-if-range]port trunk permit vlan 1 10 20 [SW3-if-range]port trunk pvid vlan 10 [SW3-if-range]qu [SW3]int vlan 20 [SW3-Vlan-interface20]ip add 192.168.20.3 24硬盘录像机ping摄像头[H3C]ping 192.168.1.2 Ping 192.168.1.2 (192.168.1.2): 56 data bytes, press CTRL_C to break 56 bytes from 192.168.1.2: icmp_seq=0 ttl=255 time=1.230 ms 56 bytes from 192.168.1.2: icmp_seq=1 ttl=255 time=2.140 ms监控汇聚ping监控交换机3<SW1>ping 192.168.20.3 Ping 192.168.20.3 (192.168.20.3): 56 data bytes, press CTRL_C to break 56 bytes from 192.168.20.3: icmp_seq=0 ttl=255 time=1.000 ms 56 bytes from 192.168.20.3: icmp_seq=1 ttl=255 time=1.000 ms改造完成二、VLAN串联 1、项目需求此需求来源真实,SW1、SW2均为网管交换机,SW1 g1-g24为accessVLAN5 g25-g28为trunkALL,SW2 g1-g24为accessVLAN1 g25-g28为trunkALL,此时SW2所在区域已经封闭无法进入,请通过SW1的调整使服务器与读卡器互通。2、现状测试服务器无法ping通读卡器<H3C>ping 192.168.1.2 Ping 192.168.1.2 (192.168.1.2): 56 data bytes, press CTRL_C to break Request time out Request time out3、技术解析由于SW2无法操作,因此要在SW1上将VLAN5与VLAN1互联,通过VLAN1穿过trunk接口将数据送达读卡器,我们在SW1上创建一个VLAN1接口,将VLAN1与VLAN5接口通过网线串联。注意:我们是无法直接为端口配置VLAN1的,但可以通过default使接口恢复为VLAN1.[SW1-GigabitEthernet1/0/4]dis th # interface GigabitEthernet1/0/4 port link-mode bridge port access vlan 5 combo enable fiber # return [SW1-GigabitEthernet1/0/4]default This command will restore the default settings. Continue? [Y/N]:y [SW1-GigabitEthernet1/0/4]dis th # interface GigabitEthernet1/0/4 port link-mode bridge combo enable fiber # return [SW1-GigabitEthernet1/0/4]dis interface brief GE1/0/1 UP 1G(a) F(a) A 5 GE1/0/2 DOWN auto A A 5 GE1/0/3 DOWN auto A A 5 GE1/0/4 DOWN auto A A 1 GE1/0/5 DOWN auto A A 54、测试发现仍无法ping通ping 192.168.1.2 Ping 192.168.1.2 (192.168.1.2): 56 data bytes, press CTRL_C to break Request time out Request time out5、技术分析在同一台交换机上串联接口,我们首先要考虑STP防环协议是否阻止了接口,查看STP接口状态,发现g4接口被屏蔽[SW1]dis stp brief MST ID Port Role STP State Protection 0 GigabitEthernet1/0/1 DESI FORWARDING NONE 0 GigabitEthernet1/0/3 DESI FORWARDING NONE 0 GigabitEthernet1/0/4 BACK DISCARDING NONE 0 GigabitEthernet1/0/28 DESI FORWARDING NONE关闭stp协议[SW1]un stp global en检查服务器与读卡器是否互通<H3C>ping 192.168.1.2 Ping 192.168.1.2 (192.168.1.2): 56 data bytes, press CTRL_C to break 56 bytes from 192.168.1.2: icmp_seq=0 ttl=255 time=1.227 ms 56 bytes from 192.168.1.2: icmp_seq=1 ttl=255 time=1.665 ms测试通过注意:此方法仅用于特殊情况下的紧急处理,请勿实施于正常网络中。
2023年08月04日
466 阅读
0 评论
0 点赞
2023-08-03
almalinux8安装tomcat9
从yum源直接安装tomcat9yum install tomcat tomcat-webapps tomcat-admin-webapps启动服务systemctl enable --now tomcat访问tomcat正常http://IP:8080/配置Manager App访问范围/usr/share/tomcat/webapps/manager/META-INF/context.xml原内容 <Context antiResourceLocking="false" privileged="true" > <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" sameSiteCookies="strict" /> <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 增加任意IP访问 \d+\.\d+\.\d+\.\d+ 修改后 <Context antiResourceLocking="false" privileged="true" > <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" sameSiteCookies="strict" /> <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|\d+\.\d+\.\d+\.\d+" /> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> </Context> 配置Manager App用户名密码/usr/share/tomcat/conf/tomcat-users.xml在倒数第二行添加 <role rolename="manager-gui"/> <user username="admin" password="admin" roles="manager-gui"/>重启服务systemctl restart tomcat完毕
2023年08月03日
264 阅读
0 评论
0 点赞
2023-07-27
0基础上手python3编程,本地文件存活监控
架构图 判断文件是否存在;如果文件不存在,判断check.config是否为1,如果为1程序退出,如果不存在或为0,生成或写入1并发送企业微信告警;如果文件存在,判断check.config是否为0,如果为0程序退出,如果不存在或为1,生成或写入0并发送企业微信告警;预览 系统组成 由两个文件组成 check.py check.conf,其中 check.conf为自动生成代码 check.pyimport os,requests #企业微信机器人 def post_weixin(stats): url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=用自己的' body = { "msgtype": "news", "news": { "articles": [ { "title": "文件监控", "description": stats, "url": "90apt.com", "picurl": "用自己的" } ] }} response = requests.post(url, json=body) print(response.text) print(response.status_code) if os.path.exists("D:\hello.txt") == False: #判断文件是否存在 f1 = open("D:\check.config", 'r') #读取文件 config = f1.read() if config == "1": f1.close() else: f1.close() f1 = open("D:\check.config", 'w+') f1.write("1") #写入文件 post_weixin("监控到文件丢失") f1.close() else: f1 = open("D:\check.config", 'r') config = f1.read() if config == "0": f1.close() else: f1 = open("D:\check.config", 'w+') f1.write("0") post_weixin("监控到文件已生成") f1.close()总结 简单
2023年07月27日
293 阅读
0 评论
0 点赞
2023-07-27
0基础上手python3编程,单线程监控摄像头巡检平台
架构图 读取配置文件;通过rtsp连接摄像头,保存一张截图;发送企业微信通知;记录log日志;预览 系统组成 rtsp.py rtsp.json代码 由于代码在windows平台运行,因此使用绝对路径C:\\jiankong\,文件放置在此目录下。rtsp.pyimport cv2,os,json,time,requests,codecs from func_timeout import func_set_timeout from multiprocessing import Process @func_set_timeout(5) def dayin(): video1 = "rtsp://"+rtspconfig['name']+":"+rtspconfig['password']+"@"+rtspconfig['ip']+rtsp_config[rtspconfig['brand']] cap = cv2.VideoCapture(video1) # 使用整数,此处打开的本地摄像头 while 1: ret, frame = cap.read() if ret == False: # 若没有帧返回,则重新刷新rtsp视频流 continue else: break; # cv2.imshow("capture",frame) cv2.imwrite(nowdir+"\\"+rtspconfig['ip']+".jpeg", frame) cap.release() return rtspconfig['hostname']+"保存成功" def get_config(): config = json.loads(open("C:\\jiankong\\rtsp.json", encoding='utf-8').read()) return config def post_weixin(stats): url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=用自己的' body = { "msgtype": "news", "news": { "articles": [ { "title": "监控摄像头自动巡检", "description": stats, "url": "90apt.com", "picurl": "https://www.hikvision.com/content/dam/hikvision/cn/product/network-camera/fixed-ipc/%E7%BB%8F%E9%94%80%E7%B3%BB%E5%88%97/%E7%BB%8F%E9%94%80%E7%B3%BB%E5%88%97%E5%AF%BC%E8%88%AA%E7%9B%AE%E5%BD%95.jpg" } ] }} response = requests.post(url, json=body) print(response.text) print(response.status_code) total = 0 fail = 0 weixindata = "" rtsp_config = get_config() print(rtsp_config) #path1=os.path.abspath('.') path1=("C:\\jiankong\\") nowtime = time.strftime("%Y%m%d", time.localtime()) try: os.mkdir(path1 + "\\" + nowtime) except: None nowdir = (path1 + "\\" + nowtime) for rtspconfig in rtsp_config['rtsp']: total = total + 1 try: dayin() except: weixindata = weixindata + (rtspconfig['hostname']+" "+rtspconfig['ip']+" 网络或账号密码错误\n") fail = fail + 1 weixinpost = "总计巡检:"+str(total)+"台"+",故障摄像头:"+str(fail)+"台\n"+weixindata post_weixin(weixinpost) flog = codecs.open(nowdir+"\\"+nowtime+".log", 'w',encoding='utf-8') flog.write(weixinpost) flog.close() rtsp.json yushi指宇视品牌摄像头,haikang指海康威视{ "haikang" : ":554/h264/ch1/main/av_stream", "yushi" : ":554/video1", "rtsp" : [ {"ip" : "172.16.1.1","hostname" : "摄像头1","brand" : "yushi","name": "admin","password": "admin"}, {"ip" : "172.16.1.2","hostname" : "摄像头2","brand" : "yushi","name": "admin","password": "admin"}, {"ip" : "172.16.1.3","hostname" : "摄像头3","brand" : "haikang","name": "admin","password": "admin"} ] }总结 简单
2023年07月27日
257 阅读
0 评论
1 点赞
2023-07-20
python编译exe可执行文件
安装pyinstaller模块在终端运行pyinstaller -F -w 自己的py名字.py -F 打包为1个文件 -w 隐藏窗口模式
2023年07月20日
257 阅读
0 评论
0 点赞
2023-07-12
RHEL8+Graylog5.1日志监控系统快速部署接入
本教程适用于RHEL8/Oracle linux8/ALMA Linux8操作系统,当前组件版本信息为:java-17-openjdk-17.0.7.0.7-3.0.1.el8.x86_64 opensearch-2.8.0-1.x86_64 mongodb-org-database-6.0.8-1.el8.x86_64 graylog-server-5.1.3-1.x86_64建议 装一台Alma8服务器,安装graylog,关闭selinux,保持系统更新。全部采用yum源安装,方便快速更新我防火墙仅开放了9000/TCP 1514/UDP 和 SSH端口官方安装教程 https://go2docs.graylog.org/5-1/downloading_and_installing_graylog/red_hat_installation.htm安装OpenJdk17yum install java-17-openjdk安装MongoDB 创建yum源文件/etc/yum.repos.d/mongodb-org.repo[mongodb-org-6.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc安装并启动sudo yum install -y mongodb-org sudo systemctl daemon-reload sudo systemctl enable mongod sudo systemctl start mongod sudo systemctl status mongod安装OpenSearchsudo curl -SL https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/opensearch-2.x.repo -o /etc/yum.repos.d/opensearch-2.x.repo sudo yum install -y opensearch配置OpenSearch端口监听/etc/opensearch/opensearch.ymlcluster.name: graylog node.name: ${HOSTNAME} path.data: /var/lib/opensearch path.logs: /var/log/opensearch discovery.type: single-node network.host: 0.0.0.0 action.auto_create_index: false plugins.security.disabled: true修改内存占用/etc/opensearch/jvm.options-Xms6g -Xmx8g修改内核参数sudo sysctl -w vm.max_map_count=262144 sudo echo 'vm.max_map_count=262144' >> /etc/sysctl.conf启动程序sudo systemctl daemon-reload sudo systemctl enable opensearch sudo systemctl start opensearch sudo systemctl status opensearch安装Graylogsudo rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-5.1-repository_latest.rpm sudo yum install graylog-server修改配置/etc/graylog/server/server.conf增加password_secret和root_password_sha2选项,不增加这两项不允许访问,配置http_bind_address,默认只监听127.0.0.1,修改为0.0.0.0取得root_password_sha2值echo -n "Enter Password: " && head -1 </dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1取得password_secret值< /dev/urandom tr -dc A-Z-a-z-0-9 | head -c${1:-96};echo;启动程序sudo systemctl daemon-reload sudo systemctl enable graylog-server.service sudo systemctl start graylog-server.service sudo systemctl --type=service --state=active | grep graylog登录系统 默认为http://IP:9000/用户名和密码均在server.conf中定义启动Syslog UDP监听器 注意:graylog无法监听1024以内端口,因此Syslog将使用1514UDP端口 graylog - system -inputsH3C交换机快速接入info-center loghost 172.16.0.1 port 1514浪潮BMC快速接入 群晖快速接入 预览 问题处理 时间不对,修改时区 server.confroot_timezone = Asia/Shanghai总结 为什么不用ELK? 你研究ELK? 等你研究出来马斯克都上火星了! 人生苦短,我用Graylog!
2023年07月12日
699 阅读
0 评论
3 点赞
2023-07-10
0基础上手python3编程,通用Mysql数据库字段监控,企业微信告警
架构图 通过redis缓存mysql数据库字段进行对比,当发现内容变动时,进行企业微信告警预览 系统组成 由两部分组成 check.py和redis数据库,从mysql中读取指定字段存储到redis中代码import requests,redis import mysql.connector def post_weixin(data): url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=用自己的' body = { "msgtype": "news", "news": { "articles": [ { "title": "卡号监控机器人", "description": data, "url": "90apt.com", "picurl": "https://www.zkteco.com/cn/uploads/image/20210301/3e1adaa2dce94812e658c5d42afc1525.png" } ] } } headers = {"Content-Type": "application/json"} response = requests.post(url, json=body) print(response.text) print(response.status_code) def sqlread(): mqdb = mysql.connector.connect( host="127.0.0.1", user="admin", passwd="password", database="mysqldata" ) mqcursor = mqdb.cursor() getconfig_sql = "SELECT number,card,name FROM userinfo where ifnull(name, '') <> ''" mqcursor.execute(getconfig_sql) mqconfig = mqcursor.fetchall() global cardchange cardchange = "" readredis = redis.Redis(connection_pool=redis.ConnectionPool(host="127.0.0.1", port="6379", password="password",decode_responses=True)) for i in mqconfig: if readredis.get(i[0]) == str(i[1]): None else: cardchange = cardchange + i[2]+readredis.get(i[0])+"变为"+str(i[1])+"\n" readredis.set(i[0], str(i[1])) sqlread() post_weixin(cardchange)总结 简单
2023年07月10日
303 阅读
0 评论
3 点赞
2023-07-07
RHEL8通过ODBC链接SQL Server数据库
安装完SQLServer数据库,开启数据库远程访问配置对IP的监听配置防火墙端口开放测试端口RHEL8系统安装ODBC驱动https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16&tabs=redhat18-install%2Calpine17-install%2Cdebian8-install%2Credhat7-13-install%2Crhel7-offlinesudo su #Download appropriate package for the OS version #Choose only ONE of the following, corresponding to your OS version #RHEL 7 and Oracle Linux 7 curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo #RHEL 8 and Oracle Linux 8 curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo #RHEL 9 curl https://packages.microsoft.com/config/rhel/9.0/prod.repo > /etc/yum.repos.d/mssql-release.repo exit sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts sudo ACCEPT_EULA=Y yum install -y msodbcsql18 # optional: for bcp and sqlcmd sudo ACCEPT_EULA=Y yum install -y mssql-tools18 echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc source ~/.bashrc # optional: for unixODBC development headers sudo yum install -y unixODBC-devel配置/etc/odbc.inihttps://learn.microsoft.com/zh-cn/sql/connect/odbc/linux-mac/connection-string-keywords-and-data-source-names-dsns?view=sql-server-ver16[TEST] Driver = ODBC Driver 18 for SQL Server # Server = [protocol:]server[,port] Server = tcp:172.16.10.102,1433 TrustServerCertificate=YES # # Note: # Port isn't a valid keyword in the odbc.ini file # for the Microsoft ODBC driver on Linux or macOS 测试,连接成功isql -v TEST user passwd +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | echo [string] | | quit | | | +---------------------------------------+ SQL>
2023年07月07日
330 阅读
0 评论
0 点赞
2023-06-28
0基础上手python3编程,批量自动备份交换机配置并进行企业微信通知
架构图 架构图懒得画了,通过telnet备份交换机配置并通知备份结果,展示失败列表;根据命令不同,可以自定义修改用于任意品牌交换机的配置备份。预览 系统组成 由两个文件组成 swtelnet.py config.json代码 由于代码在Windows平台编写,如果在linux平台运行,请把路径中的\换成/swtelnet.pyimport os.path,telnetlib,time,requests,json,codecs def get_config(): config = json.loads(open(path1+"\config.json", encoding='utf-8').read()) return config def gettelnet_config(): nowtime = time.strftime("%Y%m%d", time.localtime()) try: os.mkdir(path1 + "\\" +nowtime) except: None nowdir = (path1 + "\\" +nowtime) for host in config['ip']: try: tn = telnetlib.Telnet(host['host'], timeout=5) tn.write(config['user'].encode('ascii') + b'\n') time.sleep(3) tn.write(config['passwd'].encode('ascii') + b'\n') time.sleep(3) tn.write(b'screen-length disable\n') time.sleep(1) tn.write(b'dis cur\n') time.sleep(1) tn.write(b'undo screen-length disable\n') time.sleep(1) tn.write(b'quit\n') mac1 = tn.read_all() f1 = open(nowdir+"\\"+host['host']+".conf", 'wb') f1.write(mac1) f1.close() flog.write("finish " + host['hostname'] + " " + host['host']+"\n") except: flog.write("fail " + host['hostname'] + " " + host['host']+"\n") def count_sw(): lines = open(path1 + "\\backup.log", "r", encoding='utf-8').readlines() finish = 0 fail = 0 total = 0 failprint = "" for line in lines: line1 = line.split() total = total + 1 if line1[0] == "fail": failprint = failprint + str(line) fail = fail + 1 else: finish = finish + 1 return "交换机备份报告\n总计"+str(total)+" 完成"+str(finish)+" 失败"+str(fail)+"\n备份失败清单:\n"+failprint class network: def yiyan(): try: url = 'https://v1.hitokoto.cn/?c=d&c=k' response = requests.get(url) res = json.loads(response.text) text1 = res['hitokoto'] if res['from'] == None: text2 = "" else: text2 = res['from'] if res['from_who'] == None: text3 = "" else: text3 = res['from_who'] return text1 + " " + text2 + " " + text3 + "\n\n" except: return "一言API故障\n\n" def tianqi(): try: response2 = requests.get(config['weatherapi']) data1 = json.loads(response2.text) data2 = json.dumps(data1['now']) data2 = json.loads(data2) data3 = "环境温度" + data2['temp'] + " 体感温度" + data2['feelsLike'] + " 天气状况 " + data2[ 'text'] + "\n风向 " + data2['windDir'] + " 风力等级" + data2['windScale'] + " 风速" + data2[ 'windSpeed'] + " 湿度" + data2['humidity'] + " 能见度" + data2['vis'] + "公里\n\n" return data3 except: return "天气API故障\n\n" def post_weixin(stats): url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=用自己的' body = { "msgtype": "news", "news": { "articles": [ { "title": "AI智慧运维", "description": network.tianqi()+network.yiyan()+stats, "url": "90apt.com", "picurl": "用自己的" } ] } } response = requests.post(url, json=body) print(response.text) print(response.status_code) path1=os.path.abspath('.') config = get_config() flog = codecs.open(path1+"\\backup.log", 'w',encoding='utf-8') gettelnet_config() flog.close() network.post_weixin(count_sw())config.json{ "user" : "用自己的账号", "passwd" : "用自己的密码", "weatherapi" : "https://devapi.qweather.com/用自己的API", "ip" : [ {"host" : "172.16.1.6","hostname" : "仓库6"}, {"host" : "172.16.1.5","hostname" : "仓库5"} ] }总结 简单
2023年06月28日
489 阅读
0 评论
3 点赞
1
...
8
9
10
...
24