-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some bugs and add fabric #566
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
297bc2a
add
gongweibao dc50be2
fix2
gongweibao 09f2a14
fix centos version
gongweibao 25d1042
add some colors and fix
gongweibao 61382ac
fix resgistry error
gongweibao 8a8b6b0
fix rm bugs
gongweibao 0fac779
fix
gongweibao 76b8e6f
fix by comments
gongweibao da21864
add fabric
gongweibao 256b372
add fabric
gongweibao 9724b1b
fix
gongweibao 084a4b2
add pxe option
gongweibao 880d6d8
add gpu
gongweibao 6fdb2a0
add reboot
gongweibao 18cf173
add mac_host
gongweibao 2343476
fix
gongweibao e3e78a8
fix
gongweibao d134f6b
fix mac
gongweibao 5e30fb6
add k8s install
gongweibao 80282ea
fix
gongweibao 4675261
add gpu
gongweibao b0830b4
add log.sh
gongweibao 2e58e05
fix logs
gongweibao 09810ec
add log ok
gongweibao 449e439
set host ok
gongweibao cef4f47
rm not need
gongweibao 2828e87
set startpxe
gongweibao 042dfd3
modify etcd path ok
gongweibao b92438b
change docker path ok
gongweibao 37d0027
etcd path ok
gongweibao a969494
rm not need
gongweibao a6e2b6b
add reame
gongweibao e55ec05
fix etcd path
gongweibao dd81911
Merge branch 'fix' of https://github.com/gongweibao/sextant into fix
gongweibao 038857a
fix kubelet start bug
gongweibao 6d15c86
fix by comments
gongweibao 15b275c
fix readme
gongweibao 86641e7
Merge branch 'fix' of https://github.com/gongweibao/sextant into fix
gongweibao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 前言 | ||
Sextant设计之初考虑的是在裸机集群中一键式的解决方案。实际使用的过程中,企业内部的集群一般都有了自己的初始化安装环境,如部署了DHCP服务器,有自己的DNS,机器也有自己的hostname,机器之间通过hostname相互也能ping同。这种情况下,同时两个DHCP服务器无疑是有冲突的,需要对Sextant做一些改动以便适应这种的环境。 | ||
|
||
我们可以把Sextant PXE服务部分设置为可选项,保留资源cache服务部分。由于post_script不能通过kick start的方式启动,所以引入fabric作为集群管理者,方便安装、配置、检查、启动、关闭软件。我们写的如下的步骤,都是在考虑了企业一般的现实情况来做的。 | ||
|
||
首先,`copy host.template.yaml host.yaml`,然后修改之。 | ||
|
||
***注意:*** | ||
- 符合要求的步骤可以略过 | ||
- 需要已经安装centos7的基础操作系统 | ||
|
||
# 步骤一:机器之间可以访问 | ||
我们需要机器都可以通过hostname来相互之间访问。如果企业的网络不支持,需要我们把静态解析写入各个节点`/etc/hosts`中(已经支持的可以忽略)。 | ||
|
||
``` | ||
# get mac_ip_host | ||
fab -f get_mac_ip_host.py get_mac_addr | ||
|
||
# display all before set them | ||
fab -f set_hosts.py display | ||
|
||
# set hosts | ||
fab -f set_hosts.py set_mac_hosts | ||
``` | ||
|
||
# 步骤二:生成bsroot | ||
注意设置cluster-desc.yaml中的`start_pxe: n`。 | ||
|
||
|
||
# 步骤三:升级kernel | ||
``` | ||
fab -f upgrade_kernel.py prepare | ||
fab -f upgrade_kernel.py upgrade | ||
fab -f upgrade_kernel.py reboot | ||
``` | ||
|
||
# 步骤四:安装gpu driver | ||
``` | ||
fab -f gpu_driver.py prepare | ||
fab -f gpu_driver.py install | ||
fab -f gpu_driver.py check | ||
``` | ||
|
||
# 步骤五:安装k8s需要的软件 | ||
``` | ||
fab -f k8s.py prepare | ||
fab -f k8s.py install | ||
``` | ||
|
||
# TODO: 启动etcd flannel kubelet等 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from __future__ import with_statement | ||
from fabric.api import * | ||
from fabric.contrib.console import confirm | ||
import fabric.operations as op | ||
import yaml | ||
import sys | ||
import re | ||
|
||
def get_mac_addr(): | ||
src_path = "/etc/mac_ip_host" | ||
|
||
cmd = """ default_iface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route | uniq) && | ||
default_iface=`echo ${default_iface} | awk '{ print $1 }'` && | ||
mac_addr=`ip addr show dev ${default_iface} | awk '$1 ~ /^link\// { print $2 }'` && | ||
echo $mac_addr %s $HOSTNAME > %s | ||
""" % (env.host_string, src_path) | ||
run(cmd) | ||
|
||
dst_path = env.host_string + "/mac_ip_host" | ||
get(src_path, dst_path) | ||
|
||
with open("hosts.yaml", 'r') as stream: | ||
try: | ||
y = yaml.load(stream) | ||
env.hosts = y["hosts"] | ||
env.user = y["user"] | ||
env.password = y["password"] | ||
except yaml.YAMLError as exc: | ||
print(exc) | ||
abort("load yaml error") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import with_statement | ||
from fabric.api import * | ||
from fabric.contrib.console import confirm | ||
import fabric.operations as op | ||
import yaml | ||
import sys | ||
|
||
driver_version="" | ||
http_gpu_dir="" | ||
boot_strapper="" | ||
|
||
def prepare(): | ||
cmd = """setenforce 0 | ||
&& sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config | ||
&& cat /etc/selinux/config | grep SELINUX""" | ||
run(cmd) | ||
|
||
def install(): | ||
# Imporant: gpu must be installed after the kernel has been installed | ||
run("wget -P /root %s/build_centos_gpu_drivers.sh" % http_gpu_dir) | ||
cmd = "bash -x /root/build_centos_gpu_drivers.sh %s %s" % (driver_version, http_gpu_dir) | ||
run(cmd) | ||
|
||
#@parallel | ||
def check(): | ||
cmd="ret=`nvidia-smi | grep \"Driver Version\" | grep %s` ; if [[ -z $ret ]]; then exit 1; fi " % driver_version | ||
result = run(cmd) | ||
if result.failed: | ||
abort(env.host_string + ": check failed") | ||
|
||
with open("hosts.yaml", 'r') as stream: | ||
try: | ||
y = yaml.load(stream) | ||
env.hosts = y["hosts"] | ||
env.user = y["user"] | ||
env.password = y["password"] | ||
|
||
boot_strapper = y["boot_strapper"] | ||
driver_version = y["gpu"]["driver_version"] | ||
|
||
http_gpu_dir="http://%s/static/CentOS7/gpu_drivers" % boot_strapper | ||
except yaml.YAMLError as exc: | ||
print(exc) | ||
abort("load yaml error") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
user: "root" | ||
password: "passwd" | ||
hosts: | ||
- 192.168.16.23 | ||
- 192.168.16.24 | ||
- 192.168.16.25 | ||
- 192.168.16.26 | ||
- 192.168.16.27 | ||
- 192.168.16.28 | ||
- 192.168.16.29 | ||
kernel: | ||
old_version: "3.10.0-327.el7.x86_64" | ||
new_version: "4.4.79-1.el7.elrepo.x86_64" | ||
gpu: | ||
driver_verion: 375.26 | ||
boot_strapper: "192.168.16.23" | ||
|
||
# host, mac, all | ||
set_type: host | ||
|
||
# change hostname to mac? | ||
set_mac_hostname: n | ||
|
||
# set "" if not need to change default path | ||
docker_data_path: "/home/var/lib/docker" | ||
etcd_data_path: "/home/var/lib/etcd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from __future__ import with_statement | ||
from fabric.api import * | ||
from fabric.contrib.console import confirm | ||
import fabric.operations as op | ||
import yaml | ||
import sys | ||
import re | ||
|
||
|
||
boot_strapper="" | ||
set_mac_hostname="" | ||
docker_data_path="" | ||
etcd_data_path="" | ||
|
||
def prepare(): | ||
run("systemctl stop firewalld && systemctl disable firewalld") | ||
run("wget -O /etc/yum.repos.d/Cloud-init.repo http://%s/static/CentOS7/repo/cloud-init.repo" % boot_strapper) | ||
run("wget -O /root/post-process.sh http://%s/centos/post-script/00-00-00-00-00-00" % boot_strapper) | ||
run("wget -O /root http://%s/static/CentOS7/post_cloudinit_provision.sh" % boot_strapper) | ||
|
||
def install(): | ||
run("yum --enablerepo=Cloud-init install -y cloud-init docker-engine etcd flannel") | ||
run("""cd /root | ||
&& export set_mac_hostname=%s | ||
&& export docker_data_path=%s | ||
&& bash post-process.sh""" % (set_mac_hostname, docker_data_path)) | ||
|
||
if len(etcd_data_path) > 0 : | ||
run("id -u etcd &>/dev/null || useradd etcd") | ||
run("mkdir -p %s && chown etcd -R %s" % (etcd_data_path, etcd_data_path)) | ||
|
||
run(""" cd /root | ||
&& export bootstrapper_ip=%s | ||
&& export etcd_data_path=%s | ||
&& bash post_cloudinit_provision.sh""" % (boot_strapper, etcd_data_path)) | ||
|
||
def rm_clouinit_cache(): | ||
run("rm -rf /var/lib/cloud/instances/iid-local01") | ||
|
||
def start_etcd(): | ||
run("""systemctl daemon-reload | ||
&& systemctl stop etcd | ||
&& systemctl enable etcd | ||
&& systemctl start etcd""") | ||
|
||
with open("hosts.yaml", 'r') as stream: | ||
try: | ||
y = yaml.load(stream) | ||
env.user = y["user"] | ||
env.password = y["password"] | ||
env.hosts = y["hosts"] | ||
boot_strapper = y["boot_strapper"] | ||
|
||
set_mac_hostname = y["set_mac_hostname"] | ||
docker_data_path = y["docker_data_path"] | ||
etcd_data_path = y["etcd_data_path"] | ||
except yaml.YAMLError as exc: | ||
print(exc) | ||
abort("load yaml error") | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from __future__ import with_statement | ||
from fabric.api import * | ||
from fabric.contrib.console import confirm | ||
import fabric.operations as op | ||
import yaml | ||
import sys | ||
import re | ||
|
||
mac_ip={} | ||
host_ip={} | ||
set_type="" | ||
|
||
def modify_mac_hosts(path, ips): | ||
import copy | ||
local = copy.deepcopy(ips) | ||
|
||
#hostname->ip | ||
hosts = [] | ||
with open(path, "r") as fp: | ||
for line in fp.read().split('\n'): | ||
if len(re.sub('\s*', '', line)) and not line.startswith('#'): | ||
parts = re.split('\s+', line) | ||
ip = parts[0] | ||
host_name = " ".join(parts[1:]) | ||
hosts.append([host_name, ip]) | ||
fp.close() | ||
|
||
for n in hosts: | ||
if n[0] in local: | ||
n[1] = local[n[0]] | ||
local[n[0]]= "" | ||
|
||
with open(path, "w") as fw: | ||
for n in hosts: | ||
fw.write("%s %s\n" % (n[1], n[0]) ) | ||
for n in local: | ||
if len(local[n]) > 0: | ||
fw.write("%s %s\n" % (local[n], n) ) | ||
fw.close() | ||
|
||
def set_mac_hosts(): | ||
src_path = "/etc/hosts" | ||
dst_path = env.host_string + "/hosts" | ||
get(src_path) | ||
if set_type == "mac" or set_type == "all": | ||
modify_mac_hosts(dst_path, mac_ip) | ||
if set_type == "host" or set_type == "all": | ||
modify_mac_hosts(dst_path, host_ip) | ||
put(dst_path, src_path) | ||
|
||
def display(): | ||
print host_ip | ||
print mac_ip | ||
|
||
with open("hosts.yaml", 'r') as stream: | ||
try: | ||
y = yaml.load(stream) | ||
env.hosts = y["hosts"] | ||
env.user = y["user"] | ||
env.password = y["password"] | ||
|
||
set_type = y["set_type"] | ||
except yaml.YAMLError as exc: | ||
print(exc) | ||
abort("load yaml error") | ||
|
||
for h in env.hosts: | ||
dst_path = h + "/mac_ip_host" | ||
with open(dst_path, "r") as fp: | ||
for line in fp.read().split('\n'): | ||
if len(re.sub('\s*', '', line)) and not line.startswith('#'): | ||
parts = re.split('\s+', line) | ||
mac = parts[0].replace(":", "-") | ||
ip = parts[1] | ||
host_name = parts[2] | ||
|
||
mac_ip[mac] = ip | ||
host_ip[host_name] = ip | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“ y” 引号里有一空格?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的。脚本解析yaml文件的时候有一个空格。