13、Centos7初始化脚本
更新于:2024年3月29日
Centos7初始化脚本
脚本位置
wget -qO- https://onedayxyy.cn/scripts/centos7_init_shell/centos7_init_shell-2024.3.29.sh|bash
centos7_init_shell-2024.3.29.sh
#!/bin/bash
#关闭且禁用如下服务:firewalld、NetworkManager、selinux
systemctl stop firewalld && systemctl disable firewalld
systemctl stop NetworkManager && systemctl disable NetworkManager
setenforce 0
sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config
#网络yum配置及常用软件安装
cd /etc/yum.repos.d/
mkdir backup-`date +%F`
mv * !$
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum install -y net-tools
yum install -y vim
yum install -y wget
yum install -y lrzsz
yum install -y tree
yum install -y sl
#配置命令行提示颜色
echo 'PS1="\[\e[1;32m\][\[\e[1;33m\]\u\[\e[35m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\$"' > /etc/profile.d/env.sh
案例:主机名配置
hostnamectl --static set-hostname test
exec bash
useradd hg
useradd xyy
# echo 1234|passwd --stdin root
# echo 1234|passwd --stdin hg
# echo 1234|passwd --stdin xyy
案例:初始化环境配置
关闭且禁用如下服务:firewalld、NetworkManager、selinux
systemctl stop firewalld && systemctl disable firewalld && systemctl stop NetworkManager && systemctl disable NetworkManager
setenforce 0
sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config
案例:网络yum配置及常用软件安装
cd /etc/yum.repos.d/
mkdir backup-`date +%F`
mv * !$
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum install -y net-tools
yum install -y vim
yum install -y wget
yum install -y lrzsz
yum install -y iproute
yum install epel-release -y
yum install sl -y # 安装小火车软件包
案例:自定义.vimrc
vim ~/.vimrc
set ts=4
set expandtab
set ignorecase
set cursorline
set autoindent
set paste
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: hg" )
call setline(5,"#QQ: 2675263825")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#URL: https://www.onedayxyy.cn")
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
autocmd BufNewFile * normal G