文章目录一、centos基本命令1、升级内核到最新版本2、文件句柄数限制优化3、ssh、sftp、scp等远程命令4、find、grep文件查找5、vi命令6、yum1阿里yum源centos72centos82常用7、防火墙8、sed编辑文件9、rpm相关10、网络1修改网络2dig命令3配置dns4端口11、awk命令12、查看操作系统二、windows常用操作1、activate2、查看已保存的wifi密码3、win11右键默认打开更多选项4、win10为了对电脑保护 已经阻止此应用三、实用操作1、docker运行linux挂前台的任务2、部署命令3、内核参数调整四、debian常用操作1、源2、查看cpu温度一、centos基本命令1、升级内核到最新版本# 1、查看内核版本[rootlocalhost ~]# cat /etc/centos-releaseCentOS Linux release7.8.2003(Core)# 2、yum会把下载的软件包和header存储在cache中而不自动删除。所以需要先使用yum clean all命令清除缓存。yum clean all# 3、升级yum update-y# 4、重启reboot# 5、再次查看内核版本cat/etc/centos-release2、文件句柄数限制优化# 局部文件句柄数单个进程最大打开文件数# 查看一个进程最大打开的文件数fd不同系统有不同的默认值[rootlocalhost ~]# ulimit -n1024# 修改文件句柄vi/etc/security/limits.conf#文末添加* hard nofile65535* soft nofile65535# 其中*代表所有用户65535代表修改的值修改以后需要重新登录才能生效常规设置65535就够用这也是云服务器默认的# 全局文件句柄所有进程能够创建的文件句柄数之和[rootlocalhost ~]# cat /proc/sys/fs/file-max382508# 修改全局文件句柄vi/etc/sysctl.conf# 文末加上fs.file-max10000000000# 使配置生效sysctl-p3、ssh、sftp、scp等远程命令https://feixiang.blog.csdn.net/article/details/1324210044、find、grep文件查找https://feixiang.blog.csdn.net/article/details/1068356665、vi命令https://blog.csdn.net/A_art_xiang/article/details/1068346166、yum1阿里yum源centos7https://blog.csdn.net/m0_53167220/article/details/141263109# 1、备份yum源配置文件mv/etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak# 2、新建yum仓库配置文件vi/etc/yum.repos.d/CentOS-Base.repo# 3、按i进入编辑模式将以下内容填入# 4、清除缓存并重建元数据缓存yum clean allyum makecache# CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client. You should use this for CentOS updates# unless you are manually picking other mirrors.## If the mirrorlist does not work for you, as a fall back you can try the# remarked out baseurl line instead.##[base]nameCentOS-$releasever- Base - mirrors.aliyun.comfailovermethodprioritybaseurlhttps://mirrors.aliyun.com/centos-vault/7.9.2009/os/$basearch/gpgcheck1gpgkeyhttps://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7#released updates[updates]nameCentOS-$releasever- Updates - mirrors.aliyun.comfailovermethodprioritybaseurlhttps://mirrors.aliyun.com/centos-vault/7.9.2009/updates/$basearch/gpgcheck1gpgkeyhttps://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7#additional packages that may be useful[extras]nameCentOS-$releasever- Extras - mirrors.aliyun.comfailovermethodprioritybaseurlhttps://mirrors.aliyun.com/centos-vault/7.9.2009/extras/$basearch/gpgcheck1gpgkeyhttps://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages[centosplus]nameCentOS-$releasever- Plus - mirrors.aliyun.comfailovermethodprioritybaseurlhttps://mirrors.aliyun.com/centos-vault/7.9.2009/centosplus/$basearch/gpgcheck1enabled0gpgkeyhttps://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7#contrib - packages by Centos Users[contrib]nameCentOS-$releasever- Contrib - mirrors.aliyun.comfailovermethodprioritybaseurlhttps://mirrors.aliyun.com/centos-vault/7.9.2009/contrib/$basearch/gpgcheck1enabled0gpgkeyhttps://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-72centos8https://blog.csdn.net/qq_45496140/article/details/1397557702常用# 更新yum-yupdate# 安装yuminstallpython3-y# 移除yum removejava# 列出所有已安装和可安装的软件包yum list# 查找软件包yum searchkeyword7、防火墙# 防火墙添加规则# 192.168.56.10/24 就是192.168.56.1 -255# 192.168.56.10/32 就是192.168.56.10这个单个IPfirewall-cmd--permanent--add-rich-rulerule familyipv4 source address192.168.56.10/32 port protocoltcp port8081 acceptfirewall-cmd--permanent--add-rich-rulerule familyipv4 port protocoltcp port8081 acceptfirewall-cmd--reloadfirewall-cmd--zonepublic --list-all# 关闭防火墙sudosystemctl stop firewalldsudosystemctl disable firewalld8、sed编辑文件# sed参数# -n 不输出模式空间内容到屏幕即不自动打印# -i.bak 备份文件并原处编辑# -e 多点编辑# -f /PATH/SCRIPT_FILE 从指定文件中读取编辑脚本# -r 支持使用扩展正则表达式# scripe参数# p 打印当前模式空间内容追加到默认输出之后# d 删除模式空间匹配的行并立即启用下一轮循环# a [\]text 在指定行后面追加文本支持使用\n实现多行追加# i [\]text 在行前面插入文本# c [\]text 替换行为单行或多行文本# w /path/file 保存模式匹配的行至指定文件# r /path/file 读取指定文件的文本至模式空间中匹配到的行后# 为模式空间中的行打印行号# ! 模式空间中匹配行取反处理# s/// 查找替换,支持使用其它分隔符ss#### 替换标记# g 行内全局替换# p 显示替换成功的行# w /PATH/FILE 将替换成功的行保存至文件中# 第二行 打印sed-n2 ptestifconfig|sed-n2 p# 2-3行sed-n2,3 ptest# 第二行往后3行sed-n2,3 ptest# 删除第二行但是不会修改文件只会修改显示结果sed2 dtest# 修改源文件并且备份 -i直接修改源文件不备份sed-i.bak2 dtest# 行后插入 加 \ 表示隔离开sed/root/a\superman/etc/passwd# 行前插入sed/root/i\superman/etc/passwd# 代替行sed/root/c\superman/etc/passwd# 全局替换 test替换为mytestseds/test/mytest/gexamplesed–ns/root/superman/p/etc/passwd#单词后sed–ns/root/superman/p/etc/passwd#单词前# 执行多次操作 -esed-es/dog/cat/-es/hi/lo/petssed–i.baks/dog/cat/gpets9、rpm相关# 查看安装信息rpm-qibind# 查看软件包含的文件列表rpm-qlbind10、网络1修改网络# 查看网卡ipaddr# 编辑网卡信息vi/etc/sysconfig/network-scripts/ifcfg-eth1# resolv.confDNS客户机的配置文件cat/etc/resolv.conf# 重启网卡servicenetwork restart#VAGRANT-BEGIN# The contents below are automatically generated by Vagrant. Do not modify.NM_CONTROLLEDyesBOOTPROTOnoneONBOOTyesIPADDR192.168.56.10GATEWAY192.168.56.1DNS1114.114.114.114DNS28.8.8.8NETMASK255.255.255.0DEVICEeth1PEERDNSno#VAGRANT-END2dig命令# 安装yuminstallbind-utils3配置dns# 方式一直接生效修改/etc/resolv.confcat/etc/resolv.conf nameserver192.168.56.10 nameserver192.168.56.10# 方式二需要重启网卡vi/etc/sysconfig/network-scripts/ifcfg-eth14端口# 查看端口netstat-lntp# 查看所有端口及进程ss-tulnp# 查找特定端口的使用情况例如80端口ss-tulnp|grep8011、awk命令# 获取pidpid$(psaux|grepqtg-admin|grep-vgrep|awk{print $2})kill${pid}12、查看操作系统# 查看操作系统cat/etc/os-release二、windows常用操作1、activate# windows10slmgr /skms kms.03k.org slmgr /ato# win11slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX slmgr /skms kms.03k.org slmgr /ato2、查看已保存的wifi密码# 1、查看保存的wifi密码netsh wlan show profile# 2、查看wifi密码 这里的“WiFi名称”应替换为你想要查看密码的WiFi网络名称。# 关键内容即 密码netsh wlan show profilenameWiFi名称keyclear3、win11右键默认打开更多选项# cmd管理员权限打开reg.exeaddHKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32/f /ve# 重启资源管理器taskkill /f /im explorer.exestart explorer.exe4、win10为了对电脑保护 已经阻止此应用1、用鼠标右键单击开始图标接着在出现的选框中单击打开“运行”栏或者使用快捷键win r 调用“运行”。2、在运行框中输入“gpedit.msc”并点击确定进入“本地组策略编辑器”。3、在“本地组策略编辑器”窗口中依次打开“计算机配置——Windows设置——安全设置——本地策略——安全选项”。4、接着找到“安全选项”中的“用户账户控制以管理员批准模式运行所有管理员”。5、右键点击选择“属性”在“属性”窗口里选择“已禁用”点击确定最后重启电脑就可以了。三、实用操作1、docker运行linux挂前台的任务tail-f/dev/null2、部署命令# 启动 标准输出写入app.log标准错误输出也写入app.log# /dev/null 丢弃输出nohupjava-jar-Dspring.profiles.activetestspringboot.jarapp.log21# 停止pid$(psaux|grepspringboot.jar|grep-vgrep|awk{print $2})kill${pid}3、内核参数调整# 查看内核参数sysctl-a|greptcp_retries2# 修改高并发内核参数sudosysctl-wnet.ipv4.tcp_tw_reuse1sudosysctl-wnet.ipv4.tcp_syncookies1sudosysctl-wnet.ipv4.tcp_max_tw_buckets5000sudosysctl-wnet.ipv4.tcp_max_syn_backlog16384sysctl-wnet.core.netdev_max_backlog10000sysctl-wnet.core.somaxconn65535sysctl-wnet.ipv4.tcp_retries23sudoecho1024065000/proc/sys/net/ipv4/ip_local_port_range四、debian常用操作1、源https://www.cnblogs.com/smlile-you-me/p/17727308.html# 修改源vi/etc/apt/sources.list# 设置 跟文章里一样多搞几个deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib deb https://mirrors.aliyun.com/debian-security/ bookworm-security main deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib# 更新aptupdate2、查看cpu温度aptinstalllm-sensors-ysensors