生成centos7 安装脚本
[root@us-1-217 install]# cat gen7.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, crypt
base_path = '/opt/opmgmt/install'
pxe_path = os.path.join(base_path, 'pxelinux.cfg')
kickstart_path = os.path.join(base_path, 'kickstart')
sitename = 'us.install.suntv.tv'
installhost = '10.150.1.217'
yumhost = 'us.yum.suntv.tv'
hosts = 'hosts.txt'
os = 'centos7'
password = 'password'
rootpw = crypt.crypt(password, '$6$MySalt')
def generate_pxe_file(os, mac, sitename, pxe_path):
pxe = '''default menu.c32
prompt 0
timeout 100
LABEL %s
MENU DEFAULT
MENU LABEL %s
KERNEL %s/vmlinuz
APPEND initrd=%s/initrd.img ks=http://%s/kickstart/%s ksdevice=link ramdisk_size=102400 console=ttyS1,115200
''' % (os, mac, os, os, sitename, mac)
filename = pxe_path + '/01-' + '-'.join(mac.split(':'))
with open(filename, 'w') as f:
f.write(pxe)
print 'generate pxe file: %s' % ('01-' + '-'.join(mac.split(':')))
def generate_kickstart_file(os, sitename, rootpw, kickstart_path, dev, prefix, mac, private_ip, private_mask, public_ip, public_mask, default_gw):
# interface
if dev == 'em':
private_interface = '''cat > /etc/sysconfig/network-scripts/ifcfg-%s1 << _EOF_
DEVICE=%s1
ONBOOT=yes
BOOTPROTO=static
IPADDR=%s
NETMASK=%s
_EOF_
''' % (dev, dev, private_ip, private_mask)
if public_ip != '0' and public_mask !='0':
public_interface = '''cat > /etc/sysconfig/network-scripts/ifcfg-%s2 << _EOF_
DEVICE=%s2
ONBOOT=yes
BOOTPROTO=static
IPADDR=%s
NETMASK=%s
_EOF_
''' % (dev, dev, public_ip, public_mask)
else:
public_interface = ''
if dev == 'eth':
private_interface = '''cat > /etc/sysconfig/network-scripts/ifcfg-%s0 << _EOF_
DEVICE=%s0
ONBOOT=yes
BOOTPROTO=static
IPADDR=%s
NETMASK=%s
_EOF_
''' % (dev, dev, private_ip, private_mask)
if public_ip != '0' and public_mask !='0':
public_interface = '''cat > /etc/sysconfig/network-scripts/ifcfg-%s1 << _EOF_
DEVICE=%s1
ONBOOT=yes
BOOTPROTO=static
IPADDR=%s
NETMASK=%s
_EOF_
''' % (dev, dev, public_ip, public_mask)
else:
public_interface = ''
# network
network = '''cat > /etc/sysconfig/network << _EOF_
NETWORKING=yes
HOSTNAME=%s-%s-%s
GATEWAY=%s
_EOF_
''' % (prefix, private_ip.split('.')[2], private_ip.split('.')[3], default_gw)
# dns
dns = '''cat > /etc/resolv.conf << _EOF_
nameserver 8.8.8.8
nameserver 8.8.4.4
_EOF_
'''
# ssh
ssh = '''sed -i 's/#Port 22/Port 29922/g' /etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/g' /etc/ssh/sshd_config
sed -i 's/#GSSAPIAuthentication no/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
'''
# tcp/ip
tcp_ip = '''cat >> /etc/sysctl.conf << _EOF_
fs.file-max = 100000
#net.ipv4.tcp_syncookies = 1
#net.ipv4.tcp_tw_reuse = 1
#net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65000
#net.ipv4.tcp_max_syn_backlog = 8192
#net.ipv4.tcp_max_tw_buckets = 5000
_EOF_
'''
# limit
limit ='''cat >> /etc/security/limits.conf << _EOF_
* soft nofile 100000
* hard nofile 100000
_EOF_
'''
# hosts
hosts ='''cat >> /etc/hosts << _EOF_
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
%s %s
_EOF_
''' % (installhost, yumhost)
# yum
yum ='''
rm -rf /etc/yum.repos.d/*
curl http://%s/centos6.repo -o /etc/yum.repos.d/centos.repo
curl http://%s/epel.repo -o /etc/yum.repos.d/epel.repo
''' % (yumhost, yumhost)
kickstart = '''text
keyboard us
timezone Asia/Shanghai
lang en_US.UTF-8
skipx
auth --enableshadow --passalgo=sha512
rootpw --iscrypted %s
#zerombr
bootloader --boot-drive=sda --location=mbr
ignoredisk --only-use=sda
clearpart --drives=sda --all
#part swap --fstype='swap' --ondisk=sda --size=8000
part biosboot --fstype='biosboot' --size=1
part / --fstype='xfs' --ondisk=sda --size=50000
part /opt --fstype='xfs' --ondisk=sda --size=1 --grow
network --bootproto=dhcp --device=%s --activate
install
url --url='http://%s/%s'
logging level=info
firewall --disabled
selinux --disabled
firstboot --disabled
services --enabled=network,rc-local --disabled=NetworkManager,postfix
reboot
%%packages
@core
%%end
%%pre
/usr/sbin/parted -s /dev/sda mklabel gpt
%%end
%%post
%s
%s
%s
%s
%s
%s
%s
%s
%s
%%end
''' % (rootpw, mac, sitename, os, private_interface, public_interface, network, dns, ssh, tcp_ip, limit, hosts, yum)
filename = kickstart_path + '/' + mac
with open(filename, 'w') as f:
f.write(kickstart)
print 'generate kickstart file: %s ' % mac
with open(hosts, 'r') as f:
for host in f:
dev, prefix, mac, private_ip, private_mask, public_ip, public_mask, default_gw = host.strip('\n').split(' ')
generate_pxe_file(os, mac.lower(), sitename, pxe_path)
generate_kickstart_file(os, sitename, rootpw, kickstart_path, dev, prefix, mac.lower(), private_ip, private_mask, public_ip, public_mask, default_gw)
生成centos7 安装脚本的更多相关文章
- 用python & bat写软件安装脚本 + HM NIS Edit自动生成软件安装脚本
2019-03-11更新:原来NSIS脚本也可以禁用64位文件操作重定向的! 1.在安装脚本的开始处定义 LIBRARY_X64. !include "MUI.nsh"!inclu ...
- Centos7安装Docker CE
每次安装Docker都要去找文档,或者每次安装的都不一样,还是要好好管理自己的这些东西,下次用的时候可以省很多的时间 Docker的早期版本称为docker或docker-engine:现在的 ...
- Centos7搭建pptp一键安装脚本
废话不多说,先上脚本地址:Centos7一键pptp 使用: wget http://files.cnblogs.com/files/wangbin/CentOS7-pptp-host1plus.sh ...
- centos7 安装docker(手动和脚本安装)换源 卸载
centos7 安装docker(手动和脚本安装)换源 卸载 Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker ...
- centos7 lvm合并分区脚本初探-linux性能测试 -centos7修改网卡名字-jdk环境安装脚本-关键字查询文件-批量添加用户
1.#!/bin/bash lvmdiskscan | grep centos > /root/a.txt a=`sed -n '1p' /root/a.txt` b=`sed -n '2p' ...
- Centos7安装Docker 基于Dockerfile 搭建httpd运行环境
Centos7安装Docker 基于Dockerfile 搭建httpd运行环境 docker docker搭建 docker build 本文档完成目标内容如下 使用Docker搭建http服务器一 ...
- Centos7安装jexus,部署asp.net core,asp.net mvc
什么是Jexus 官网解释:https://www.jexus.org/ Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关,Jexus Web Service,简称JWS,以支持AS ...
- CentOS7安装配置Bacula yum方法
参考: https://www.baidu.com/link?url=o2QIy2YZWjsJPAFJuYFhrH3nPvtyRkSe-o5Q_FqFZ5E1EMOsIOmGeKm0HAonwHOw8 ...
- RHEL7或CentOS7安装11.2.0.4 RAC碰到的问题
RHEL7或CentOS7安装11.2.0.4 RAC碰到的问题 随着Linux 版本的普及,但Oracle数据库主流版本仍是11gR2, 的支持不很完美,在Linux 上安装会遇到几处问题,以此记录 ...
随机推荐
- paraview plot over line
- rest-assured的对象映射(序列化和反序列化)
rest-assured支持映射Java对象到Json和XML以及从Json和XML中映射到Java对象.Json映射需要在classpath 中有Jackson.Jackson 2或者是Gson,X ...
- LeetCode记录之35——Search Insert Position
这道题难度较低,没有必要作说明. Given a sorted array and a target value, return the index if the target is found. I ...
- html的第一个程序
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MySQL 简洁 数据操作 增删改查 记不住的 看这里把
1.库操作====================== 1.创建 CREATE DATABASE DB2 charset utf8; 2.删除 DROP DATABASE db2; 3.使用(进入) ...
- POJ - 3090 gcd水题
大概题意就是求\(1 \le i,j \le n\)的\(gcd(i,j) = 1\)的个数+2(对于0的特判) 正解应该是欧拉函数或者高逼格的莫比乌斯反演 但数据实在太水直接打表算了 /*H E A ...
- [转] 配置文件解析利器-Config库
[From] https://blog.csdn.net/zero__007/article/details/51493851 Typesafe的Config库,纯Java写成.零外部依赖.代码精简. ...
- linux 运维基础之http协议详解
引言 这尼玛博客还得自己在这里写,难受一匹本来排版好的...每次都这样嗨....本内容属于借鉴资源,侵权删! HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系 ...
- 【卷土重来之C#学习笔记】(三) 类型 存储和变量
.c#程序是一组类型声明 ※C#程序或DLL的源代码是一组一种或多种类型声明 ※对于可执行程序,类型声明必须有一个包含Main方法类 ※命名空间是一种把相关的类型声明分组并命名的方法.既然程序是一组相 ...
- Java入门系列-09-循环结构
这篇文章为你搞懂5个问题 while 循环如何使用 do-while 循环的使用 for 循环的使用 break.continue 的使用 循环结构的嵌套使用 生活中有很多事情需要我们重复的去做,比如 ...