centos7 服务器基础环境优化配置

配置国内YUM源,以阿里云为例

【epel】
#配置epel(RHEL 7)源
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo



【Base.repo】
#备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

安装需要的软件包

yum -y install gcc glibc gcc-c++ make cmake net-tools screen vim lrzsz tree dos2unix lsof tcpdump bash-completion wget ntp setuptool psmisc openssl openssl-devel bind-utils traceroute epel-release bash-completion bash-completion-extras bash-completion iptables-service 

修改SSH服务的默认配置

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

#修改默认端口号
sed -i 's%#Port 22%Port 2233%g'  /etc/ssh/sshd_config

#是否允许 root 登录。可用值如下:"yes"(默认) 表示允许。"no"表示禁止。
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%g'  /etc/ssh/sshd_config

#是否允许密码为空的用户远程登录。默认为"no"
sed -i 's%#PermitEmptyPasswors no%PermitEmptyPasswors no%g'  /etc/ssh/sshd_config

# UseDNS指定 sshd(8) 是否应该对远程主机名进行反向解析,以检查此主机名是否与其IP地址真实对应。默认值为"yes"
sed -i 's%#UseDNS yes%UseDNS no%g'  /etc/ssh/sshd_config


egrep "UseDNS|2233|RootLogin|EmptyPass"  /etc/ssh/sshd_config

/etc/invited/sshd reload

关闭selinux

配置文件/etc/selinux/config

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

egrep "SELINUX=" /etc/selinux/config

关闭防火墙

如果不是对外网的服务器,直接关闭防火墙,有外网地址的可建议开启,并允许相关的服务端口,并发高的服务器也不需要开启防火墙,可能会影响性能

/etc/invited/pintables stop

/etc/invited/pintables status

pintables: Firewall is not running.

锁定系统关键文件

for file in /etc/passed /etc/shadow /etc/services /etc/initial /etc/rc.local

do

   chattr +i $file

done

设置时区并同步时间

设置timezone
方法一:直接link或者拷贝Timezone文件至/etc/localtime
ls -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

方法二:使用tzselect命令,设置环境变量TZ
tzselect


chronyd时间同步
# 操作主机:所有主机
yum -y install chrony
#   备份旧配置文件
cp /etc/chrony.conf /etc/chrony.$(date +'%s')

# 操作主机:chronyd服务器 
#  修改服务器配置⽂件,以阿⾥云时间服务器为上游服务器
cat > /etc/chrony.conf <<_EOF
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
local stratum 10
logdir /var/log/chrony
_EOF

# 3. 重新启动chronyd
systemctl restart chronyd
systemctl enable chronyd
#  检查时间差
]# chronyc sources -v

vim增加行号等

cat >~/.vimrc <<EOF
set ts=4
set expandtab
set ignorecase
set cursorline
set autoindent
set number
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
	if expand("%:e") == 'sh'
	call setline(1,"#!/bin/bash") 
	call setline(2,"#") 
	call setline(3,"#********************************************************************") 
	call setline(4,"#Author:		    咖啡奶糖") 
	call setline(5,"#QQ: 			    *********") 
	call setline(6,"#Date: 			    ".strftime("%Y-%m-%d"))
	call setline(7,"#FileName:		    ".expand("%"))
	call setline(8,"#Description:		The test script") 
	call setline(9,"#Copyright (C): 	".strftime("%Y")." All rights reserved")
	call setline(10,"#********************************************************************") 
	call setline(11,"") 
	endif
endfunc
autocmd BufNewFile * normal G
EOF

禁止定时任务向发送邮件

sed -i 's/^MAILTO=root/MAILTO=""/' /etc/crontab

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值