首页 文章 精选 留言 我的

精选列表

搜索[centos],共5623篇文章
优秀的个人博客,低调大师

CentOS文件删除的恢复(rm -rf *)

文件删除,需要进行恢复。 1. lsof 文件刚刚被删除,想要恢复,先尝试lsof. #lsof |grep data.file1 # cp /proc/xxx/xxx/xx /dir/data.file1 2. 如果lsof不能看到文件,那么就需要使用恢复软件进行恢复。 要做的第一件事是立刻卸载被误删除文件所在的分区,或者重新以只读方式挂载此分区。 umount /dev/part 或 mount -o remount,ro /dev/part 删除一个文件,就是将文件inode(inode 是操作系统寻找文件的目录,起到索引作用) 节点中的扇区指针清除,同时,释放这些数据对应的数据块, 而真实的文件还存留在磁盘分区中。但是这些被删除的文件不一定会一直存留在磁盘中,当这些 释放的数据块被操作系统重新分配时,这些被删除的数据就会被覆盖。因此要立刻卸载分区。 3. ext3grep 该工具只能用于ext3文件系统,操作步骤不详细介绍. 1> unmount /dev/part 2> ext3grep /dev/part --ls --inode 2 ##列出可恢复文件信息 3>ext3grep /dev/part --restore-inode N 4>恢复到 RESTORED_FILES/ 更多命令查看 ext3grep --help 4. extundelete 该工具可以恢复ext3,ext4. http://extundelete.sourceforge.net/ 1>fuser -k /dev/part && unmunt /dev/part 2>extundelete --inode 2 /dev/part 3>extundelete --restore-inode 13 /dev/part 4>恢复到 RECOVERD_FILES/ root@grid1 ~]# extundelete --help Usage: extundelete [options] [--] device-file Options: --version, -[vV] Print version and exit successfully. --help, Print this help and exit successfully. --superblock Print contents of superblock in addition to the rest. If no action is specified then this option is implied. --journal Show content of journal. --after dtime Only process entries deleted on or after 'dtime'. --before dtime Only process entries deleted before 'dtime'. Actions: --inode ino Show info on inode 'ino'. --block blk Show info on block 'blk'. --restore-inode ino[,ino,...] Restore the file(s) with known inode number 'ino'. The restored files are created in ./RECOVERED_FILES with their inode number as extension (ie, file.12345). --restore-file 'path' Will restore file 'path'. 'path' is relative to root of the partition and does not start with a '/' The restored file is created in the current directory as 'RECOVERED_FILES/path'. --restore-files 'path' Will restore files which are listed in the file 'path'. Each filename should be in the same format as an option to --restore-file, and there should be one per line. --restore-directory 'path' Will restore directory 'path'. 'path' is relative to the root directory of the file system. The restored directory is created in the output directory as 'path'. --restore-all Attempts to restore everything. -j journal Reads an external journal from the named file. -b blocknumber Uses the backup superblock at blocknumber when opening the file system. -B blocksize Uses blocksize as the block size when opening the file system. The number should be the number of bytes. --log 0 Make the program silent. --log filename Logs all messages to filename. --log D1=0,D2=filename Custom control of log messages with comma-separated Examples below: list of options. Dn must be one of info, warn, or --log info,error error. Omission of the '=name' results in messages --log warn=0 with the specified level to be logged to the console. --log error=filename If the parameter is '=0', logging for the specified level will be turned off. If the parameter is '=filename', messages with that level will be written to filename. -o directory Save the recovered files to the named directory. The restored files are created in a directory named 'RECOVERED_FILES/' by default. 看上面的命令就很容易理解,各个参数的作用。 5.note 1> 对于空文件,不会进行恢复 2> 可以恢复mysql表, 由于myisam是单独3个文件,恢复出来就能使用。 3> 建议innodb,设置innodb_file_per_table 为 ON,这样也就能恢复单表数据。 4> 从上面可以看出,恢复工具这能恢复分区,所以,建议为应用软件单独划区进行安装, 存放数据。

优秀的个人博客,低调大师

修改centos下只读文件的权限

使用chmod命令,为文件提供其他的权限。 如果要给只读文件加上写权限,到文件所在目录下运行终端,输入 sudo chmod a+w filename 下面是chmod的详细介绍,不予赘述。 指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [–help] [–version] mode file… 说明 : Linux/Unix 的档案调用权限分为三级 : 档案拥有者、群组、其他。利用 chmod 可以藉以控制档案如何被他人所调用。 参数 : mode : 权限设定字串,格式如下 : [ugoa…][[+-=][rwxX]…][,…],其中 u 表示该档案的拥有者,g 表示与该档案的拥有者属于同一个群体(group)者,o 表示其他以外的人,a 表示这三者皆是。 + 表示增加权限、- 表示取消权限、= 表示唯一设定权限。 r 表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该档案是个子目录或者该档案已经被设定过为可执行。 -c : 若该档案权限确实已经更改,才显示其更改动作 -f : 若该档案权限无法被更改也不要显示错误讯息 -v : 显示权限变更的详细资料 -R : 对目前目录下的所有档案与子目录进行相同的权限变更(即以递回的方式逐个变更) –help : 显示辅助说明 –version : 显示版本 范例 :将档案 file1.txt 设为所有人皆可读取 : chmod ugo+r file1.txt 将档案 file1.txt 设为所有人皆可读取 : chmod a+r file1.txt 将档案 file1.txt 与 file2.txt 设为该档案拥有者,与其所属同一个群体者可写入,但其他以外的人则不可写入 : chmod ug+w,o-w file1.txt file2.txt 将 ex1.py 设定为只有该档案拥有者可以执行 : chmod u+x ex1.py 将目前目录下的所有档案与子目录皆设为任何人可读取 : chmod -R a+r * 此外chmod也可以用数字来表示权限如 chmod 777 file 语法为:chmod abc file 其中a,b,c各为一个数字,分别表示User、Group、及Other的权限。 r=4,w=2,x=1 若要rwx属性则4+2+1=7; 若要rw-属性则4+2=6; 若要r-x属性则4+1=7。 范例: chmod a=rwx file 和 chmod 777 file 效果相同 chmod ug=rwx,o=x file 和 chmod 771 file 效果相同 若用chmod 4755 filename可使此程序具有root的权限. 指令名称 : chown 使用权限 : root 使用方式 : chmod [-cfhvR] [–help] [–version] user[] file… 说明 : Linux/Unix 是多人多工作业系统,所有的档案皆有拥有者。利用 chown 可以将档案的拥有者加以改变。一般来说,这个指令只有是由系统管理者(root)所使用,一般使用者没有权限可以改变别人的档案拥有者,也没有权限可以自己的档案拥有者改设为别人。只有系统管理者(root)才有这样的权限。 把计 : user : 新的档案拥有者的使用者 IDgroup : 新的档案拥有者的使用者群体(group)-c : 若该档案拥有者确实已经更改,才显示其更改动作-f : 若该档案拥有者无法被更改也不要显示错误讯息-h : 只对于连结(link)进行变更,而非该 link 真正指向的档案-v : 显示拥有者变更的详细资料-R : 对目前目录下的所有档案与子目录进行相同的拥有者变更(即以递回的方式逐个变更)–help : 显示辅助说明–version : 显示版本 范例 : 将档案 file1.txt 的拥有者设为 users 群体的使用者 jessie : chown jessie:users file1.txt 将目前目录下的所有档案与子目录的拥有者皆设为 users 群体的使用者 lamport : chmod -R lamport:users * -rw——- (600) – 只有属主有读写权限。 -rw-r–r– (644) – 只有属主有读写权限;而属组用户和其他用户只有读权限。 -rwx—— (700) – 只有属主有读、写、执行权限。 -rwxr-xr-x (755) – 属主有读、写、执行权限;而属组用户和其他用户只有读、执行权限。 -rwx–x–x (711) – 属主有读、写、执行权限;而属组用户和其他用户只有执行权限。 -rw-rw-rw- (666) – 所有用户都有文件读、写权限。这种做法不可取。 -rwxrwxrwx (777) – 所有用户都有读、写、执行权限。更不可取的做法。 以下是对目录的两个普通设定: drwx—— (700) - 只有属主可在目录中读、写。 drwxr-xr-x (755) - 所有用户可读该目录,但只有属主才能改变目录中的内容。 运行 .sh 文件类型的文件: 用file命令测试一下看是什么类型的 file xxxx.sh 如果是Bourne-Again shell script 可以sh xxxx.sh 或者chmod +x xxxx.sh 再./xxx.sh 一般 .sh 的直接添加x(可执行属性) chmod +x xxx.sh 然后./xxx.sh就可以了 chmod是一个改变用户拥有指定文件的权限的命令.r:只读,w:写,x执行.也可以用数字

优秀的个人博客,低调大师

centos配置mutt和msmtp发送邮件

一、安装mutt 1 yum install mutt -y 二、配置mutt vim /etc/Muttrc 在里面找到下面几行,并将内容修改为你自己的内容(下面几行分布在不同位置,请耐心查找,记得去掉它行首的#号) set from="发送邮件地址" set sendmail="/usr/local/msmtp/bin/msmtp" set use_from=yes set realname="发件人姓名" set editor="vim" 三、下载并解压msmtp wget http://downloads.sourceforge.net/msmtp/msmtp-1.4.30.tar.bz2?big_mirror=0 tar xf msmtp-1.4.30.tar.bz2 根据系统情况,需要安装wget和bzip2 1yuminstallwgetbzip2-y 四、编译msmtp 解压好之后,进入解压目录,并运行如下语句 ./configure --prefix=/usr/local/msmtp make make install 五、配置msmtp cd /usr/local/msmtp mkdir etc cd etc vim msmtprc 在文件里面加入如下内容: defaults #指定log的位置 logfile /usr/local/msmtp/msmtp.log # The SMTP server of the provider. account test # SMTP邮件服务器地址 host smtp.qq.com # 用来发送邮件Email from xxxxx@qq.com auth login # 用来发送邮件的账号账号 user xxxxxx@qq.com # 用来发邮件的账号的登陆密码登陆密码 password 123456 # Set a default account account default: test 保存退出 因为密码是明文的,所以此处最好修改文件的权限:chmod 600 msmtprc 六、测试 根据以上配置配置好之后就可以进行测试,运行一下语句 echo "邮件内容" |mutt -s "邮件主题" 收件者邮箱 一切正常的话,收件者的邮箱是可以接受到邮件的。 七、用途 之所以搭建用来发送邮件的程序,是因为服务器管理中如果需要提示管理员的时候,可以使用发送邮件的方式进行提醒。 比如,每天定时检测磁盘的占用率,如果占用率高的话,便发送邮件提示管理员该来处理一下。 其他用途,各位可以根据你们的需要来自己写脚本。 八、mutt参数 语 法:mutt [-hnpRvxz][-a<文件>][-b<地址>][-c<地址>][-f<邮件文件>][-F<配置文件>][-H<邮件草稿>][-i<文件>][-m<类型>][-s<主题>][邮件地址] 补充说明:mutt是一个文字模式的邮件管理程序,提供了全屏幕的操作界面。 参 数: -a<文件> 在邮件中加上附加文件。 -b<地址> 指定密件副本的收信人地址。 -c<地址> 指定副本的收信人地址。 -f<邮件文件> 指定要载入的邮件文件。 -F<配置文件> 指定mutt程序的设置文件,而不读取预设的.muttrc文件。 -h 显示帮助。 -H<邮件草稿> 将指定的邮件草稿送出。 -i<文件> 将指定文件插入邮件内文中。 -m<类型> 指定预设的邮件信箱类型。 -n 不要去读取程序培植文件(/etc/Muttrc)。 -p 在mutt中编辑完邮件后,而不想将邮件立即送出,可将该邮件暂缓寄出。 -R 以只读的方式开启邮件文件。 -s<主题> 指定邮件的主题。 -v 显示mutt的版本信息以及当初编译此文件时所给予的参数。 -x 模拟mailx的编辑方式。 -z 与-f参数一并使用时,若邮件文件中没有邮件即不启动mutt。

优秀的个人博客,低调大师

Linux(CentOS)下安装Elasticsearch5.0.0

一.ES5.0解压安装到Windows之后(可能)需要进行的设置: 1.如果不设置,直接运行elasticsearch.bat 文件 ,会报错: 2.解决方式 调节 conf/jvm.options 配置文件 这里采取调小ES占用的内存: 默认配置如下图,初始化和最大内存大小为2G 调节为1g 之后再运行bin/elasticsearch.bat文件就可以正常启动了. 二.ES5.0 解压安装到Linux之后需要进行一些设置才能正常使用. 之前一直是在Linux上使用的ES的1.4版本,在Linux上解压就能用,今天尝试使用ES的5.0.0版本. 1.遇到第一个问题:java.lang.RuntimeException: can not run elasticsearch as root 以及解决方式 如果使用Linux的root用户 对ES5.0 解压运行 会报如下错误:java.lang.RuntimeException: can not run elasticsearch as root 错误是说运行ES不能以root用户的身份 ES5之后就不允许用root用户启动了,如果是ES5.0以下的版本可以参考此解决方式:http://blog.csdn.net/u010317005/article/details/52205825 [2017-11-16T23:06:39,263][ERROR][o.e.b.Bootstrap ] Exception java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:96) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:155) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:112) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:103) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.cli.Command.main(Command.java:62) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) [elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:73) [elasticsearch-5.0.0.jar:5.0.0] [2017-11-16T23:06:39,328][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:116) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:103) ~[elasticsearch-5.0.0.jar:5.0.0] 这是出于系统安全考虑设置的条件。由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑,建议创建一个单独的用户用来运行ElasticSearch. 创建elsearch用户组及elsearch用户 groupadd elsearch useradd elsearch -g elsearch -p elasticsearch 更改elasticsearch文件夹及内部文件的所属用户及组为elsearch:elsearch chown -R elsearch:elsearch elasticsearch-5.0.0 切换到elsearch用户再启动(有可能还是会报错,可能的报错以及解决方式见下文) su elsearch #切换账户 cd elasticsearch/bin #进入你的elasticsearch目录下的bin目录 ./elasticsearch 2.遇到的第二个问题:unable to install syscall filter [2017-11-16T23:17:07,043][WARN ][o.e.b.JNANatives ] unable to install syscall filter: java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in at org.elasticsearch.bootstrap.Seccomp.linuxImpl(Seccomp.java:349) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.Seccomp.init(Seccomp.java:630) ~[elasticsearch-5.0.0.jar:5.0.0] at org.elasticsearch.bootstrap.JNANatives.trySeccomp(JNANatives.java:215) [elasticsearch-5.0.0.jar:5.0.0] 报了一大串错误,其实就是一个警告信息. 使用新的Linux版本就不会出现此问题了. 不用理会.... 3.遇到的第三个问题: node validation exception bootstrap checks failed [2017-11-16T23:20:30,812][ERROR][o.e.b.Bootstrap ] [m2M7ykG] node validation exception bootstrap checks failed max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] max number of threads [1024] for user [elsearch] likely too low, increase to at least [2048] max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] [2017-11-16T23:20:30,815][INFO ][o.e.n.Node ] [m2M7ykG] stopping ... [2017-11-16T23:20:30,852][INFO ][o.e.n.Node ] [m2M7ykG] stopped [2017-11-16T23:20:30,852][INFO ][o.e.n.Node ] [m2M7ykG] closing ... [2017-11-16T23:20:30,886][INFO ][o.e.n.Node ] [m2M7ykG] closed 解决方式: 第一步:切换到root用户,编辑limits.conf 添加类似如下内容 vi /etc/security/limits.conf 添加如下内容: (soft nproc和hard nproc也可以设置成65536) * soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096 以上几个参数的解释 ① soft nproc:可打开的文件描述符的最大数(软限制) ② hard nproc:可打开的文件描述符的最大数(硬限制) ③ soft nofile:单个用户可用的最大进程数量(软限制) ④ hard nofile:单个用户可用的最大进程数量(硬限制) 第二步: 使用命令vim /etc/security/limits.d/90-nproc.conf将下图中红框所示位置的值从1024 改成 2048 第三步 使用命令vim /etc/sysctl.conf在最后添加一行数据如下:vm.max_map_count=262144 第四步:修改完后,执行如下命令sysctl -p 这个命令也必须使用root用户, 使用非root用户报错: 4.做了以上修改之后在Linux启动应该可以正常启动.但是如果在通过别的机器来访问启动机器所在的ES的Web页面,会发现访问不到.需要做如下配置: 我们需要编辑其中的elasticsearch.yml 这一文件,使用命令vimelasticsearch.yml 修改network.host和discovery.zen.ping.unicast.hosts的IP,改成当前ip地址(通过ifconfig命令查看)。如果不修改,则只能本地访问(localhost或127.0.0.1) 以上修改就可以远程访问该ES的Web服务. 5.ES的后台启动命令 和 检查ES的启动进程 ElasticSearch后台启动命令 ./elasticsearch -d 查看后台命令是否启动成功 ps aux|grep elasticsearch elsearch 3119 4.6 3.2 3535488 250876 pts/1 Sl 16:50 0:09 /opt/java/jdk1.7.0_75/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/home/py-project/elasticsearc-2.4.0 -cp /home/py-project/elasticsearch-2.4.0/lib/elasticsearch-2.4.0.jar:/home/py-project/elasticsearch-2.4.0/lib/* org.elasticsearch.bootstrap.Elasticsearch start -d elsearch 3254 0.0 0.0 110224 916 pts/1 S+ 16:54 0:00 grep --color=auto elasticsearch 本文转自SummerChill博客园博客,原文链接:http://www.cnblogs.com/DreamDrive/p/7853162.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Centos7 yum rpm命令大全

rpm命令 rpm包,由“-”、“.”构成,包名、版本信息、版本号、运行平台 对已安装软件信息的查询 rpm -qa 查询已安装的软件 rpm -qf 文件名绝对路径 文件名的绝对路径 rpm -ql 软件名 查询已安装的软件包都安装到何处 软件名:rpm包去除平台信息和后缀信息 1 2 rpm -qi 软件名 查询一个已安装软件包的信息 rpm -qc 软件名 查看已安装软件的配置文件 rpm -qd 软件名 查看已安装软件的文档安装位置 rpm -qR 软件名 查看已安装软件依赖包和文件 对未安装软件信息的查询 rpm -qpi rpm文件 查看一个软件包的用途和版本信息 rpm -qpl rpm文件 查看一个软件包所包含的文件 rpm -qpd rpm文件 查看软件包的文档所在位置 rpm -qpc rpm文件 查看软件包的配置文件 rpm -qpR rpm文件 查看软件包的依赖关系 软件包的安装、升级、删除 rpm -ivh rpm文件 安装rpm包 rpm -Uvh rpm文件 更新rpm包 rpm -e 软件名 删除rpm包 rpm -e 软件名 –nodeps 不管依赖关系,强制删除软件 rpm –import 签名文件 导入签名 rpm --import RPM-GPG-KEY 1 2 yum命令 yum= yellow dog updater, modified 主要功能更方便添加、删除、更新rpm包,自动解决依赖性问题,便于管理大量系统的更新问题 同时配置多个资源库(repository)简介的配置文件(/etc/yum.conf自动解决增加或删除rpm包时遇到的依赖性问题,方便保持rpm数据库的一致性) yum安装,rpm -ivh yum-*.noarch.rpm在第一次启用yum之前要先导入系统的RPM-GPG-KEY 第一次使用yum管理软件时,yum会自动下载需要的headers放置在/var/cache/yum目录下 rpm包更新 yum check-update 查看可以更新的软件包 yum update 更新所有的软件包 yum update kernel 更新指定的软件包 yum upgrade 大规模更新升级 rpm包安装和删除 yum install xxx[服务名] 安装rpm包 yum remove xxx[服务名] 删除rpm包 yum缓存信息 yum clean packages 清除缓存的rpm包文件 yum clean headers 清除缓存的rpm头文件 yum clean old headers 清除缓存中旧的头文件 yum clean all 清除缓存中旧的rpm头文件和包文件 查询软件包信息 yum list 列出资源库中所有可以安装或更新的rpm包 yum list firefox* 列出资源库中可以安装、可以更新、已安装的指定rpm包 yum list update 列出资源库中可以更新的rpm包 yum list installed 列出所有已安装的rpm包 yum list extras 列出已安装但不包含在资源库中rpm包 ps:通过网站下载安装的rpm包 1 2 yum info 列出资源库中所有可以安装或更新的rpm包信息 yum info firefox* 列出资源库可以安装或更新的指定的rpm的信息 yum info update 列出资源库中可以更新的rpm包信息 yum info installed 列出已安装的所有rpm包信息 yum info extras 列出已安装到时不包含在资源库中rpm包信息 yum search firefox 搜索匹配特定字符的rpm包 yum provides firefox 搜索包含特定文件的rpm包

优秀的个人博客,低调大师

Centos 7 下安装 jdk rpm包

1.下载 jdk-8u101-linux-x64.rpm http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.上传到服务器 通过 rz -e 命令,上传到服务器, 如果没有 rz 命令,则通过 yum -y install lrzsz 命令安装 rz 命令. 3. 解压安装 rpm -ivh jdk-6u32-linux-i586-rpm 4.设置环境变量 #vi /etc/profile 在最后面加入 #set java environment JAVA_HOME=/usr/java/jdk1.8.0_101 CLASSPATH=.:$JAVA_HOME/lib/tools.jar PATH=$JAVA_HOME/bin:$PATH export JAVA_HOME CLASSPATH PATH 启用该设置 . /etc/profile (点后边有个空格) 5.在终端使用echo命令检查环境变量设置情况 #echo $JAVA_HOME #echo $CLASSPATH #echo $PATH 6.检查JDK是否安装成功 #java -version 如果看到JVM版本及相关信息,即安装成功!

优秀的个人博客,低调大师

CentOS自动删除n天前日志

linux是一个很能自动产生文件的系统,日志、邮件、备份等。虽然现在硬盘廉价,我们可以有很多硬盘空间供这些文件浪费,让系统定时清理一些不需要的文件很有一种爽快的事情。不用你去每天惦记着是否需要清理日志,不用每天收到硬盘空间不足的报警短信,想好好休息的话,让我们把这个事情交给机器定时去执行吧。 1.删除文件命令: find对应目录-mtime+天数-name"文件名"-execrm-rf{}\; 实例命令: find/opt/soft/log/-mtime+30-name"*.log"-execrm-rf{}\; 说明: 将/opt/soft/log/目录下所有30天前带".log"的文件删除。具体参数说明如下: find:linux的查找命令,用户查找指定条件的文件; /opt/soft/log/:想要进行清理的任意目录; -mtime:标准语句写法; +30:查找30天前的文件,这里用数字代表天数; "*.log":希望查找的数据类型,"*.jpg"表示查找扩展名为jpg的所有文件,"*"表示查找所有文件,这个可以灵活运用,举一反三; -exec:固定写法; rm-rf:强制删除文件,包括目录; {}\;:固定写法,一对大括号+空格+\+; 2.计划任务: 若嫌每次手动执行语句太麻烦,可以将这小语句写到一个可执行shell脚本文件中,再设置cron调度执行,那就可以让系统自动去清理相关文件。 2.1创建shell: touch/opt/soft/bin/auto-del-30-days-ago-log.sh chmod+xauto-del-30-days-ago-log.sh 新建一个可执行文件auto-del-30-days-ago-log.sh,并分配可运行权限 2.2编辑shell脚本: viauto-del-30-days-ago-log.sh 编辑auto-del-30-days-ago-log.sh文件如下: #!/bin/sh find/opt/soft/log/-mtime+30-name"*.log"-execrm-rf{}\; ok,保存退出(:wq)。 2.3计划任务: #crontab-e 将auto-del-30-days-ago-log.sh执行脚本加入到系统计划任务,到点自动执行 输入: 100***/opt/soft/log/auto-del-7-days-ago-log.sh>/dev/null2>&1 这里的设置是每天凌晨0点10分执行auto-del-7-days-ago-log.sh文件进行数据清理任务了。 完成以上三步,你就再也不每天惦记是否硬盘空间满了,该清理日志文件了,再也不会受到服务器硬盘空间不足的报警信息了,放心的去看书喝咖啡去吧!

优秀的个人博客,低调大师

CentOS 集群 NTP 时钟同步配置教程

1. 安装 NTP 软件 (集群所有机器) [plain]view plain copy #yum-yinstallntp 2. 配置 NTP Server (NTP 服务提供主机) 2.1 设置 NTP 服务开机自启动 [plain]view plain copy #systemctlenablentpd #systemctlstartntpd 2.2 编辑/etc/ntp.conf 配置文件 注释掉默认的server,添加本地server,然后重启服务 [plain]view plain copy #systemctlrestartntpd 3. 配置 NTP Client (NTP服务使用主机) 3.1 禁用 NTP 服务 [plain]view plain copy #systemctldisablentpd #systemctlstopntpd 3.2 使用定时器作定期时间同步 [plain]view plain copy #vim/etc/crontab 每隔10分钟同步一次时钟,配置如下: [plain]view plain copy */10****rootntpdate<你的NTP服务提供主机IP>&&hwclock-w 重启 crond 服务 [plain]view plain copy #systemctlrestartcrond 至此,Client 机器的时钟会定期向 Server 同步,以保证整个集群时间一致!

优秀的个人博客,低调大师

CentOS 集群 ssh 免密码登录配置

1. 更新 Hosts 文件 更新集群节点 /etc/hosts 文件,确保所有机器能够通过 hostname 互相访问 2. ssh 初始化配置 [plain]view plain copy #ssh-keygen-trsa-f/root/.ssh/id_rsa-P'' #cat/root/.ssh/id_rsa.pub>>/root/.ssh/authorized_keys #sed's@session\s*required\s*pam_loginuid.so@sessionoptionalpam_loginuid.so@g'-i/etc/pam.d/sshd [plain]view plain copy #vim/root/.ssh/config [plain]view plain copy Host* StrictHostKeyCheckingno UserKnownHostsFile=/dev/null [plain]view plain copy #cp/root/.ssh/config/etc/ssh/ssh_config 3. ssh 免密码配置 将登录端机器的id_rsa.pub 公钥文件复制到各个被登录端机器, 并将内容追加到被登录端机器的 authorized_keys 中 [plain]view plain copy #cat<登录端id_rsa.pub>>>/root/.ssh/authorized_keys 至此,登录端机器就可以通过执行 ssh <被登录端主机名> 免密码登录了。

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

用户登录
用户注册