服務(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
最后會(huì)得到下圖幾個(gè)文件:
二:
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啟動(dòng)文件
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:啟動(dòng)etcd
systemctl daemon-reload && systemctl enable etcd && systemctl start etcd(systemctl restart etcd)
沒報(bào)錯(cuò)則代表啟動(dòng)成功,如果有錯(cuò)香罐,則會(huì)拋出異常阿逃。
5.其他節(jié)點(diǎn)重復(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破托、安裝運(yùn)行時(shí)依賴的 Lua 庫
```
$ make deps
```
3肪跋、檢查 APISIX 的版本號(hào)
```
$ ./bin/apisix version
```
4、更改conf
cd conf
vim config-default.yaml
注釋該行土砂。意思是允許所有的ip訪問apisix州既,也可以加一個(gè)0.0.0.0/0谜洽,也代表所有ip可訪問
添加etcd cluster,就是本機(jī)ip吴叶。
5阐虚、啟動(dòng)apisix
make init。所有的修改操作都要執(zhí)行make init
make run? (停止 make stop, 重載make reload)
6.檢查apisix是否啟動(dòng)成功