CentOS7优化系统

作者: oldboy 分类: Yum 发布时间: 2022-07-05 13:42
yum install -y wget vim bash-completion lrzsz net-tools nfs-utils yum-utils rdate ntpdate
PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"
echo 'PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"' >>/etc/profile
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >>/etc/bashrc
echo -e "ClientAliveInterval 30 \nClientAliveCountMax 86400" >>/etc/ssh/sshd_config
#sed -i '/#Port 22/a Port 52113' /etc/ssh/sshd_config
service sshd restart
#rdate -s time.nist.gov
ntpdate 61.160.213.184
clock -w
echo "0 */1 * * * /usr/sbin/ntpdate 61.160.213.184 &> /dev/null" >> /var/spool/cron/root
#echo "0 */1 * * * /usr/bin/rdate -s time.nist.gov &> /dev/null" >> /var/spool/cron/root
mkdir /etc/yum.repos.d/bak
\mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak  
wget -O /etc/yum.repos.d/CentOS-Base.repo   http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo   http://mirrors.aliyun.com/repo/epel-7.repo
sed -ri 's@(.*aliyuncs)@#\1@g' /etc/yum.repos.d/CentOS-Base.repo
yum clean all
yum makecache 
#yum update -y --exclude=kernel* --exclude=centos-release* --skip-broken
echo 'LANG="en_US.UTF-8"' >/etc/locale.conf
. /etc/locale.conf
echo "net.ipv4.ip_forward = 1" >>/etc/sysctl.conf
sysctl -p
sed -i '/UseDNS/a UseDNS no' /etc/ssh/sshd_config
systemctl restart  sshd
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -ri 's#^(SELINUX=).*$#\1disabled#g' /etc/selinux/config
setenforce 0
systemctl stop NetworkManager
systemctl disable NetworkManager

提示符达到这个效果:

PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"
echo 'PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"' >>/etc/profile

让历史记录显示操作时间及用户(需要注销重新登录)

echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >>/etc/bashrc

镇江机房zkeys控制器的服务器优化:

yum install -y wget vim bash-completion lrzsz net-tools nfs-utils yum-utils rdate ntpdate
PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"
echo 'PS1="\[\e[1;32m\][\t \[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"' >>/etc/profile
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >>/etc/bashrc
echo -e "ClientAliveInterval 30 \nClientAliveCountMax 86400" >>/etc/ssh/sshd_config
sed -i '/Port 22/a Port 52113' /etc/ssh/sshd_config
service sshd restart
rdate -s time.nist.gov
clock -w
#echo "0 */1 * * * /usr/bin/rdate -s time.nist.gov &> /dev/null" >> /var/spool/cron/root
mkdir /etc/yum.repos.d/bak
\mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak  
wget -O /etc/yum.repos.d/CentOS-Base.repo   http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo   http://mirrors.aliyun.com/repo/epel-7.repo
sed -ri 's@(.*aliyuncs)@#\1@g' /etc/yum.repos.d/CentOS-Base.repo
yum clean all
yum makecache 
echo 'LANG="en_US.UTF-8"' >/etc/locale.conf
. /etc/locale.conf
echo "net.ipv4.ip_forward = 1" >>/etc/sysctl.conf
sysctl -p
sed -i '/UseDNS/a UseDNS no' /etc/ssh/sshd_config
systemctl restart  sshd
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -ri 's#^(SELINUX=).*$#\1disabled#g' /etc/selinux/config
setenforce 0
systemctl stop NetworkManager
systemctl disable NetworkManager
#启用防火墙并限制只能办公室的IP地址能登录ssh
systemctl enable --now firewalld
firewall-cmd --zone=public --permanent --add-rich-rule='rule family=ipv4 source address=61.160.202.235 port port=52123 protocol=tcp accept'
firewall-cmd --reload
#设置服务器名称要修改
hostnamectl set-hostname zj135zkeys

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

2条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

标签云