zoukankan      html  css  js  c++  java
  • python配置主机名

    1、准备hosts模板
    
    mkdir -p /k8s/profile
    
    cat >/k8s/profile/hosts<<EOF
    192.168.0.91 test1
    192.168.0.92 test2
    192.168.0.93 test3
    EOF
    
    
    2、编写脚本
    
    cat > hostname.py <<EOF 
    #!/usr/bin/python
    #-*- codinig: UTF-8 -*-
    from __future__ import print_function
    import os
    import shutil
    import tarfile
    import subprocess
    
    def hostname_format():
        subprocess.call(["hostnamectl set-hostname test1"], shell=True)
        #配置hosts解析
        ms=open("/k8s/profile/hosts")
        for line in ms.readlines():
            with open('/etc/hosts','a+') as mon:
                mon.write(line)
        ms.close()
        subprocess.call(["sed -i '$ahostname=test1' /etc/hostname"], shell=True)
        subprocess.call(["sed -i '$ahostname=test1' /etc/sysconfig/network"], shell=True)
        subprocess.call(["sed -i 's/enforcing/disabled/g' /etc/selinux/config"], shell=True)
        subprocess.call(["sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux"], shell=True)
        subprocess.call(["sed -i 's//dev/mapper/centos-swap/#/dev/mapper/centos-swap/g' /etc/fstab"], shell=True)
        subprocess.call(["systemctl stop firewalld && systemctl disable firewalld"], shell=True)
        subprocess.call(["reboot"], shell=True)
    
    def func_list():
        hostname_format()
    
    def main():
        func_list()
    if __name__ == '__main__':
        main()
    EOF
     
     
  • 相关阅读:
    database join
    图像超分辨率重建
    信号处理
    将博客搬至CSDN
    Openstack
    nginx的优化
    CentOS系统的优化
    zabbix服务端客户端部署
    MySQL优化必须调整的10项配置
    TCP三次握手
  • 原文地址:https://www.cnblogs.com/effortsing/p/10338651.html
Copyright © 2011-2022 走看看