CentOS 7.6 初始化脚本

自己安装的系统,根据自己需求做一些统一的初始化设置

#! /bin/sh
# 更新系统
yum -y update

# 安装基础软件
yum -y install net-tools lrzsz wget vim

# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld

# 关闭selinux,把selinux状态改为disabled
getenforce
setenforce 0 
sed -i 's/^SELINUX=.*$/SELINUX=disabled/g' /etc/selinux/config
getenforce

# 把服务器的时间改成统一的时区
timedatectl set-timezone Asia/Shanghai

# 配置docker源
cd /etc/yum.repos.d
if [ ! -f docker-ce.repo ];then
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
fi

# 配置kubernetes源
cat >> /etc/yum.repos.d/kubernetes.repo << EOF 
[kubernetes]
name=Kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
enabled=1
EOF

#配置epel源
设置centos7的YUM源为国内阿里云源epel源
cd /etc/yum.repos.d/
if [ ! -f epel-7.repo ];then
wget http://mirrors.aliyun.com/repo/epel-7.repo
fi

# 配置nginx源
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 
#下面的方式貌似有点问题
#cat >> /etc/yum.repos.d/nginx.repo << EOF 
#[nginx]
#name=nginx repo
#baseurl=http://nginx.org/packages/centos/7/$basearch/
#gpgcheck=0
#enabled=1
#EOF

# 加载源配置
yum clear all
yum makecache

# 给admin设置管理员权限
STR_NAME="admin    ALL=(ALL)       NOPASSWD: ALL"
if grep -Fxq "$STR_NAME" /etc/sudoers
then
    echo "admin had has the administrator right"
else
    echo "admin    ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
fi

grep "$STR_NAME" /etc/sudoers

# 禁止root账户直接登录,关闭UseDNS,加速ssh连接
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
grep PermitRootLogin /etc/ssh/sshd_config
grep UseDNS /etc/ssh/sshd_config
systemctl restart sshd

 

posted @ 2020-08-13 10:44  康康路马  阅读(234)  评论(0编辑  收藏  举报