CreditEase Open Source | taught you how to install the application first LAIN

Further Reading: CreditEase Open Source | Detailed PaaS platform LAIN functionality and architecture

Letter should open | a Living Example 9 big killer feature of PaaS platform LAIN

First, install the cluster LAIN

This section contains three scenarios at the cluster mounting LAIN

  • Local start the virtual machine installation LAIN cluster for local test development
  • Physical server / virtual machine cluster installation LAIN
  • Cloud cluster server installation LAIN

LAIN need to get all three versions of the source code has been released from GitHub:
https://github.com/laincloud/lain/releases

After decompression can download the source code on the target machine.

tar xf lain-VERSION.tar.gz

1, the local cluster installation LAIN

1) dependent on the environment

  • Linux / MacOS
  • Able to connect to the Internet
  • VirtualBox 5.1.22 r115126 (Qt5.6.2)
  • Vagrant 1.9.4
  • 2G minimum remaining memory (if necessary pull plurality of nodes, at least 3G)

2) Initialization

Start and initialize the first node

cd lain-VERSION
vagrant up --provision

Start download time consuming depending vagrant box, start vagrant is performed automatically after the completion of bootstrap initialized, initialization takes at least 20 minutes, depending on network speed. Initialization process for the cluster default configuration vip = 192.168.77.201

If the following error:

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant 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

This error is because laincloud Virtual Box Guest Additions and the host of / centos-lain box installed Guest Additions due to inconsistent versions, can not be created / vagrant this directory synchronization. Please modify Vagrantfile in the project root directory, prohibit host forced to install a new version of the Guest Additions, that is, add the following configuration:

config.vbguest.auto_update = false

3) add more nodes

vagrant up node2

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

4) Similarly you can add so node3

2, the physical server / virtual machine cluster installation LAIN

1) dependent on the environment

  • CentOS 7.2
  • NTP service guarantees consistent between nodes time
  • Requires access to an available source yum (including EPEL)
  • Able to connect to the Internet
  • Between each node can ssh
  • Each node hostname different
  • Each node are in the same router

2) Initialization

The first node

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

Aliyun domestic users recommend the use of accelerator download mirrors by -m parameter to use

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

Add more nodes

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

3, the cloud server cluster installation LAIN

1) dependent on the environment

  • CentOS 7.2
  • NTP service guarantees consistent between nodes time
  • Requires access to an available source yum (including EPEL)
  • Able to connect to the Internet
  • Between each node can ssh
  • Each node hostname different
  • Each node is located within the VPC same (or virtual routers) of

3) Initialization

The first node

cd lain-VERSION

# 如果 VPC 不对数据包进行来源 IP 限制(如青云)
sudo ./bootstrap -r docker.io/laincloud

# 如果 VPC 限制了数据包的来源 IP(如阿里云)
sudo ./bootstrap -r docker.io/laincloud --ipip

Add more nodes

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

4, the configuration of DNS LAIN Console

LAIN LAIN Console component is a cluster console, you can access the browser after you configure DNS http: //console.lain.local

echo "IP/VIP  console.lain.local" >> /etc/hosts

5. Frequently Asked Questions

add-node ssh-copy-id fail

If the ssh-copy-id fails, you may need to put node1:/root/.ssh/lain.pubcontent into the node2:/root/.ssh/authorized_keysinside, the new line. Of course, the reason may be diverse, most probably lain-02's /root/.sshfile directory or directory permissions wrong

Second, install the client LAIN

When developing LAIN application, you need to install LAIN client. LAIN clients rely on:

  • docker
  • python

As long as support docker and python system, you can use LAIN client, such as Linux and macOS.

The following are assumed as cluster domain LAIN lain.local, for the other domain, can be replaced in the following lain.local.

1, installation and configuration docker

1) Installation

Refer https://docs.docker.com/engine/installation/ mounted docker> = 1.12.

2) Configuration

Insecure Registries

After installing, please refer https://docs.docker.com/registry/insecure/ will registry.lain.localadd docker daemon's insecure-registriesoptions.

For example, on Linux, the following /etc/docker/daemon.jsonsaid it would registry.lain.localjoin insecure-registries:

{
  "insecure-registries" : ["registry.lain.local"]
}

macOS insecure registries on the configuration shown below:

Configuration insecure-registriesis because mirroring warehouse LAIN cluster provides only HTTP services, does not provide HTTPS service.

2, Installation and Configuration lain-cli

pip install lain-cli

Virtualenv recommended to install the python package, namely:

pip install virtualenv  # 安装 virtualenv
virtualenv lain  # lain 是虚拟环境的名字,也可以取其他名字
source lain/bin/activate  # 激活 lain 虚拟环境
pip install lain-cli
deactivate  # 退出 lain 虚拟环境

After the need to use lain-cli when using source ${lain-virtualenv-path}/bin/activateactivated lain virtual environment; do not use lain-cli when, with the deactivateexit lain virtual environment

After installing, you need to configure lain-cli, let lain-cli know Domain LAIN cluster information such as:

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

If LAIN cluster opened sso verification (not turned on by default), configure sso:

lain config save local sso_url https://sso.lain.local

3, components of DNS configuration LAIN

If LAIN cluster can not be resolved in the public network (such as local start cluster), configure the / etc / hosts.

If you start the cluster, using the vipmodel, that uses a /vagrant/bootstrap -r docker.io/laincloud --vip=192.168.77.201start, execute:

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.201Vip is the parameter when starting the cluster

If you start a cluster, do not use vippatterns, that is used /vagrant/bootstrap -r docker.io/laincloudto start, execute:

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.21IP is the primary node of the cluster, that is, start IP node for the cluster.

Third, the application first LAIN

This section will demonstrate how to create a LAIN LAIN cluster-based application that provides HTTP services, when a user visits /, the return Hello, LAIN..

1, the pre-conditions

  • LAIN first need a cluster, it is recommended by the two nodes
  • Second, the needs of local development environment. LAIN see concrete steps to install the client.

LAIN is a docker's PaaS-based system, it is recommended to understand the basic concepts of the next docker:

2, business code

package main

import (
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello, LAIN."))
    })

    http.ListenAndServe(":8080", nil)
}

Logic of the code is:

  • Monitor 0.0.0.0:8080port
  • Received /during the HTTP request, returnHello, LAIN.

3, lain.yaml

lain.yamlLAIN profile is applied, as shown in the following example:

appname: hello-world  # 应用名,在集群内唯一,由小写字母、数字和 `-` 组成,且开头不能为数字,不能有连续的 `-`

build:  # 描述如何构建 hello-world:build-${git-committer-date}-${git-commit-hash} 镜像
  base: golang:1.8  # 基础镜像,类似于 Dockerfile 里的 FROM
  script:
    - go build -o hello-world  # 编译指令,类似于 Dockerfile 里的 RUN,WORKDIR 为 /lain/app

proc.web:  # 定义一个 proc,名字为 web
  type: web  # proc 类型为 web(LAIN 会为 web 类型的 proc 配置 ${appname}.${LAIN-domain} 的域名,对外提供 HTTP 服务)
  cmd: /lain/app/hello-world  # 因为 WORKDIR 为 /lain/app,所以编译好的程序在 /lain/app 目录下
  port: 8080  # hello-world 监听的端口

Because we need to provide HTTP services, so the definition of a webtype of proc, LAIN cluster will be automatically assigned to proc type of web a p p n a m e . {appname}. {} LAIN-Domain name.

proc.type is web, its name must also be web, namely a web app can have only one type of proc, and its name is web.

laincloud / hello-world @ basic complete code here: https://github.com/laincloud/hello-world/tree/basic

4, run locally

[vagrant@lain ~]$ cd ${hello-world-project}  # 进入工程目录

[vagrant@lain hello-world]$ lain build  # 构建 hello-world:build-${git-committer-date}-${git-commit-hash} 镜像,生成编译结果
>>> Building meta and release images ...
>>> found shared prepare image at remote and local, sync ...
>>> generating dockerfile to /Users/bibaijin/Projects/go/src/github.com/laincloud/hello-world/Dockerfile
>>> building image hello-world:build-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005 ...
Sending build context to Docker daemon 6.656 kB
Step 1/4 : FROM registry.lain.local/hello-world:prepare-0-1494908044
 ---> 7406706a7f21
Step 2/4 : COPY . /lain/app/
 ---> 45f6215362ad
Removing intermediate container 41e822d3b086
Step 3/4 : WORKDIR /lain/app/
 ---> 75c0f3094b6e
Removing intermediate container 24065cf1d7de
Step 4/4 : RUN ( go build -o hello-world )
 ---> Running in 43cefd489608
 ---> 644f596f83c8
Removing intermediate container 43cefd489608
Successfully built 644f596f83c8
>>> build succeeded: hello-world:build-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
>>> tag hello-world:build-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005 as hello-world:release-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
>>> generating dockerfile to /Users/bibaijin/Projects/go/src/github.com/laincloud/hello-world/Dockerfile
>>> building image hello-world:meta-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005 ...
Sending build context to Docker daemon 6.656 kB
Step 1/2 : FROM scratch
 --->
Step 2/2 : COPY lain.yaml /lain.yaml
 ---> cfdb9c518f0d
Removing intermediate container ab94a3603b8a
Successfully built cfdb9c518f0d
>>> build succeeded: hello-world:meta-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
>>> Done lain build.

[vagrant@lain hello-world]$ lain run web  # 在本地运行
>>> run proc hello-world.web.web with image hello-world:release-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
59f7fe4b1a7c6214361ecd5e06b19023ab7e02058888aa625749028af7b92954
>>> container name: hello-world.web.web
>>> port mapping:
>>> 8080/tcp -> 0.0.0.0:32769
  • All commands lain-cli are required to run in the directory that contains lain.yaml files.
  • lain-cli depends on the git version management, so you must install git, but also lain buildprior togit commit

docker psWhen you can see:

CONTAINER ID        IMAGE                                                                     COMMAND                  CREATED             STATUS              PORTS                     NAMES
59f7fe4b1a7c        hello-world:release-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005   "/lain/app/hello-w..."   27 seconds ago      Up 31 seconds       0.0.0.0:32769->8080/tcp   hello-world.web.web

Represents the above output lain by Docker Hello-world.web.web container port 8080 is mapped to the host 32769, it can be accessed on the host:

[vagrant@lain hello-world]$ curl http://localhost:32769
Hello, LAIN.

Get the desired results.

5, deployed to the cluster LAIN

You can see from the previous section, there is no problem running locally, you can now be deployed to the cluster LAIN:

[vagrant@lain ~]$ cd ${hello-world-project}  # 进入工程目录

[vagrant@lain hello-world]$ lain build  # 构建 hello-world:build-${git-committer-date}-${git-commit-hash} 镜像,生成编译结果

[vagrant@lain hello-world]$ lain tag local  # 类似于 docker tag,为 hello-world:(meta/release)-${git-committer-date}-${git-commit-hash} 镜像添加仓库前缀
>>> Taging meta and relese image ...
>>> tag hello-world:meta-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005 as registry.lain.local/hello-world:meta-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
>>> tag hello-world:release-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005 as registry.lain.local/hello-world:release-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
>>> Done lain tag.

[vagrant@lain hello-world]$ lain push local  # 类似于 docker push,将镜像推送到 LAIN 集群
>>> Pushing meta and release images ...
>>> pushing image registry.lain.local/hello-world:meta-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005 ...
The push refers to a repository [registry.lain.local/hello-world]
1a4886bd9611: Layer already exists
meta-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005: digest: sha256:daed70190af5fa980d6963fd3a6350591708c1568e180fe85e7eb6cfdd12d998 size: 524
>>> pushing image registry.lain.local/hello-world:release-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005 ...
The push refers to a repository [registry.lain.local/hello-world]
1a2245680fe1: Layer already exists
dfe083dd50ba: Layer already exists
edac683c8e67: Layer already exists
0372f18510d4: Layer already exists
c0b53d6ac422: Layer already exists
bcf20a0a17f3: Layer already exists
9d039e60afe3: Layer already exists
a172d29265f3: Layer already exists
e6562eb04a92: Layer already exists
596280599f68: Layer already exists
5d6cbe0dbcf9: Layer already exists
release-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005: digest: sha256:1cea69b6ed882fcc16f1f5661b3830a8b3f20263264c51d0610b8ec09e72a439 size: 2626
>>> Done lain push.

[vagrant@lain hello-world]$ lain deploy local  # 将应用部署到 LAIN 集群
>>> Begin deploy app hello-world to local ...
upgrading... Done.
>>> app hello-world deploy operation:
>>>     last version: 1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
>>>     this version: 1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
>>> if shit happened, rollback your app by:
>>>     lain deploy -v 1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005
  • LAIN name for the local cluster, refer to the installation settings in the client LAIN
  • lain tagAdd warehouse prefix mirror before you can make lain push
  • releaseImage contains the compiled results, the future will be to run this image-based container
  • metaImage contains lain.yamlfiles for LAIN cluster resolution, users need not be concerned
  • The deployment process is an asynchronous process, lain deploy localyou can use the following lain ps localquery deployment results.

At this point, you can be accessed via the following command hello-world:

[vagrant@lain hello-world]$ curl -H "Host: hello-world.lain.local" http://192.168.77.201
Hello, LAIN.

Or I can simply change /etc/hoststhe file, then use the domain names:

[vagrant@lain hello-world]$ echo "192.168.77.201 hello-world.lain.local" >> /etc/hosts
[vagrant@lain hello-world]$ curl http://hello-world.lain.local
Hello, LAIN.

The above 192.168.77.201is a virtual cluster IP local LAIN, to no vipway to start, use192.168.77.21

Get a Hello, LAIN.response, in line with our expectations.

GitHub Address : https://github.com/laincloud

White Paper : https://laincloud.gitbooks.io/white-paper/content/

Guess you like

Origin blog.csdn.net/gao2175/article/details/90715077