查看inode相关信息

inode定义 The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attributes may include metadata (times of last change,[2] access, modification), as well as owner and permission data.[3] from inode wiki inode数据结构用于描述文件系统中的文件、目录等, 每一个inode保存了文件系统系统对象memdata如修改时间,访问时间以及权限等。Dennis Ritchie对于inode中i可能代表index,而被访问的文件列表,被组织为存放存放在磁盘上的一维数组。 环境准备 Linux Distributions: CentOS 7 通过fdisk划出一个10M分区, 格式化为ext4 $ fdisk /dev/sdb ... # Start End Size Type Name 1 2048 8390655 4G Linux filesyste 2 8390656 8411135 10M Linux filesyste [root@centosgpt ~]# $ mkfs.ext4 /dev/sdb2 $ mount /dev/sdb2 /root/inode inode查看 ls ls -i 文件名or目录 ...

2020-09-15 · 2 min · 257 words

dhclient error while loading shared libraries libdns-export.so.1102

环境: cenos7(X86_64) 问题: 网站显示无法链接数据库,重启后发现无法链接服务器,通过管理端登录服务器 /var/log/messages显示 dhclient: error while loading shared libraries: libdns-export.so.1102: cannot open shared object file: No such file or directory 修复: 需要root权限 # ldconfig # dhclient --help # systemctl restart NetworkManager.service # ip -a 其他 查找过程及问题: 由于前一阵刚好在服务器上增加了防火墙相关配置,所以当时开始一直判断是防火墙设置问题。关闭防火墙后仍无法访问。 排除防火墙问题后,查看了下网络配置发现eth0没有相关IP信息。 在到/var/log/messages中查看错误信息,最终通过error定位到dhclient错误. 当然还是决定改为静态方式配置IP, 我用的是eth0, 修改下面配置即可 /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" BOOTPROTO="static" ONBOOT="yes" IPADDR=XXX.XXX.XXX.XXX NETMASK=255.255.255.0 GATEWAY=XXX.XXX.XXX.XXX DNS1=XXX.XXX.XXX.XXX 相关Bug Bug 1726534 与我遇到的问题一样, 大致的意思说就是说安装一些库的时候, 比如libapr虽然安装失败,导致 /etc/ld.so.cache 保存的是老版本libdns-export.so.100 不是新版本的libdns-export.so.1102 导致dhclient载入libdns-export.so.1102失败, 通过ldconfig重新更新一下 /etc/ld.so.cache即可。 serverfault.com-Cannot Access My Google VM after reboot

2020-08-25 · 1 min · 71 words

python excel文件中指定字段是否相等

工作需要检查相关excel数据信息, 查询一个表格中的指定位置编号,检查相关多个个相关表格中指定位置编号是否相同。 环境 windows10 python3.7 + openpyxl + xlrd 测试数据 目录结构 C:. │ checklist.py │ reference.xlsx │ └─newdir ├─dir1 │ data1.xls │ └─dir2 data2.xls 文件内容 参考表格 reference.xlsx A CODE-12345 表格1 data1.xls A CODE-12345 表格2 data2.xlsx A CODE-67890 代码 from openpyxl import load_workbook from openpyxl import Workbook import os import xlrd ## 获取待检查清单列表 def get_file(root_path,all_files=[]): files = os.listdir(root_path) for file in files: if not os.path.isdir(root_path + '/' + file): # 检查文件名包含"功能点", 以 "xls", "xlsx"为后缀的文件 if (file.endswith('.xls') or file.endswith('.xlsx')) \ and 'XXXX' in file: all_files.append(root_path + '/' + file) else: # 如果是目录,目录后增加'/'递归查找符合条件的文件 get_file((root_path+'/'+file),all_files) return all_files ## 获取参考文件指定位置编号 def get_request_no(root_path): files = os.listdir(root_path) for file in files: if not os.path.isdir(root_path + '/' + file): if file.endswith('.xls') or file.endswith('.xlsx') \ and 'YYYY' in file: print (file) ## only xlsx wb_in = load_workbook(file) ws_in = wb_in.active ## 查找第2行,第5列的编号 request_no = ws_in.cell(row=2, column=5) print (request_no.value + '\n') ##break return request_no.value; ## 遍历参考列表文件记录与参考文件表中需求编号不同的文件名 def check_file(files, request_no): result="" for file in files: ## 由于openpyxl, 不支持xls,这里使用的是xlrd库 wb_in = xlrd.open_workbook(file) ws_in = wb_in.sheets()[0] ## 编号是从0开始计数, 第8行, 第2列中的数据 file_request_no = ws_in.cell(rowx=7, colx=1) if str(file_request_no.value) != str(request_no): s = file_request_no.value + file +'\n' result += s return result def write_log(result): file=open("result.txt", "w") file.write(result) file.close() path = r'.\\ZZZZ' list=get_file(path) path = r'.' no=get_request_no(path) result=check_file(list, no) write_log(result) 运行结果 > python check.py > type result.txt CODE-67890.\\newdir/dir2/data2.xls 参考 Openpyxl Doc xlrd- API Reference

2020-08-24 · 2 min · 217 words

文件时间信息

文件时间信息一般包含,文件创建时间,文件修改时间,文件访问时间。 Unix/Linux 文件修改时间有两个一个是(Modify Time 文件内容修改/ Change Time:文件权限状态/权限), 根据不同的文件系统,文件时间信息属性会有一些差别。Unix/Linux在挂载文件系统的时候会设置相关文件时间属性相关参数。 File Times in Linux 定义 Linux 早期内核版本也没有创建日期,在最新版本内核中已经可以看到相关字段 /include/linux/stat.h struct kstat { struct timespec64 atime; struct timespec64 mtime; struct timespec64 ctime; struct timespec64 btime; /* File creation time */ }; 不过glibc中没有相关接口 struct stat { /* These are the members that POSIX.1 requires. */ ... __time_t st_atime; /* Time of last access. */ __time_t st_mtime; /* Time of last modification. */ __time_t st_ctime; /* Time of last status change. */ ... }; 相关命令 ls ...

2020-07-30 · 3 min · 489 words

python修改excel文档相关日期信息

工作需要修改excel文件创建内容时间(excel属性非文件属性)和上次修改时间, 用python写了一个脚本处理了一下。 环境: windows10 python3.7 + openpyxl 1. 使用openpyxl修改excel属性 import openpyxl from datetime import datetime fh = openpyxl.load_workbook("results.xlsx") obj = fh.properties #To get old properties print( obj ) # print old properties fh.properties.created = datetime(2000,1,1, 8,30,11) fh.properties.modified = datetime(2000,2,1, 8,32,19) ##similarly you can set other fields ## new_obj = fh.properties #Now get new properties print ( new_obj ) # print new properties fh.save("results2.xlsx") 2.使用os.utime方法修改文件属性的访问时间,修改时间 import os, sys,time from datetime import datetime # Showing stat information of file stinfo = os.stat('results.xlsx') print (stinfo) # Using os.stat to recieve atime and mtime of file print ("access time of results.xlsx: %s" %stinfo.st_atime) print ("modified time of results.xlsx: %s" %stinfo.st_mtime) # Modifying atime and mtime t = datetime(2008, 1, 1, 12,12, 12) atime = time.mktime(t.timetuple()) t = datetime(2009, 1, 1, 12,12, 12) mtime = time.mktime(t.timetuple()) os.utime("results.xlsx",(atime, mtime)) print ("done!!") 3.使用pywin32-SetFileTime方法修改文件属性的创建日期, 访问时间,修改时间 from win32file import CreateFile, SetFileTime, GetFileTime, CloseHandle from win32file import GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING from pywintypes import Time import time from datetime import datetime def modifyFileTime(filePath, createTime, modifyTime, accessTime): try: fh = CreateFile(filePath, GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, 0) createTimes = Time(createTime) accessTimes = Time(modifyTime) modifyTimes = Time(accessTime) print (createTimes, accessTimes, modifyTimes) SetFileTime(fh, createTimes, accessTimes, modifyTimes) CloseHandle(fh) return 0 except: return 1 if __name__ == '__main__': t = datetime (2019, 12,13,21,51,2) cTime = time.mktime(t.timetuple()) t = datetime (2019, 2,2,0,1,3) mTime = time.mktime(t.timetuple()) t = datetime (2019, 2,2,0,1,4) aTime = time.mktime(t.timetuple()) fName = r"results.xlsx" r = modifyFileTime(fName, cTime, mTime, aTime) if r == 0: print('修改完成') elif r == 1: print('修改失败') 参考及引用 Openpyxl Doc python 修改文件的创建时间、修改时间、访问时间 pythondoc-os.utime In Python, how do you convert a datetime object to seconds? python ImportError: No module named win32file

2020-07-29 · 2 min · 270 words

centos7 升级 glibc && gcc

环境 cenos7(X86_64) 为了验证 mmap()一些功能需要升级glibc版本, 顺便把gcc一起升级一下 升级gcc 预安装包 安装过程中需要makeinfo, 先安装下texi2html, texinfo yum install texi2html texinfo 安装gcc wget https://ftp.gnu.org/gnu/gcc/gcc-10.1.0/gcc-10.1.0.tar.gz tar zxvf gcc-10.1.0.tar.gz cd gcc-10.1.0/ mkdir build cd build /configure --enable-languages=c,c++ --disable-multilib make && make install 验证 # gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=... Target: x86_64-pc-linux-gnu Configured with: ../configure --enable-languages=c,c++ --disable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.1.0 (GCC) 升级glibc 预安装包 我的机器上是要求安装最新的make, 网上有需要升级ld, 的下载安装binutils就可以了 wget https://ftp.gnu.org/pub/gnu/make/make-4.3.tar.gz tar zxvf make-4.3.tar.gz cd make-4.3 mkdir build ./configure make && make install cp /usr/bin/make make.backup ln /usr/local/bin/make /usr/bin/make 安装glibc wget http://ftp.gnu.org/gnu/glibc/glibc-2.31.tar.gz tar -xvf glibc-2.31.tar.gz mkdir glibc-2.31/build cd glibc-2.31/build ../configure --prefix=/usr --with-headers=/usr/include --with-binutils=/usr/bin make make install 问题 make install 报错 /usr/bin/perl scripts/test-installation.pl /tmp/glibc-2.31/build/ /usr/bin/ld: cannot find -lnss_test2 ... LD_SO=ld-linux-x86-64.so.2 CC="gcc -B/usr/bin/" /usr/bin/perl scripts/test-installation.pl /tmp/glibc-2.31/build/ /usr/bin/ld: /lib/../lib64/libnss_nis.so: undefined reference to '_nsl_default_nss@GLIBC_PRIVATE' 可以从上面脚本信息看到是 scripts/test-installation.pl 有报错, 进去看一下, 主目录下的 Makefile ...

2020-07-18 · 3 min · 433 words

cenos7+openssh 修改SSH服务端口

环境: cenos7(X86_64) + openssh ssh端口配置 修改端口 例如8888 文件 /etc/ssh/sshd_config #Port 22 Port 8888 重启服务 systemctl restart sshd systemctl status sshd 防火墙配置: 我这里配置比较简单仅zone配置了一个public firewall-cmd --permanent --zone=public --add-port=8888/tcp 重启服务 systemctl restart firewalld systemctl status firewalld

2020-07-13 · 1 min · 33 words

通过alternatives进行多版本间切换

上周在学习单点登录安装CAS Overlay Template要使用指定版本,当时机器上安装了多个版本的jdk使用alternatives命令进行了切换. 如果需要在多个版本应用间切换并进行管理可以使用这个命令。 alternative 前身是 Debian Linux的一个用 Perl实现的工具 update-alternatives 后续Red Hat重写了并重新命名使用在 Red Hatand CentOS版本中. alternative统一了有多个版本应用,但在UNIX中更认可通过环境变量来设置 通常定义在 /etc/profile 或 $HOME/.profile 下面用一个例子演示一下 如果有有一个应用 em ,他的新版本 nem, 由于习惯原因, 我们更习惯敲em, 可以通过下面步骤设置一下 创建 先创建两个脚本做为代表em nem应用 [root@centosgpt alternatives]# cat em #!/bin/bash echo " This is em " [root@centosgpt alternatives]# cat nem #!/bin/bash echo " This is nem " 生成一个alternative需要下面四个要素: alternatives --install <link> <name> <path> <priority> link : 统一应用名称,一个链接文件 name : alternative 的名称便于记忆 path : 实际版本的路径 priority :优先级 [root@centosgpt alternatives]# sudo alternatives --install /usr/bin/em uemacs /root/alternatives/em 1 [root@centosgpt alternatives]# sudo alternatives --install /usr/bin/em uemacs /root/alternatives/nem 99 [root@centosgpt alternatives]# alternatives --config uemacs There are 2 programs which provide 'uemacs'. Selection Command ----------------------------------------------- + 1 /root/alternatives/em * 2 /root/alternatives/nem 验证 [root@centosgpt ~]# em This is nem [root@centosgpt ~]# alternatives --config uemacs There are 2 programs which provide &#039;uemacs&#039;. Selection Command ----------------------------------------------- 1 /root/alternatives/em *+ 2 /root/alternatives/nem Enter to keep the current selection[+], or type selection number: 1 [root@centosgpt ~]# em This is em 移除 alternatives --remove <name> <path> ...

2020-06-28 · 2 min · 324 words

Linux Swap 启停及swappiness设置

生成swap分区 可以通过磁盘分区和文件两种方式进行操作 1. 通过磁盘分区 划出一块4G磁盘fdisk /dev/sdb sdb磁盘对应的文件 [root@centosgpt ~]# fdisk /dev/sdb Command (m for help): n Partition number (1-128, default 1): First sector (34-41943006, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943006, default 41943006): +4G Created partition 1 ... Command (m for help): p ... # Start End Size Type Name 1 2048 8390655 4G Linux filesyste .. Command (m for help): w The partition table has been altered! 创建分区mkswap /dev/sdb1 sdb1对应分区 [root@centosgpt ~]# mkswap /dev/sdb1 Setting up swapspace version 1, size = 1020 KiB no label, UUID=5dabc5b1-d763-4757-9e0c-383f0cacb0ea 2. 通过文件生成 生成文件dd if=/dev/zero of=/swap bs=1MB count=1024 ...

2020-06-21 · 2 min · 344 words

/proc/buddyinfo文件

/proc/buddyinfo文件 /proc/buddyinfo 文件可以查看Linux机器上可用的内存页, 可以查看每个节点,不同区域的每个order大小的块的可用数量, 下面是我们虚拟机的信息: cat /proc/buddyinfo Node 0, zone DMA 97 90 51 31 10 9 6 2 0 0 0 Node 0, zone DMA32 456 876 665 457 192 83 25 5 1 0 0 mm/vmstat.c walk_zones_in_node 实现了其proc文件输出 可以看到显示的单一NUMA节点Node 0在内核使用pglist_data结构表示, 每个节点包含多个 区域, 使用zone结构标识。 ZONE类型如下: ZONE_DMA 这个区域为一些不能在所有内存地址初始化DMA的设备保留,大小和体系结构有关 , 一些ISA需要它 ZONE_DMA32 这个区域仅存在与X86_64体系中,支持32位设备放到到小于4G的内存 ZONE_NORMAL 可以直接映射的区域, 如果DMA设备支持所有可寻址内存,则可以将所有可寻址内存视为正常区域, DMA操作可以在这些页面上启动 ZONE_HIGHMEM 对于32bit系统内核空间和用户空间比例是1:3模式下(3G用户空间,1G 内核空间), 该区域包含的页面只能由内核通过显式映射到其地址空间来访问,内核段以外的所有物理内存页都可以通过映射到该区域 ZONE_MOVABLE 从最高内存区域划出一片的内存, 处理内存碎片,X86-32bit大于ZONE_HIGH的区域, X86-64bit 大于ZONE_DMA32的区域,启动是根据内核有参数kernelcore用于设置不可移动的内存大小。 如果指定了“mirror”选项,则mirror内存用于非移动分配,其余内存用于移动页面。 ZONE_DEVICE 与SPARSEMEM这种新的物理内存模型有关, 这种模型支持内存热插拔, 这类内存通过devm_memremap_pages,映射到内存的这个区域. 伙伴分配将每个区域ZONE进一步划分为2次幂(order)个页面大小的块, 就是后面的那串数字 collectl 工具可以实时监控相关剩余内存的变化 #collectl -sB -oT waiting for 1 second sample... # MEMORY FRAGMENTATION (4K pages) #Time Node Zone 1Pg 2Pgs 4Pgs 8Pgs 16Pgs 32Pgs 64Pgs 128Pgs 256Pgs 512Pgs 1024Pgs 12:50:41 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:41 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:42 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:42 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:43 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:43 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:44 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:44 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:45 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:45 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:46 0 DMA 126 93 71 64 38 13 4 2 0 0 0 12:50:46 0 DMA32 441 349 94 26 14 0 0 0 0 0 0 12:50:47 0 DMA 126 94 71 66 40 13 4 2 0 0 0 12:50:47 0 DMA32 452 354 97 40 19 0 0 0 0 0 0 相关资料 一篇介绍/proc/buddyinfo博客文章Making sense of /proc/buddyinfo quora上关于这个问题的讨论里面有What is the purpose of “/proc/buddyinfo” entry on Linux systems? [v4,2/2] mm/page_alloc.c: introduce kernelcore=mirror option KernelNewbies: Linux_4.6 Mastering Linux Kernel Development: A kernel developer’s reference manual Physical Memory Model Memory Fragmentation

2020-06-06 · 2 min · 333 words