Linux:对新机器进行初始化设置的脚本
2020-08-26 13:59
1341 查看
初始化
学习Linux过程中,经常要新建虚拟机,新建虚拟机后,又要重新配置yum源等。最好的解决办法当然是克隆已经配置好的虚拟机。以下是一些基础的配置,放到虚拟机直接执行即。
#!/bin/bash echo "本次配置适用于Redhat7 CentOS7的物理机。公有云不可使用!其他版本系统慎用!" #将IP地址修改为静态 read -p "请输入你的IP(最后一位即可,默认192.168.186.xxx): " ip read -p "请输入你的主机名:" host_name sed -i 's/\<dhcp\>/none/' /etc/sysconfig/network-scripts/ifcfg-ens33 sed -i "$ a IPADDR=192.168.186.${ip}\nNETMASK=255.255.255.0\nDNS=223.6.6.6\nGATEWAY=192.168.186.2" /etc/sysconfig/network-scripts/ifcfg-ens33 ifdown ens33;ifup ens33 #添加DNS解析 sed -i '/^nameserver/d' /etc/resolv.conf echo "nameserver 223.6.6.6" >> /etc/resolv.conf #配置yum源 yum -y install wget > /dev/null mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo yum clean all yum makecache #配置epel源 find /etc/yum.repos.d/ -name "epel*"|xargs -i mv {} {}.bak wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel* sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* yum clean all yum makecache #永久修改主机名 echo "${host_name}" >/etc/hostname #永久关闭防火墙 SeLinux systemctl stop firewalld systemctl disable firewalld setenforce 0 >> /dev/null sed -i.bak 's/enforcing$/disabled/' /etc/selinux/config #ntp对时 yum -y install ntp-4.2.6p5-29.el7.centos.2.x86_64 ntpdate ntp.aliyun.com #是否重启 read -p "初始化完成,部分配置需重启生效。现在重启?[y]" reply [ $reply == "y" ] && reboot || echo "请您稍后手动重启。【reboot】"
相关文章推荐
- Linux、Centos设置启动脚本没有结束,导致无法开启机器
- 通过linux的shell脚本批量创建用户名,用户名所属目录,设置对应密码
- 初始化脚本【Linux运维之道之脚本案例】
- 【Linux开发】Linux启动脚本设置
- Linux网络服务与shell脚本——Linux网络设置与基础服务1(DHCP)
- 设置Linux用户连续N次输入错误密码进行登陆时,自动锁定X分钟
- 新建Linux虚拟机初始化网络等设置
- Linux下如何进行FTP设置
- Linux下如何进行FTP设置
- 浅谈Linux环境下,为什么设置用户ID位对shell脚本无效
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- linux脚本实现自动发送和收取邮件的设置方法
- 快速设置Linux路由脚本
- Linux下如何进行FTP设置
- Linux-crontab定时执行sh脚本进行数据库备份
- WMware设置linux虚拟机访问window机器
- 【转】使用Shell脚本对Linux系统和进程资源进行监控
- Linux下设置定期执行脚本
- 对java类进行初始化设置,默认设置String类型为空串""
- linux自定义初始化脚本