最小化安装CentOS7后,初始化系统脚本
- 配置好yum源
- 安装常用软件包
- 关闭防火墙,selinux
- 优化sshd服务
- 设置vim的配置文件
- 设置默认编辑器
- 设置hosts文件
#!/bin/bash
#
installsoftware(){
yum install -y vim-enhanced tcpdump lrzsz tree telnet \
bash-completion net-tools wget bzip2 lsof tmux man-pages zip \
unzip nfs-utils gcc make gcc-c++ glibc glibc-devel \
pcre pcre-devel openssl openssl-devel systemd-devel \
zlib-devel yum-utils psmisc bind bind-utils
}
configurerepo(){
cd /etc/yum.repos.d/
rename .repo .repo.bak *
cat <<-EOF > `hostname`.repo
[local]
name=local repository
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever
[aliyun]
name=aliyun repository
baseurl=https://mirrors.aliyun.com/centos/\$releasever/opstools/\$basearch/
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-\$releasever
[aliyun_epel]
name=aliyun repository
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-\$releasever
EOF
yum clean all
yum repolist
}
disable_firewall_selinux(){
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i.bak -r '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
}
optimization_ssd(){
sed -i.bak -r '$a\UseDNS no\nGSSAPIAuthentication no' /etc/ssh/sshd_config
systemctl restart sshd
}
optimization_vim(){
cat <<-EOF > ~/.vimrc
set ts=2
set ai
set cursorline
set ic
EOF
}
optimization_env(){
echo "export EDITOR=vim" >> /etc/profile.d/env.sh
source /etc/profile.d/env.sh
}
optimization_hosts(){
echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
}
if [ ! -d /mnt/cdrom ];then
mkdir /mnt/cdrom
fi
echo "/dev/sr0 /mnt/cdrom iso9660 defaults 0 0" >> /etc/fstab
mount -a
configurerepo
installsoftware
disable_firewall_selinux
optimization_ssd
optimization_vim
optimization_env
optimization_hosts