————————————————

CentOS7初始化脚本

#!/bin/bash
#CentOS7初始化脚本,需要自行修改部分参数(此脚本适合虚拟机部署使用,业务场景尽量不建议使用)
# set ip 
nmcli connection modify ens33 ipv4.addresses 192.168.35.30/24
nmcli connection modify ens33 ipv4.gateway 192.168.35.2
nmcli connection modify ens33 ipv4.dns 114.114.114.114
nmcli connection modify ens33 ipv4.method manual
nmcli connection up ens33 
echo -e "\033[32m-----------------------------------ip_ipaddrss changed !!!--------------------------------------\033[0m" 

#set hostname
ipaddress=` ifconfig ens33 |grep -w inet |tr -s " "|cut -d " " -f3`
last_num=`echo  $ipaddress |cut -d "." -f4`
hostname=`hostnamectl set-hostname host$last_num`
echo -e "hostname: `hostname`"
echo -e  "\033[32m-----------------------------------hostname changed !!!--------------------------------------\033[0m" 

#set yum source
cd /etc/yum.repos.d
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo  http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all && yum clean metadata && yum clean dbcache && yum makecache  
yum -y install tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop iotop sysstat nethogs vim -y
				   
echo -e "\033[32m -----------------------------------yum repo changed !!!--------------------------------------\033[0m"

#stop firewalld 
systemctl stop firewalld 
systemctl disable firewalld
echo -e "\033[32m -----------------------------------firewalld status changed !!!--------------------------------------\033[0m"

#disable selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo -e "\033[32m -----------------------------------selinux status changed !!!--------------------------------------\033[0m"

posted @ 2022-10-10 16:21  Tjane'Blogs  阅读(53)  评论(0)    收藏  举报