QCon北京「鸿蒙专场」火热来袭!即刻报名,与创新同行~ 了解详情
写点什么

手把手教你安装第一个 LAIN 应用(上)

  • 2020-02-10
  • 本文字数:2943 字

    阅读完需:约 10 分钟

手把手教你安装第一个LAIN应用(上)

一、安装 LAIN 集群

本节包含三种场景下安装 LAIN 集群


  • 本地启动虚拟机安装 LAIN 集群,可供本地测试开发

  • 物理服务器/虚拟机安装 LAIN 集群

  • 云服务器安装 LAIN 集群


三者都需要从 GitHub 获取已经发布的 LAIN 版本源代码: https://github.com/laincloud/lain/releases


下载源码后在目标机器上解压即可。


tar xf lain-VERSION.tar.gz
复制代码

1、本地安装 LAIN 集群

1)环境依赖


  • Linux / MacOS

  • 能够连接到互联网

  • VirtualBox 5.1.22 r115126 (Qt5.6.2)

  • Vagrant 1.9.4

  • 最少 2G 剩余内存(如果需要拉起多个节点,最少 3G)


2)初始化


启动并初始化第一个节点


cd lain-VERSIONvagrant up --provision
复制代码


启动耗时取决于 vagrant box 下载时间, 启动完成后 vagrant 会自动 执行 bootstrap 进行初始化, 初始化需要至少 20 分钟,取决于网络速度。 初始化过程为集群默认配置 vip=192.168.77.201


如果出现以下错误:


Vagrant was unable to mount VirtualBox shared folders. This is usuallybecause the filesystem "vboxsf" is not available. This filesystem ismade available via the VirtualBox Guest Additions and kernel module.Please verify that these guest additions are properly installed in theguest. This is not a bug in Vagrant and is usually caused by a faultyVagrant box. For context, the command attempted was:
mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: No such device
复制代码


这个错误是因为宿主机的 Virtual Box 的 Guest Additions 与 laincloud/centos-lain box 已安装的 Guest Additions 版本不一致引起的,导致无法创建 /vagrant 这个同步 目录。请修改工程根目录下的 Vagrantfile,禁止宿主机强行安装新版本的 Guest Additions, 即添加如下配置:


config.vbguest.auto_update = false
复制代码


3)添加更多节点


vagrant up node2
# 待 node2 启动后[vagrant@node1 ~]$ cd /vagrant[vagrant@node1 ~]$ sudo lainctl node add -p playbooks node2:192.168.77.22# root 密码为 vagrant
复制代码


4)同理可以如此添加 node3

2、物理服务器/虚拟机安装 LAIN 集群

1)环境依赖


  • CentOS 7.2

  • NTP 服务保证节点间时间一致

  • 需要能访问到可用的 yum 源(包括 epel)

  • 能够连接到互联网

  • 各节点之间能够互相 ssh

  • 各节点 hostname 不同

  • 各个节点位于同一个路由器之内


2)初始化


第一个节点


cd lain-VERSION# 选择一个同网段的未被使用的 IP 地址作为 VIPsudo ./bootstrap -r docker.io/laincloud --vip={{ vip }}
复制代码


国内用户建议通过 -m 参数使用 aliyun 的加速器下载镜像,使用方式为


sudo ./bootstrap -m https://l2ohopf9.mirror.aliyuncs.com \-r docker.io/laincloud --vip=192.168.77.201
复制代码


添加更多节点


# 需要输入 root 密码sudo lainctl node add -p playbooks {{ hostname }}:{{ ip }}
复制代码

3、云服务器安装 LAIN 集群

1)环境依赖


  • CentOS 7.2

  • NTP 服务保证节点间时间一致

  • 需要能访问到可用的 yum 源(包括 epel)

  • 能够连接到互联网

  • 各节点之间能够互相 ssh

  • 各节点 hostname 不同

  • 各个节点位于同一个 VPC (或虚拟路由器)之内


3) 初始化


第一个节点


cd lain-VERSION
# 如果 VPC 不对数据包进行来源 IP 限制(如青云)sudo ./bootstrap -r docker.io/laincloud
# 如果 VPC 限制了数据包的来源 IP(如阿里云)sudo ./bootstrap -r docker.io/laincloud --ipip
复制代码


添加更多节点


# 需要输入 root 密码sudo lainctl node add -p playbooks {{ hostname }}:{{ ip }}
复制代码

4、配置 LAIN Console 的域名解析

LAIN Console 组件是 LAIN 集群的控制台,配置域名解析后即可在浏览器访问 http://console.lain.local


echo "IP/VIP  console.lain.local" >> /etc/hosts
复制代码

5、常见问题

add-node ssh-copy-id 失败


如果出现 ssh-copy-id 失败,可能需要把 node1:/root/.ssh/lain.pub 内容放到 node2:/root/.ssh/authorized_keys里,新增一行。当然原因可能是多样的,最有可能就是 lain-02 的 /root/.ssh 目录或者目录中的文件权限不对

二、安装 LAIN 客户端

开发 LAIN 应用时,需要安装 LAIN 客户端。LAIN 客户端依赖于: - docker - python


只要支持 docker 和 python 的系统,就可以使用 LAIN 客户端,比如 Linux 和 macOS。


以下均假设 LAIN 集群的 domain 为 lain.local,对于其他 domain,将下文中的 lain.local 替换即可。

1、安装与配置 docker

1)安装


请参考 https://docs.docker.com/engine/installation/ 安装 docker >= 1.12。


2)配置


Insecure Registries


安装好之后,请参考 https://docs.docker.com/registry/insecure/registry.lain.local 添加进 docker daemon 的 insecure-registries 选项。


例如,在 Linux 上,如下的 /etc/docker/daemon.json 表示将 registry.lain.local 加入了 insecure-registries


{  "insecure-registries" : ["registry.lain.local"]}
复制代码


macOS 上的 insecure registries 配置如下图所示:


1559274816295067665.jpeg



配置 insecure-registries 是因为 LAIN 集群的镜像仓库只提供了 HTTP 服务,没有提供 HTTPS 服务。

2、安装与配置 lain-cli

pip install lain-cli
复制代码


推荐使用 virtualenv 安装这个 python 包,即:


pip install virtualenv  # 安装 virtualenvvirtualenv lain  # lain 是虚拟环境的名字,也可以取其他名字source lain/bin/activate  # 激活 lain 虚拟环境pip install lain-clideactivate  # 退出 lain 虚拟环境
复制代码


以后需要使用 lain-cli 的时候,用 source ${lain-virtualenv-path}/bin/activate 激活 lain 虚拟环境; 不使用 lain-cli 的时候,用 deactivate 退出 lain 虚拟环境


安装好之后,需要配置 lain-cli,让 lain-cli 知道 LAIN 集群的 Domain 等信息:


lain config show  # 显示当前配置lain config save-global private_docker_registry registry.lain.local # 配置 docker 私有仓库lain config save local domain lain.local  # 保存 lain.local 集群,并取名为 local
复制代码


假如 LAIN 集群开启了 sso 验证(默认未开启),请配置 sso:


lain config save local sso_url https://sso.lain.local
复制代码

3、配置 LAIN 组件的域名解析

如果 LAIN 集群不能在公网上解析(比如本地启动的集群),请配置 /etc/hosts。


如果启动集群时,使用了 vip 模式,即使用了 /vagrant/bootstrap -r docker.io/laincloud --vip=192.168.77.201启动,请执行:


echo "192.168.77.201  registry.lain.local console.lain.local entry.lain.local lvault.lain.local ipaddr-client.lain.local ipaddr-service.lain.local ipaddr-client.ipaddr-resource.resource.lain.local" >> /etc/hosts
复制代码


192.168.77.201 是启动集群时的 vip 参数


如果启动集群时,没有使用 vip 模式,即使用了 /vagrant/bootstrap -r docker.io/laincloud 启动,请执行:


echo "192.168.77.21  registry.lain.local console.lain.local entry.lain.local lvault.lain.local ipaddr-client.lain.local ipaddr-service.lain.local ipaddr-client.ipaddr-resource.resource.lain.local" >> /etc/hosts
复制代码


192.168.77.21 是集群的主节点的 IP,即启动集群的节点的 IP。


本文转载自宜信技术学院网站。


原文链接:http://college.creditease.cn/detail/254


2020-02-10 21:04790

评论

发布
暂无评论
发现更多内容

架构师训练营第十一周作业

李日盛

LeetCode题解:264. 丑数 II,暴力法,JavaScript,详细注释

Lee Chen

算法 大前端 LeetCode

想法

BerryMew

RocketMQ避坑指南:你部署的RocketMQ集群真的是高可用?

中间件兴趣圈

架构 RocketMQ 故障分析 消息队列

第一周架构方法-练习-食堂就餐卡系统设计

潘涛

架构师训练营 4 期

【计算机内功修炼】二:读取文件时,程序经历了什么

码农的荒岛求生

后端 文件 操作系统 进程 线程’

意想不到,这个神奇的bug让我加班到深夜

码农的荒岛求生

bug修复

一次线上cpu过高问题

kcnf

架构师训练营第十一周笔记

李日盛

笔记

第九周 作业1

Mr_No爱学习

微信气质

池建强

微信

架构入门感悟之十一

笑春风

区块链游戏开发注意事项

CECBC

区块链 区块链游戏

时间戳——区块链不可篡改特性的重中之重

CECBC

区块链

架構師訓練營 大作業一

ilake

架构师训练营—大作业(一)

Geek_shu1988

架构师训练营—第十三周学习总结

Geek_shu1988

架构师训练营第十一周作业

丁乐洪

数据爬虫

RainGod

爬虫

「架构师训练营 4 期」 第一周 - 001002

凯迪

从考研失败到最具成长力员工,这个2020就像过山车一样

Java鱼仔

程序员 面试 程序人生 考研

架构师大作业

_

大作业 架构师训练营第 1 期

2021你好 | 一名五道口程序员的年终总结

herongwei

程序员 职场 自媒体 年终总结 新年

在 Emit 代码中如何await一个异步方法

八苦-瞿昙

分析了2020年3万多条的微博热搜,我看到了什么

CoderW

Python 程序人生 爬虫 后端 微博热搜

上地七街

潇潇雨歇

架构师训练营—第十三周作业

Geek_shu1988

交报告 | 2020年读完的50本书

Geek_u406me

【计算机内功修炼】一:看完这篇还不懂线程与线程池你来打我

码农的荒岛求生

高并发 线程池 进程 高性能 线程’

数字版权资源价值日益凸显

CECBC

版权保护

探讨典型互联网系统使用的技术方案

Andy

手把手教你安装第一个LAIN应用(上)_安全_LAIN团队_InfoQ精选文章