Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Trustworthy open source | hands-on to teach you to install the first LAIN application

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

First, install LAIN cluster

This section contains three scenarios for installing LAIN clusters

Start virtual machines locally and install LAIN clusters, which can be used for local test development, physical servers / virtual machines to install LAIN clusters, cloud servers, and LAIN clusters.

All three need to obtain the released LAIN version source code from GitHub:

Https://github.com/laincloud/lain/releases

Download the source code and decompress it on the target machine.

Tar xf lain-VERSION.tar.gz1, local installation of LAIN cluster

1) Environmental dependence

Linux / MacOS can connect to Internet VirtualBox 5.1.22 r115126 (Qt5.6.2) Vagrant 1.9.4 at least 2 GB of remaining memory (at least 3G if multiple nodes need to be pulled up)

2) initialize

Start and initialize the first node

Cd lain-VERSIONvagrant up-provision

The startup time depends on the vagrant box download time. After startup, vagrant automatically executes bootstrap for initialization, which takes at least 20 minutes, depending on the network speed. The initialization process configures vip=192.168.77.201 by default for the cluster

If the following error occurs:

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 / vagrantThe error output from the command was:/sbin/mount.vboxsf: mounting failed with the error: No such device

This error is caused by the inconsistency between the Guest Additions of the host's Virtual Box and the installed Guest Additions version of laincloud/centos-lain box, which makes it impossible to create the synchronization directory / vagrant. Modify the Vagrantfile in the root directory of the project to prohibit the host from forcibly installing a new version of Guest Additions, that is, add the following configuration:

Config.vbguest.auto_update = false

3) add more nodes

Vagrant up node2# after node2 starts, [vagrant@node1 ~] $cd / vagrant [vagrant@node1 ~] $sudo lainctl node add-p playbooks node2:192.168.77.22# root password is vagrant

4) similarly, you can add node3 in this way.

2. Install LAIN cluster on physical servers / virtual machines

1) Environmental dependence

CentOS 7.2NTP service ensures that the nodes need to be able to access available yum sources (including epel) at the same time, to be able to connect to the Internet, and to be able to ssh each node hostname different nodes in the same router.

2) initialize

First node

Cd lain-VERSION# selects an unused IP address of the same network segment as VIPsudo. / bootstrap-r docker.io/laincloud-- vip= {{vip}}

Domestic users suggest that you use the accelerator of aliyun to download the image through the-m parameter. The mode of use is

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

Add more nodes

# enter the root password sudo lainctl node add-p playbooks {{hostname}}: {{ip}} 3, and install the LAIN cluster on the CVM

1) Environmental dependence

CentOS 7.2NTP service ensures that nodes need to be able to access available yum sources (including epel) at the same time, to be able to connect to the Internet, each node can ssh each other, each node hostname different nodes are in the same VPC (or virtual router).

3) initialize

First node

Cd lain-VERSION# if VPC does not restrict the source of the packet (e.g. × × ×) sudo. / bootstrap-r docker.io/laincloud# if VPC limits the source of the packet IP (such as Aliyun) sudo. / bootstrap-r docker.io/laincloud-- ipip

Add more nodes

# enter root password sudo lainctl node add-p playbooks {{hostname}}: {{ip}} 4, configure domain name resolution of LAIN Console

The LAIN Console component is the console of the LAIN cluster. After configuring domain name resolution, you can access http://console.lain.local in the browser.

Echo "IP/VIP console.lain.local" > > / etc/hosts5, FAQ

Add-node ssh-copy-id failed

If ssh-copy-id fails, you may need to put the node1:/root/.ssh/lain.pub content in the node2:/root/.ssh/authorized_keys and add a new line. Of course, there may be a variety of reasons, and the most likely reason is that the / root/.ssh directory of lain-02 or the file permissions in the directory are incorrect.

Second, install the LAIN client

When developing LAIN applications, you need to install the LAIN client. The LAIN client depends on:

Dockerpython

As long as systems that support docker and python, you can use LAIN clients, such as Linux and macOS.

The following assumes that the domain of the LAIN cluster is lain.local, and for other domain, replace the lain.local below.

1. Install and configure docker

1) installation

Please refer to https://docs.docker.com/engine/installation/ installation docker > = 1.12.

2) configuration

Insecure Registries

Once installed, refer to the https://docs.docker.com/registry/insecure/ insecure-registries option for adding registry.lain.local to docker daemon.

For example, on Linux, the following / etc/docker/daemon.json indicates that registry.lain.local is added to the insecure-registries:

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

The insecure registries configuration on macOS is shown in the following figure:

Insecure-registries is configured because the image repository of the LAIN cluster only provides HTTP services, not HTTPS services.

2. Install and configure lain-clipip install lain-cli

It is recommended to install this python package using virtualenv, that is:

Pip install virtualenv # install virtualenvvirtualenv lain # lain is the name of the virtual environment. You can also choose another name source lain/bin/activate # to activate the lain virtual environment pip install lain-clideactivate # to exit the lain virtual environment

When you need to use lain-cli later, activate the lain virtual environment with source ${lain-virtualenv-path} / bin/activate; when you are not using lain-cli, use deactivate to exit the lain virtual environment

After installation, you need to configure lain-cli to let lain-cli know the Domain and other information of the LAIN cluster:

Lain config show # shows the current configuration lain config save-global private_docker_registry registry.lain.local # configures docker private warehouse lain config save local domain lain.local # saves the lain.local cluster and names it local

If sso authentication is enabled for the LAIN cluster (not enabled by default), configure sso:

Lain config save local sso_url https://sso.lain.local3, domain name resolution for configuring LAIN components

If the LAIN cluster cannot be resolved on the public network (such as a locally started cluster), configure / etc/hosts.

If vip mode is used when starting the cluster, even if / vagrant/bootstrap-r docker.io/laincloud-- vip=192.168.77.201 startup is used, 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.201 is the vip parameter when starting the cluster

If vip mode is not used when starting the cluster, even if / vagrant/bootstrap-r docker.io/laincloud is used to start the cluster, 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.21 is the IP of the primary node of the cluster, that is, the IP of the node that starts the cluster.

Third, the first LAIN application

This section demonstrates how to create a LAIN application based on a LAIN cluster, which provides HTTP services and returns Hello, LAIN. When the user visits /.

1. The precondition first requires a LAIN cluster, which is recommended to be composed of 2 nodes. Secondly, it needs a local development environment. For specific steps, please see installing the LAIN client.

LAIN is a docker-based PaaS system. It is recommended to understand the basic concepts of docker first:

Docker official document: https://docs.docker.com/Docker from introduction to practice: https://yeasy.gitbooks.io/docker_practice/content/2, business code package mainimport ("net/http") func main () {http.HandleFunc ("/", func (w http.ResponseWriter, r * http.Request) {w.Write ([] byte ("Hello, LAIN.")}) http.ListenAndServe (": 8080", nil)}

The logic of the code is:

When listening to the HTTP request received by port 0.0.0.0 LAIN.3 8080, return Hello, LAIN.3, lain.yaml

Lain.yaml is the configuration file for the LAIN application, as shown in the following example:

Appname: hello-world # application name, unique within the cluster, consists of lowercase letters, numbers and `-`. It cannot start with a number and cannot have a continuous `-` build: # describes how to build a hello-world:build-$ {git-committer-date}-${git-commit-hash} image base: golang:1.8 # basic image, similar to the FROM script:-go build- o hello-world # compilation instruction in Dockerfile Similar to RUN,WORKDIR in Dockerfile, define a proc named web type: web # proc type web (LAIN will configure a domain name of ${appname}. ${LAIN-domain} for proc of type web to provide HTTP services) cmd: / lain/app/hello-world # because WORKDIR is / lain/app, the compiled program listens on port: 8080 # hello-world in the / lain/app directory

Because we need to provide HTTP services, defining a proc,LAIN cluster of type web automatically assigns a domain name of ${appname}. ${LAIN-domain} to proc of type web.

When proc.type is web, its name must also be web, that is, an app can have only one proc of type web, and its name is web.

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

4. Run [vagrant@lain ~] $cd ${hello-world-project} # locally to enter the project directory [vagrant@lain hello-world] $lain build # to build a hello-world:build-$ {git-committer-date}-${git-commit-hash} image Generate compilation results > 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 kBStep 1 kBStep 4: FROM registry.lain.local/hello-world:prepare-0-1494908044-- > 7406706a7f21Step 2 max 4: COPY. / lain/app/-- > 45f6215362adRemoving intermediate container 41e822d3b086Step 3644f596f83c8Removing intermediate container 43cefd489608Successfully built 644f596f83c8 4: WORKDIR / lain/app/-- > 75c0f3094b6eRemoving intermediate container 24065cf1d7deStep 4 hello-world 4: RUN (go build- o hello-world)-- > Running in 43cefd489608-- > 644f596f83c8Removing intermediate container 43cefd489608Successfully 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 kBStep 1 vagrant@lain hello-world 2: FROM scratch-- > Step 2 lain.yaml 2: COPY lain.yaml / lain.yaml-- > cfdb9c518f0dRemoving intermediate container ab94a3603b8aSuccessfully built cfdb9c518f0d > build succeeded: hello-world:meta-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005 > Done lain build. [vagrant@lain hello-world] $lain run web # run locally > > run proc hello-world.web.web with image hello-world:release-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d075800559f7fe4b1a7c6214361ecd5e06b19023ab7e02058888aa625749028af7b92954 > container name: hello- All commands for world.web.web > > port mapping: > > 8080/tcp-> 0.0.0.0:32769lain-cli need to be run in the directory that contains the lain.yaml file. Lain-cli depends on the git managed version, so install git first and git commit before lain build

When you docker ps, you can see:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES59f7fe4b1a7c 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

The above output shows that lain maps port 8080 in the hello-world.web.web container to 32769 of the host through docker, so it can be accessed on the host:

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

The expected results are obtained.

5. Deploy to LAIN cluster

As you can see from the previous section, there is no problem with running locally, and you can now deploy to the LAIN cluster:

[vagrant@lain ~] $cd ${hello-world-project} # enter the project directory [vagrant@lain hello-world] $lain build # to build the hello-world:build-$ {git-committer-date}-${git-commit-hash} image, and generate the compilation result [vagrant@lain hello-world] $lain tag local # similar to docker tag Add the warehouse prefix for hello-world: (meta/release)-${git-committer-date}-${git-commit-hash} image > 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 # is similar to docker push Push the image to the LAIN cluster > 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 existsmeta-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 existsdfe083dd50ba: Layer already existsedac683c8e67 : Layer already exists0372f18510d4: Layer already existsc0b53d6ac422: Layer already existsbcf20a0a17f3: Layer already exists9d039e60afe3: Layer already existsa172d29265f3: Layer already existse6562eb04a92: Layer already exists596280599f68: Layer already exists5d6cbe0dbcf9: Layer already existsrelease-1496631978-a46ef7afcbbc18c1c1248bcbb84fa770d0758005: digest: sha256:1cea69b6ed882fcc16f1f5661b3830a8b3f20263264c51d0610b8ec09e72a439 size: 2626 > > Done lain push. [vagrant@lain hello-world] $lain deploy local # deploy the application to the LAIN cluster > 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-a46ef7afcbbc18c1c1248bcbb84fa770d0758005local is the name of the LAIN cluster. Please refer to the settings in installing LAIN client to add the warehouse prefix to the image before the lain pushrelease image contains the compilation results. In the future, you will run the container meta image containing lain.yaml files based on this image for LAIN cluster resolution. Users do not need to care that the deployment process is asynchronous, and after lain deploy local, you can use lain ps local to query the deployment results.

At this point, you can access hello-world with the following command:

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

Or you can change the / etc/hosts file first, and then access it directly using the domain name:

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

The above 192.168.77.201 is the virtual IP of the local LAIN cluster and is not started in vip mode. Please use 192.168.77.21.

Hello, LAIN. The response is in line with our expectations.

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

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

Source: Yixin Institute of Technology

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report