apisix集群搭建(etcd 安装包安装方式)

服务器:10.199.250.44,10.199.250.101

### 一、依赖安装

```

# 安装 epel, `luarocks` 需要它

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

sudo rpm -ivh epel-release-latest-7.noarch.rpm

# 添加 OpenResty 源

sudo yum install yum-utils

sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

# 安装 OpenResty 和 编译工具

sudo yum install -y openresty curl git gcc luarocks lua-devel

#安装CFSSL

wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64

wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64

wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64

chmod +x cfssl_linux-amd64 cfssljson_linux-amd64 cfssl-certinfo_linux-amd64

mv cfssl_linux-amd64 /usr/local/bin/cfssl

mv cfssljson_linux-amd64 /usr/local/bin/cfssljson

mv cfssl-certinfo_linux-amd64 /usr/bin/cfssl-certinfo

# 安装 etcd

mkdir etcd && cd etcd

wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz

tar -xvf etcd-v3.4.13-linux-amd64.tar.gz && \

cd etcd-v3.4.13-linux-amd64 && \

sudo cp -a etcd etcdctl /usr/bin/

mkdir /apps/etcd/{bin,cfg,ssl} -p


一:配置ssl;cd ssl

1.etcd ca配置

cat << EOF | tee ca-config.json

{

  "signing": {

    "default": {

      "expiry": "87600h"

    },

    "profiles": {

      "etcd": {

        "expiry": "87600h",

        "usages": [

            "signing",

            "key encipherment",

            "server auth",

            "client auth"

        ]

      }

    }

  }

}

EOF

2.etcd ca证书

cat << EOF | tee ca-csr.json

{

    "CN": "etcd CA",

    "key": {

        "algo": "rsa",

        "size": 2048

    },

    "names": [

        {

            "C": "CN",

            "L": "Beijing",

            "ST": "Beijing"

        }

    ]

}

EOF

3.生成CA凭证和私钥

cfssl gencert-initca ca-csr.json|cfssljson-bare ca

4.etcd server证书

cat << EOF | tee server-csr.json{    "CN": "etcd",    "hosts": [    "10.199.250.44",    #集群服务器    "10.199.250.101"    ],    "key": {        "algo": "rsa",        "size": 2048    },    "names": [        {            "C": "CN",            "L": "Beijing",            "ST": "Beijing"        }    ]}EOF

5.生成etcd.server证书

cfssl gencert-ca=ca.pem-ca-key=ca-key.pem-config=ca-config.json-profile=etcd etcd-csr.json|cfssljson-bare server

最后会得到下图几个文件:

二:

1.配置etcd主文件 cd cfg/

cat << EOF | tee /apps/gateway/etcd/cfg/etcd.conf

#[Member]

ETCD_NAME="node01"

ETCD_DATA_DIR="/apps/gateway/etcd/etcd-v3.4.13-linux-amd64/node1.etcd"

ETCD_LISTEN_PEER_URLS="http://10.199.250.44:2380"

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

#[Clustering]

ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.199.250.44:2380"

ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"

ETCD_INITIAL_CLUSTER="node01=http://10.199.250.44:2380,node02=http://10.199.250.101:2380"

ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_INITIAL_CLUSTER_STATE="new

"

EOF

2.配置etcd启动文件

cat << EOF | tee /usr/lib/systemd/system/etcd.service

[Unit]

Description=Etcd Server

After=network.target

After=network-online.target

Wants=network-online.target

[Service]

Type=notify

EnvironmentFile=/apps/gateway/etcd/cfg/etcd.conf

ExecStart=/apps/gateway/etcd/bin/etcd 

Restart=on-failure

LimitNOFILE=65536

[Install]

WantedBy=multi-user.target

EOF

3:配置bin

将etcd-v3.4.13-linux-amd64中的etcd、etcdctl复制到bin文件中

cp etcd ../bin

cp etcdctl ../bin

4:启动etcd

systemctl daemon-reload && systemctl enable etcd && systemctl start etcd(systemctl restart etcd)

没报错则代表启动成功,如果有错,则会抛出异常。

5.其他节点重复如上操作,etcd_name等需要更改。

6.检查服务

/apps/gateway/etcd/bin/etcdctl  --endpoints="http://10.199.250.44:2379,http://10.199.250.101:2379" endpoint health

或/apps/gateway/etcd/bin/etcdctl member list

集群搭建成功。

五、APISIX安装

1、下载最新的源码发布包

```

$ cd /apps

$ mkdir apisix

$ wgethttps://downloads.apache.org/apisix/2.1/apache-apisix-2.1-src.tgz

$ tar -zxvf apache-apisix-2.1-src.tgz

```

2、安装运行时依赖的 Lua 库

```

$ make deps

```

3、检查 APISIX 的版本号

```

$ ./bin/apisix version

```

4、更改conf

cd conf

vim config-default.yaml

注释该行。意思是允许所有的ip访问apisix,也可以加一个0.0.0.0/0,也代表所有ip可访问

添加etcd cluster,就是本机ip。

5、启动apisix

make init。所有的修改操作都要执行make init

make run  (停止 make stop, 重载make reload)

6.检查apisix是否启动成功

你可能感兴趣的:(apisix集群搭建(etcd 安装包安装方式))