python配置主机名
、准备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 、编写脚本 cat > hostname.py <<EOF
#!/usr/bin/python
#-*- codinig: UTF- -*-
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 '$a\hostname=test1' /etc/hostname"], shell=True)
subprocess.call(["sed -i '$a\hostname=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
python配置主机名的更多相关文章
- Linux网络管理(一)之配置主机名与域名
Linux网络管理(一)之配置主机名与域名参考自:[1]修改主机名(/etc/hostname和/etc/hosts区别) https://blog.csdn.net/shmily_lsl/artic ...
- Linux 配置主机名
方法 1:临时配置 [root@NING ~]# hostname NING CRT重新连接即可,服务器重启失效. 方法 2:永久配置 步骤1:包含了主机最基本的网络信息,用于系统启动. [root@ ...
- CentOS配置主机名和主机映射
1.修改本机主机名 vi /etc/sysconfig/network 修改hostname HOSTNAME=s0 2.配置主机映射 vi /etc/hosts 修改内容如下 192.168.32. ...
- 使用HOSTNAMECTL配置主机名
hostnamectl工具是用来管理给定主机中. 查看所有主机名 请运行下面的命令查看所有当前主机名: 〜] $ hostnamectl status 如果未指定任何选项,默认则使用status选项对 ...
- linux初始化配置---主机名、关闭防火墙、关闭selinux
一.修改主机名 1.零时修改 [root@localhost network-scripts]# hostname jw07 然后就可以看到我们的主机名被修改了
- cent6.x配置主机名及静态网络
# 修改网卡名为NAME="eth0" [root@jenkins ~]# -persistent-net.rules # This file was automatically ...
- linux系统的初化始配置(包括网络,主机名,关闭firewalld与selinux)
每次我们使用Linux都会对系统进行初始化的配置,下面我们一一列出来. 1.服务的开启 systemctl enable firewalld.service //将指定的服务设置为开机启动 syste ...
- Linux学习笔记(10)linux网络管理与配置之一——主机名与IP地址,DNS解析与本地hosts解析(1-4)
Linux学习笔记(10)linux网络管理与配置之一——主机名与IP地址,DNS解析与本地hosts解析 大纲目录 0.常用linux基础网络命令 1.配置主机名 2.配置网卡信息与IP地址 3.配 ...
- CentOS8中进行IP和主机名的网络配置的过程图解
摘要: 很多人不知道如何在字符界面下配置主机名和ip,所以写了这个文章,本人也是新手,希望指出错误与不足.(本文只是在字符界面下教程) 一.输入你的账号密码登录 1)ifconfig 查看你目前的 主 ...
随机推荐
- 11.tensorboard网络结构
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # 载入数据集 mnist = i ...
- 【杭电多校第七场】A + B = C
原题: Given a,b,c, find an arbitrary set of x,y,z such that a*10^x+b*10^y=c*10^z and 0≤x,y,z≤10^6. 给你三 ...
- JS 获取和返填单选按钮Value值
1.获取Radio值 $('input[name="sex"]:checked ').val(); 2.返填Radio值 $('input[name="sex" ...
- 【线段树哈希】「Balkan OI 2016」Haker
1A海星 题目大意 给你一个长度为 $n$ ,由小写字母构成的字符串 $S$ 和 $Q$ 个操作,每个操作是以下 3 种之一: 1 x y k :询问当前字符串从位置 $x$ 到 $y$ 的子串与从位 ...
- +new Date是什么意思?
转载自:http://blog.csdn.net/abxn2002/article/details/53420816 JavaScript中可以在某个元素前使用 ‘+’ 号,这个操作是将该元素转换成N ...
- php类知识点滴---类继承的一些原则
完全重写 <?php class coach { public function __construct() { echo "欢迎来到~北武堂训练~"; } } cl ...
- Java-CharTools工具类
package com.gootrip.util; import java.io.UnsupportedEncodingException; /** * <p>Title:字符编码工具类 ...
- PyHook3----键盘鼠标操作
需要安装 pywin32 安装pyHook 下载网址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 注意选择的pyHook版本一定要和python对 ...
- 题解 【NOIP2014】解方程
题面 解析 这题的数据看起来似乎特别吓人... 但实际上, 这题非常好想. 只需要模一个大质数就行了(我模的是1e9+7)(实测有效) 另外,a要用快读读入,再一边模Mod(因为实在太大了). 然后, ...
- How to Fix "Linux Failure to Download extra data files for ttf-mscorefonts-installer" error
How to Fix "Linux Failure to Download extra data files for ttf-mscorefonts-installer" erro ...