centos7 系统初始化脚本怎么写
在安装完系统之后,我们需要对系统进行一些初始化设置。常见的初始化设置包括:
1. 设置主机名
2. 设置时区
3. 设置网络
4. 安装常用软件
下面我们就来介绍一下如何编写一个初始化脚本来完成这些设置。
首先,我们需要创建一个脚本文件,例如可以命名为“init.sh”。在这个脚本文件中,我们可以使用“echo”命令来输出一些提示信息,例如:
echo "This is a script for initializing the system."
echo "Please enter the hostname for the system:"
read hostname
echo "Please enter the timezone for the system:"
read timezone
然后我们可以使用“hostnamectl”命令来设置主机名:
hostnamectl set-hostname $hostname
使用“timedatectl”命令来设置时区:
timedatectl set-timezone $timezone
接下来我们需要配置网络。如果是使用DHCP获取IP地址,我们可以直接使用“nmcli”命令来进行配置:
nmcli con mod enp0s3 ipv4.method auto
nmcli con up enp0s3
如果需要手动配置IP地址,我们可以使用“ifconfig”命令来进行配置:
ifconfig enp0s3 192.168.1.100 netmask 255.255.255.0
route add default gw 192.168.1.1
最后,我们可以使用“yum”命令来安装常用软件:
yum install -y wget
yum install -y vim
yum install -y net-tools
yum install -y tree
这样我们就可以使用“./init.sh”命令来执行这个脚本文件来对系统进行初始化设置了。
相关文章