700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Linux shell脚本 服务器系统配置初始化

Linux shell脚本 服务器系统配置初始化

时间:2023-11-24 22:51:54

相关推荐

Linux shell脚本 服务器系统配置初始化

一、 服务器系统配置初始化

背景 新购买10台服务器并已安装linux操作

需求 :

设置时区并同步时间禁用selinux清空防火墙默认策略历史命令显示操作时间禁用root远程登录禁止定时任务发送邮件设置最大打开文件数减少Swap使用系统内核参数优化安装系统性能分析工具及其他

在centos8上安装ntpdate,报错No match for argument: ntpdate

在 centos 8 中, ntp 已经被 chrony 代替。

之前的版本:yum install -y ntp

centos8:yum install chrony

#/bin/bash# 设置时区并同步时间ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtimeif ! crontab -l | grep chronyc &>/dev/null ; then(echo "* 1 * * * chronyc -a makestep >/dev/null 2>&1"; crontab -l) | crontabfi# 禁用selinuxsed -i '/SELINUX/{s/permissive/disabled/}' /etc/selinux/config# 关闭防火墙if egrep "7.[0-9]" /etc/redhat-release &>/dev/null; thensystemctl stop firewalldsystemctl disable firewalldelif egrep "6.[0-9]" /etc/redhat-release &>/dev/null; thenservice iptables stopchkconfig iptables offfi# 历史命令显示操作时间if ! grep HISTTIMEFORMAT /etc/bashrc; thenecho 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/bashrcfi# ssh超时时间if ! grep "TMOUT=600" /etc/brofile &>/dev/null; thenecho "export TMOUT=600" >> /etc/profilefi# 禁止root远程登录sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config# 禁止定时任务发送邮件sed -i 's/^MAILTO=root/MAILTO=""/' /etc/crontab# 设置最大打开文件数if ! grep "* soft nofile 65535" /etc/security/limits.conf &>/dev/null; thencat >> /etc/security/limits.conf << EOF* soft nofile 65535* haed nofile 65535EOFfi# 系统内核优化cat >> /etc/sysctl.conf << EOFnet.ipv4.tcp_syncookies = 1net.ipv4.tcp_max_tw_buckets = dev_max_backlog = 262144nwt.ipv4.tcp_fin_timeout = 20EOF# 减少SWAP使用echo "0" > /proc/sys/vm/swappiness# 安装系统性能分析工具及其他yum install gcc make autoconf vim sysstat net-tools iostat iftop iotp lrzsz -y

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。