配置脚本

基于Centos 8的配置脚本

#!/bin/bash
RELEASE=`cat /etc/redhat-release |sed -rn 's/.*([[:digit:]]+)\..*\..*/\1/p'`
disable_selinux(){
    sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config && echo "SElinux已禁用,重新启动后才可生效" || { echo SELINUX禁用失败; exit 10; }
}

disable_firewall(){
    systemctl disable --now firewalld &> /dev/null && echo "防火墙已禁用" || { echo 防火墙禁用失败; exit 20; }
}

set_ps1() {
    cat > /etc/profile.d/env.sh << EOF
alias cdnet="cd /etc/sysconfig/network-scripts"
alias editnet="vim /etc/sysconfig/network-scripts/ifcfg-eth0"
alias vimeth='vim /etc/sysconfig/network-scripts/ifcfg-eth0'
alias scandisk="for i in {0..32};do echo '- - -' > /sys/class/scsi_host/host\$i/scan;done"
PS1='\[\e[1;33m\][\u@\h \W]\\$\[\e[0m\]'
export PATH=/apps/bin:$PATH
EOF

bash /etc/profile.d/env.sh      #set_ps1执行不成功
}

set_eth(){
    sed -i.bak '/GRUB_CMDLINE_LINUX=/s#"$# net.ifnames=0"#' /etc/default/grub
    grub2-mkconfig -o /boot/grub2/grub.cfg &> /dev/null
    echo "网络名称已修改成功,请重新启动才能生效"
}

set_vim(){
    cat > ~/.vimrc << EOF
set ts=4
set expandtab
set ignorecase
set cursorline
set autoindent
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:                cuiqnghe")
       call setline(5,"#QQ:                    1433236299")
       call setline(6,"#Date:                  ".strftime("%Y-%m-%d"))
       call setline(7,"#FileName:             ".expand("%"))
       call setline(8,"#URL:                   http://www.cuiqinghe.com")
       call setline(9,"#Description:          The test script")
       call setline(10,"#Copyright (C):        ".strftime("%Y")." All rights reserved")
       call setline(11,"#********************************************************************")
       call setline(12,"")
       endif
endfunc
EOF
}

set_hostinfo(){      
    echo "主机名:       `hostname`"
    echo "IP地址:       `ifconfig eth0|sed -rn  '/inet\>/s/[^0-9]+([0-9.]+).*/\1/p'`"
    echo "系统版本:     `cat /etc/redhat-release |cut -d. -f1-2`"
    echo "内核版本:      `uname -r`"
    echo "CPU型号:      `lscpu |sed -nr "/Model name:/s/^(.*): (.*)$/\2/p" |tr -s " "`"
    echo "内存空间:     `free -mh|head -2|tail -1|tr -s ' '|cut -d' ' -f2 `"
    echo "硬盘空间:     `fdisk -l|head -2|tail -1|cut -d, -f1|cut -d' ' -f2-4`"
}

set_ifcfg_eth0(){
	cd /etc/sysconfig/network-scripts ;rm -f ifcfg-ens*
	cat > ifcfg-eth0 << EOF
DEVICE=eth0
NAME=eth0
IPADDR=10.0.0.8
PREFIX=24
GATEWAY=10.0.0.2
DNS1=180.76.76.76
DNS2=223.6.6.6
BOOTPROTO=static
EOF
}

set_yum() {
	mkdir /etc/yum.repos.d/backup
	mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
	cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/BaseOS/\$basearch/os/
#baseurl=file:///misc/cd/   #本地仓库
gpgcheck=0

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/
#https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
gpgcheck=0
enabled=1

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/os/
gpgcheck=0
enabled=1

[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/centos/\$releasever/AppStream/\$basearch/os/
gpgcheck=0
EOF
}

set_app() {
	yum repolist &> /dev/null
	yum install -y gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree tmux lsof tcpdump wget net-tools iotop bc bzip2 zip unzip nfs-utils man-pages &> /dev/null || { echo 安装失败 ;exit 1; }
}

while :;do
echo "***********************系统初始化设置脚本************************"
echo -e "  1.关闭SELINUX                                               "
echo -e "  2.关闭防火墙                                                "
echo -e "  3.别名和提示符设置                                          "
echo -e "  4.网卡更名为eth0                                            "
echo -e "  5.生成脚本基本格式                                          "
echo -e "  6.显示当前主机信息                                          "
echo -e "  7.修改网卡地址                                              "
echo -e "  8.制作yum仓库                                               "
echo -e "  9.下载常用安装包                                            "
echo -e "  10.全都要                                                   "
echo -e "  0.退出脚本                                                  "
echo "+**************************************************************+"

read -p "请输入您的选项:" option
case $option in

1)
    disable_selinux
    ;;
2)
    disable_firewall
    ;;
3)
    set_ps1
    ;;
4)
    set_eth
    ;;
5)
    set_vim
    ;;
6)
    set_hostinfo
    ;;
7)
	set_ifcfg_eth0
	;;
8)
	set_yum
	;;
9)
    set_app
	;;
10)
	disable_selinux
    disable_firewall
    set_ps1
    set_eth
	set_vim
	set_hostinfo
	set_ifcfg_eth0
	set_yum
	set_app
    ;;
0)
    break
    ;;
*)
    echo "请输入正确的数字"
esac
done
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值