[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 安装脚本的更多相关文章

  1. 用python & bat写软件安装脚本 + HM NIS Edit自动生成软件安装脚本

    2019-03-11更新:原来NSIS脚本也可以禁用64位文件操作重定向的! 1.在安装脚本的开始处定义 LIBRARY_X64. !include "MUI.nsh"!inclu ...

  2. Centos7安装Docker CE

      每次安装Docker都要去找文档,或者每次安装的都不一样,还是要好好管理自己的这些东西,下次用的时候可以省很多的时间   Docker的早期版本称为docker或docker-engine:现在的 ...

  3. Centos7搭建pptp一键安装脚本

    废话不多说,先上脚本地址:Centos7一键pptp 使用: wget http://files.cnblogs.com/files/wangbin/CentOS7-pptp-host1plus.sh ...

  4. centos7 安装docker(手动和脚本安装)换源 卸载

    centos7 安装docker(手动和脚本安装)换源 卸载 Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker ...

  5. 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' ...

  6. Centos7安装Docker 基于Dockerfile 搭建httpd运行环境

    Centos7安装Docker 基于Dockerfile 搭建httpd运行环境 docker docker搭建 docker build 本文档完成目标内容如下 使用Docker搭建http服务器一 ...

  7. Centos7安装jexus,部署asp.net core,asp.net mvc

    什么是Jexus 官网解释:https://www.jexus.org/ Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关,Jexus Web Service,简称JWS,以支持AS ...

  8. CentOS7安装配置Bacula yum方法

    参考: https://www.baidu.com/link?url=o2QIy2YZWjsJPAFJuYFhrH3nPvtyRkSe-o5Q_FqFZ5E1EMOsIOmGeKm0HAonwHOw8 ...

  9. RHEL7或CentOS7安装11.2.0.4 RAC碰到的问题

    RHEL7或CentOS7安装11.2.0.4 RAC碰到的问题 随着Linux 版本的普及,但Oracle数据库主流版本仍是11gR2, 的支持不很完美,在Linux 上安装会遇到几处问题,以此记录 ...

随机推荐

  1. Covering(矩阵快速幂)

    Bob's school has a big playground, boys and girls always play games here after school.  To protect b ...

  2. no git binary found in $path(已解决,但是还有疑问)

    跟同行研究个项目代码,他把代码打包发我后,我解压到本地,路径和我本地个人项目路径基本相同, 但是当执行npm install时,就报了 no git binary found in $path ,这个 ...

  3. hdu 2570 贪心

    贪心的经典题型 该死的精度问题,WA了好几次,以后能用乘的绝不用除!! #include<iostream> #include<algorithm> #include<c ...

  4. js实现点击按钮滚动条缓慢滚动到顶部

    toTop:function(){ //toTop 滚动到顶部 var currentPosition,timer; var speed=10; timer=setInterval(function( ...

  5. 《STL详解》解题报告

    看完发现文档缺页...... 3.5  菲波那契数 vector<int> v; v.push_back(); v.push_back(); ;i < ;++i) v.push_ba ...

  6. 使用dd命令写iso文件到u盘

    1. 使用df -h查看挂载点 [seif@study ~]$ df -h 文件系统        容量  已用  可用 已用% 挂载点 udev            1.9G     0  1.9 ...

  7. http请求报头和响应报头(1)

    1.web端不可避免的http缓存机制,要理解缓存机制,先来了解下http的请求报文和响应报文的内容 2.请求报文  2.1请求行    请求行三部分组成:请求方法.URL以及版本协议 请求的方法有G ...

  8. PIXI 宝物猎人(7)

    介绍 ,本实例来自官网 代码结构 打开 treasureHunter.html 文件,你将会看到所有的代码都在一个大的文件里.下面是一个关于如何组织所有代码的概览: //Setup Pixi and ...

  9. svn server配置与TortoiseSVN、Ankhsvn+VS使用

    Svn服务器与客户端安装 1.      下载安装VisualSvn-Server服务端.(过程略)http://subversion.apache.org/packages.html 2.      ...

  10. JSON转C#实体类

    https://www.bejson.com/convert/json2csharp/