基于CentOS 7.6安装及配置APISIX 3.0环境

科技资讯 投稿 5600 0 评论

基于CentOS 7.6安装及配置APISIX 3.0环境

经历了几天折磨一样的学习,目前在本地环境中配置成功了一套,以供自己留存吧,实在是网上的很多文章要么太老了,要么就是乱写一通。

APISIX官方网址:https://apisix.apache.org/

 

1、安装ETCD(分布式Key-Value存储系统)

wget https://github.com/etcd-io/etcd/releases/download/v3.5.8/etcd-v3.5.8-linux-amd64.tar.gz
tar -xvf etcd-v3.5.8-linux-amd64.tar.gz && \
  cd etcd-v3.5.8-linux-amd64 && \
sudo cp -a etcd etcdctl /usr/bin/

这里的安装时间因为国内的原因,可能需要执行很长时间,我们同样也可以将文件提前下载好,丢到CentOS服务器上,再执行解压缩就可以了。

2、配置ETCD

(1)创建 /etc/etcd/etcd.service 服务配置文件,并编辑内容如下(本实例为单机模式部署):

ETCD_NAME=etcd ETCD_DATA_DIR=/etc/etcd/data ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380 ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379 ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380 ETCD_INITIAL_CLUSTER_STATE=new ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster

编写完成后,保存即可。

systemctl start etcd
systemctl enable etcd

到这里,整个ETCD服务就安装完成了

3、安装APISIX

(1)安装OpenRestry并且安装APISIX包

sudo yum install -y https://repos.apiseven.com/packages/centos/apache-apisix-repo-1.0-1.noarch.rpm

(2)添加APISIX YUM包源

sudo yum-config-manager --add-repo https://repos.apiseven.com/packages/centos/apache-apisix.repo

(3)执行APISIX安装

# 默认安装 sudo yum install apisix # 指定版本安装 sudo yum install apisix-3.3.0

安装完APISIX我们先不要启动,先去 /usr/local/apisix/conf/config.yaml中修改对应的文件配置,我这例子的配置如下:

# # Licensed to the Apache Software Foundation (ASF under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"; you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # If you want to set the specified configuration value, you can set the new # in this file. For example if you want to specify the etcd address: # # deployment: # role: traditional # role_traditional: # config_provider: etcd # etcd: # host: # - http://127.0.0.1:2379 # # To configure via environment variables, you can use `${{VAR}}` syntax. For instance: # # deployment: # role: traditional # role_traditional: # config_provider: etcd # etcd: # host: # - http://${{ETCD_HOST}}:2379 # # And then run `export ETCD_HOST=$your_host` before `make init`. # # If the configured environment variable can't be found, an error will be thrown. # # Also, If you want to use default value when the environment variable not set, # Use `${{VAR:=default_value}}` instead. For instance: # # deployment: # role: traditional # role_traditional: # config_provider: etcd # etcd: # host: # - http://${{ETCD_HOST:=localhost}}:2379 # # This will find environment variable `ETCD_HOST` first, and if it's not exist it will use `localhost` as default value. # apisix: node_listen: 8000 deployment: role: traditional role_traditional: config_provider: etcd etcd: host: - http://127.0.0.1:2379 admin: admin_key: - name: admin key: edd1c9f034335f136f87ad84b625c8f1 # using fixed API token has security risk, please update it when you deploy to production environment role: admin

这里要注意的是,apisix: node_listen 是不存在的,你要自己添加上并指定一下需要绑定的端口,并且在etcd 下的host 指定你ETCD服务器安装的位置(推荐使用内网,不要对外开放端口哈)

# 使用systemctl 将APISIX安装为服务
systemctl start apisix

# 添加服务开机自启动
systemctl enable apsix

启动成功后,通过访问网址 http://127.0.0.1:8000 会提示404 Route Not Found的字样,这时,我们的APISIX服务就安装完成咯!

4、安装APISIX-DASHBOARD(管理控制面板)

因为我们使用的CENTOS直接安装,那么我们执行如下的BASH脚本即可:

sudo yum install -y https://github.com/apache/apisix-dashboard/releases/download/v3.0.1/apisix-dashboard-3.0.1-0.el7.x86_64.rpm

安装需要一定的时间,安装完成后记得去 /usr/local/apisix/dashboard/conf/conf.yaml 文件中修改对应的配置ETCD地址及管理员、用户的账号及密码!

# 使用systemctl 将APISIX-DASHBOARD安装为服务
systemctl start apisix-dashboard

# 添加服务开机自启动
systemctl enable apsix-dashboard

以上所有便是APISIX在centos 7.6的安装过程,如果安装中大家有什么问题,可以一起留言讨论一下

 

编程笔记 » 基于CentOS 7.6安装及配置APISIX 3.0环境

赞同 (23) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽