Centos系统初始化脚本

包括如下内容:

修改主机名

修改ip地址,需要手动将脚本中网关改成自己网关

关闭防护墙,selinux

主机名和ip地址解析

将本地源换成阿里源

安装常用软件,时间同步

注意:安装时间可能过长,请耐心等待,如果是xshell远程连接中运行此脚本,会导致网卡刷新断开xshell连接,建议在虚拟机中运行

#!/bin/bash

# 主机名初始化
read -p "please input hostname: " hostname
hostnamectl set-hostname $hostname

# IP地址初始化
read -p "please input ip address: " ip_address

cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="none"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=$ip_address
PREFIX=24
GATEWAY=192.168.140.2
DNS1=223.6.6.6
DNS2=114.114.114.114
EOF

nmcli connection reload &> /dev/null
nmcli connection up ens33 &> /dev/null
if [ $? -eq 0 ];then
    echo "set $ip_address success!"
else
    echo "set $ip_address failure!"
    exit 66
fi
# 主机名和IP地址解析
hostname=$(hostname)
ip_address=$(hostname -I | awk '{print $1}')
echo "$ip_address   $hostname" >> /etc/hosts

# 永久关闭iptables
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld &> /dev/null
if [ $? -eq 0 ];then
    echo "firewalld is not stop "
else
    echo "firewalld is stopped"
fi
# 永久关闭SELinux
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

#将本地yum源换成阿里源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 

#下载常用软件
yum install -y wget net-tools vim-enhanced bash-completion lftp psmise unzip bzip2 tree 

#时间同步
yum install -y ntpdate &> /dev/null
(crontab -l 2>/dev/null; echo "*/30 * * * *    /usr/sbin/ntpdate 120.25.115.20 &> /dev/null") | crontab -

#ssh端口改为44444,禁用root用户
#sed -i '/#Port/c \Port 44444' /etc/ssh/sshd_config
#sed -i '/#PermitRootLogin/c \PermitRootLogin no ' /etc/ssh/sshd_config

echo "系统初始化完成。"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值