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

服務(wù)器: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",? ? #集群服務(wù)器? ? "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復(fù)制到bin文件中

cp etcd ../bin

cp etcdctl ../bin

4:啟動etcd

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

沒報錯則代表啟動成功,如果有錯,則會拋出異常。

5.其他節(jié)點重復(fù)如上操作,etcd_name等需要更改。

6.檢查服務(wù)

/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、下載最新的源碼發(fā)布包

```

$ 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,就是本機(jī)ip。

5、啟動apisix

make init。所有的修改操作都要執(zhí)行make init

make run? (停止 make stop, 重載make reload)

6.檢查apisix是否啟動成功

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容