首先划分一个分区做swap
fdisk /dev/vdb
分区类型按”t“修改为82 Linux swap,保存
格式化分区 mkswap /dev/vdb2
启动swap分区 swapon /dev/vdb2
查看swap分区UUID blkid
/etc/fstab永久挂载 UUID=04820cf8-90b3-4bf9-8402-071352674b73 swap swap defaults 0 0
查看 free -h
或 swapon -s
首先划分一个分区做swap
fdisk /dev/vdb
分区类型按”t“修改为82 Linux swap,保存
格式化分区 mkswap /dev/vdb2
启动swap分区 swapon /dev/vdb2
查看swap分区UUID blkid
/etc/fstab永久挂载 UUID=04820cf8-90b3-4bf9-8402-071352674b73 swap swap defaults 0 0
查看 free -h
或 swapon -s
环境A,B两台centos7,A ip 192.168.1.2 服务端,B ip 192.168.1.3客户端
##安装
yum install -y nfs-utils rpcbind
## ubuntu :服务端nfs-kernel-server ,客户端nfs-common
##依次启动
systemctl start rpcbind
systemctl start nfs-server
#建立共享目录
mkdir /share
chmod 777 /share
##编辑配置文件 /etc/exports
#括号后默认参数 (ro, root_squash)
#root_squash 当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户
/share 192.168.1.0/24(rw,no_root_squash,async)
##重新读取配置使之生效
systemctl reload nfs-server
##查看
[root@m1 ~]# showmount -e 192.168.1.2
Export list for 192.168.1.2:
/share 192.168.1.0/24
##挂载
[root@m1 ~]# mkdir /mnt/pub
[root@m1 ~]# mount -t nfs 192.168.1.2:/share /mnt/pub
最近查看自己搭建的一台邮件服务器的日志,发现不停的有IP在测试登录密码,就想着把这些恶意连接的IP给封了。记得以前了解有个fail2ban的工具,可以不用从头到脚写脚本,直接简单配置即可实现我的需求,于是就来部署试试。
我的centos7上已经安装了epel源,直接yum安装
yum install fail2ban -y
安装完成后,需要到配置目录(/etc/fail2ban/)做下配置。配置文件功能说明下:
fail2ban.conf 这个是程序运行相关的配置,不用动 jail.conf 这个是系统预装的相关服务检测规则,然后封禁的相关配置,因程序升级会 覆盖此文件,因此需要在同目录新建 jail.local来做个性化配置 jail.d/ 个性化配置也可在此目录下新建文件,效果与jail.local相同 filter.d/ 预置的可以jail的服务
配置文件编写规则说明:
1、默认配置文件jail.conf为总[default] ,分[sshd] [nginx]这种层次 2、个人配置文件jail.local 可以只写具体要jail的服务模块,如[sshd] ,它会自动继承 [defualt]中的所有配置,如果sshd中有default相同的命令,会重写(override)default 中的命令 3、默认所有的jail模块都是未开启的 4、如果要启动sshd 可以只写 [sshd] enabled = true 所有预置的服务(在filter.d/目录下)都可以只写上面格式的两行就可开启对于服务的监控拦截功能
我安装的是fail2ban-0.11.1-10.el7.noarch版本,预装的配置文件[default]如下
[DEFAULT]
ignorecommand =
bantime = 10m
findtime = 10m
maxretry = 5
maxmatches = %(maxretry)s
backend = auto
usedns = warn
logencoding = auto
enabled = false
mode = normal
filter = %(__name__)s[mode=%(mode)s]
destemail = root@localhost
sender = root@
mta = sendmail
protocol = tcp
chain =
port = 0:65535
fail2ban_agent = Fail2Ban/%(fail2ban_version)s
banaction = iptables-multiport
banaction_allports = iptables-allports
action_ = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
action_mw = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
%(mta)s-whois[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s"]
action_mwl = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
%(mta)s-whois-lines[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", logpath="%(logpath)s", chain="%(chain)s"]
action_xarf = %(banaction)s[name=%(__name__)s, port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
xarf-login-attack[service=%(__name__)s, sender="%(sender)s", logpath="%(logpath)s", port="%(port)s"]
action_cf_mwl = cloudflare[cfuser="%(cfemail)s", cftoken="%(cfapikey)s"]
%(mta)s-whois-lines[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", logpath="%(logpath)s", chain="%(chain)s"]
action_blocklist_de = blocklist_de[email="%(sender)s", service=%(filter)s, apikey="%(blocklist_de_apikey)s", agent="%(fail2ban_agent)s"]
action_badips = badips.py[category="%(__name__)s", banaction="%(banaction)s", agent="%(fail2ban_agent)s"]
action_badips_report = badips[category="%(__name__)s", agent="%(fail2ban_agent)s"]
action_abuseipdb = abuseipdb
action = %(action_)s
我的配置文件/etc/fail2ban/jail.local
[sshd]
enabled = true
[sendmail-auth]
enabled = true
[dovecot]
enabled = true
接着运行下面相关命令开启fail2ban,查看相关的状态信息
#开启服务
systemctl start fail2ban
#查看配置
fail2ban-client -d
#重新载入配置
fail2ban-client reload
#查看jail
fail2ban-client status
#查看某个jail状态
fail2ban-client status sshd
更高级些的用法可以添加上面default段的命令来重写,如
[nginx-auth-path]
port = 8080 ;nginx端口为8080
logpath = /usr/local/nginx/logs/errors.log
bantime = 30m ;ban30分钟
maxretry = 6 ;连续错误6次就会被ban
enabled = ture
25: SMTP(Simple Mail Transfer Protocol,简单邮件传输协议),是用于发送邮件,国内公有云服务器都会关闭云主机25端口出去的流量,也就禁止向外发邮件。
110:POP3(Post Office Protocol Version 3,邮局协议3),是用于接收邮件的。
143:IMAP(INTERNET MESSAGE ACCESS PROTOCOL),是用于接收邮件的。区别与110,它可以只收取邮件头
465:SMTPS(SMTP-over-SSL),这是SMTP协议基于SSL安全协议之上的一种变种协议
995:POP3S(POP3-over-SSL),这是POP3协议基于SSL安全协议之上的一种变种协议
993:IMAPS(IMAP-over-SSL),这是IMAP协议基于SSL安全协议之上的一种变种协议
全局配置文件: /etc/logrotate.conf ,单独系统配置文件放置在/etc/logrotate.d/目录下
参数 功能说明 compress 通过gzip 压缩转储以后的日志 nocompress 不需要压缩时,用这个参数 copytruncate 用于还在打开中的日志文件,把当前日志备份并截断;是先拷贝再清空 ,拷贝和清空之间有一个时间差,可能会丢失部分日志数据。 nocopytruncate 备份日志文件但是不截断 create mode owner group 转储文件,使用指定的文件模式创建新的日志文件。轮转时指定创 建新文件的属性,如create 0600 root root nocreate 不建立新的日志文件 delaycompress 和 compress 一起使用时,转储的日志文件到下一次转储时才压缩 nodelaycompress 覆盖 delaycompress 选项,转储同时压缩 ifempty 即使是空文件也转储,这个是 logrotate 的缺省选项。 notifempty 如果日志文件为空时,不转储 errors address 转储时的错误信息发送到指定的Email 地址 mail address 转储的日志文件发送到指定的E-mail 地址 nomail 转储时不发送日志文件 olddir directory 转储后的日志文件放入指定的目录,必须和当前日志文件在同一文件系统 noolddir 转储后的日志文件和当前日志文件放在同一个目录下 prerotate/endscript 在logrotate转储之前需要执行的指令,例如修改文件的属性等动作; 这两个关键字必须单独成行; postrotate/endscript 在logrotate转储之后需要执行的指令,例如重新启动 (kill -HUP) 某个服务!必须独立成行; daily 指定转储周期为每天 weekly 指定转储周期为每周 monthly 指定转储周期为每月 rotate count 指定日志文件删除之前转储的个数,0 指没有备份,5 指保留5个备份 tabootext [+] list 让logrotate不转储指定扩展名的文件,缺省的扩展名是:.rpm-orig, .rpmsave, v, 和 ~ size size当日志文件到达指定的大小时才转储,Size 可以指定 bytes (缺省) 以及KB (sizek)或者MB (sizem). missingok 如果日志丢失,不报错继续滚动下一个日志 sharedscripts 运行postrotate脚本,作用是在所有日志都轮转后统一执行一次脚本。 如果没有配置这个,那么每个日志轮转后都会执行一次脚本 dateext 使用当期日期作为命名格式 dateformat .%s 配合dateext使用,紧跟在下一行出现,定义文件切割后的文件名,必须配 合dateext使用,只支持 %Y %m %d %s 这四个参数 自己测试了%H也可以。 不过如果需要支持分的话logrotate需要升级到3.9版本 ,
#debug测试 -d, --debug Don't do anything, just test (implies -v)
logrotate -d configfile
1、列出多个文件,统一配置策略
#Please note:
#nocreate and copytruncate in configuration file are mutually exclusive and can't be configured at the same time,otherwise nocreate have no effect
#create and copytruncate in configuration file are mutually exclusive and can't be configured at the same time,otherwisecreate have no effect
/var/log/startup.log
/var/log/boot.log
/var/log/backup_conf.log
/var/log/cloud-init-output.log
/var/log/cloud-init.log
/var/log/daemon.log
/var/log/cron.log
/var/log/kern.log
/var/log/syslog
/var/log/unused.log
/var/log/sysmonitor.log
/var/log/tuned/*.log
/var/log/wtmp
/var/log/btmp
{
missingok
compress
notifempty
copytruncate
rotate 10
size +4000k
}
2、多个同目录下多个log 文件
/var/log/openvswitch/*.log {
missingok
notifempty
size 2048k
rotate 10
copytruncate
}
3
# Logrotate file for psacct RPM
/var/account/pacct {
compress
delaycompress
notifempty
daily
rotate 31
create 0600 root root
postrotate
if /usr/bin/systemctl --quiet is-active psacct.service ; then
/usr/sbin/accton /var/account/pacct | /usr/bin/grep -v "Turning on process accounting, file set to '/var/account/pacct'." | /usr/bin/cat
fi
endscript
}
4、mariadb
/var/log/mariadb/mariadb.log {
create 600 mysql mysql
notifempty
daily
rotate 3
missingok
compress
postrotate
# just if mysqld is really running
if [ -e /run/mariadb/mariadb.pid ]
then
kill -1 $(</run/mariadb/mariadb.pid)
fi
endscript
}
mkdir /usr/java/ && tar xf jdk-8u281-linux-x64.tar.gz -C /usr/java/
vim /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_281
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=${JAVA_HOME}/bin:$PATH
source /etc/profile
java -version
wordpress 部署需要环境如下:
centos 8.2 环境下官方yum源只能安装7.2版本php,而php 编译安装比较麻烦,我后面选择的remi的repo,用yum安装,记录如下:
dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module reset php
dnf module install php:remi-7.4
dnf install php-mysqli php-gd php-zip php-imagick
这样wordpress所需的php环境就部署完成了。
1.这是GNU Bash的官方文档:https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion
2. 其中第3.4节讲了Shell参数有两种取法:可定位参数(Positional Parameters)和特殊参数(Special Parameters)
•Positional Parameters:The shell’s command-line arguments. Shell命令行入参
•Special Parameters:Parameters denoted by special characters. 通过特殊字符表示的参数3. 可定位参数(Positional Parameters):
A positional parameter is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters are assigned from the shell’s arguments when it is invoked, and may be reassigned using thesetbuiltin command. Positional parameterNmay be referenced as${N}, or as$NwhenNconsists of a single digit. Positional parameters may not be assigned to with assignment statements. Thesetandshiftbuiltins are used to set and unset them (seeShell Builtin Commands). The positional parameters are temporarily replaced when a shell function is executed (seeShell Functions).
即可以通过非0的数字定位参数,0为命令本身,1,2,3,4,5,,,为命令后面的参数
4. 特殊参数(Special Parameters)
Shell对几个参数特殊对待,下列参数只能被引用,不能被赋值
*
($*)从1开始展开可定位参数, 当使用没有被双引号括起时,每个可定位参数展开一个独立的词。在被使用的时候,
这些词可以被再次分割或路径展开。当有被双引号括起时,它将展开为一个词(也可以理解为合并为一个词),
为"$1c$2C.."形式,c为IFS变量的首字母,如果IFS没有设置,由c为空格,如果IFS为null,则中间没有间隔
@
($@)从1开始展开可定位参数,在被使用的时候,默认展开为独立的多个词,如果没有被双引号括起来,这些词被
用来做单词分割。当没有被做分割使用时,它展开(也理解为合并)为一个由空格拼接出来的一个词。当有被双引号
括起且被单词分割时,每个参数展开为独立的词,即,"$@"等同于"$1" "$2" ...。
(这里有一段话没太理解,和这个问题关系不大,先不翻译了)。
如果没有任何可定位参数,则"$@"和$@展开为无,即它们被删除了。
5. 第3.5.3节讲了Shell参数展开
${parameter:offset}
${parameter:offset:length}
通过这种方式可以截取字符串或数组
If parameter is ‘@’, the result is length positional parameters beginning at offset. A negative offset is taken relative to one greater than the greatest positional parameter, so an offset of -1 evaluates to the last positional parameter. It is an expansion error if length evaluates to a number less than zero.
如果参数为@,则为截取可定位参数数组,从offset开始算,length为取的长度,如果不给,则取到最后。如果offset为负,则为从最后一位倒数,如offset为-1则为最后一个元素。如果offset和length计算得到的长度小于0则会报错
The following examples illustrate substring expansion using positional parameters:
后面为示例
$ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
$ echo ${@:7}
7 8 9 0 a b c d e f g h
$ echo ${@:7:0}
$ echo ${@:7:2}
7 8
$ echo ${@:7:-2}
bash: -2: substring expression < 0
$ echo ${@: -7:2}
b c
$ echo ${@:0}
./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
$ echo ${@:0:2}
./bash 1
$ echo ${@: -7:0}
所以,echo "${@:2}"
,它的意思就是输出入参的第2个至最后一个参数,且以空格分隔,合并为一个单词(word)
转自知乎刘长远的答复:https://www.zhihu.com/question/368661192/answer/991165910
#修改mtime:
touch -mt YYMMDDhhmm filename /****时间格式为年月日时分
#修改atime:
touch -at YYMMDDhhmm filename
#使用find命令查找最近24小时修改过的文件
find $HOME -mtime 0
man find 中关于在mtime后面的数字的说明:
Search for files in your home directory which have been modified in the last twenty-four hours. This command works this way because the time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.
Numeric arguments can be specified as
+n for greater than n,
-n for less than n,
n for exactly n.
重点在上面加黑中的内容:每满24小时计1,多余的会舍去。
比如过去10个小时的改动,因为10小于24,系统自动记录为0,写成find $HOME -mtime 0 格式,就可查找出过去24小时内的改动,自然也包括10小时内的。也可以写成find $HOME -mtime -1
总结如下:
n=0 表示时间是0<=time<24小时
n=1 表示时间是24<=time<48 所以+1至少要48
n=2 表示时间是48<=time<72
…依此类推