经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Linux/Shell » 查看文章
基于CentOS 7.6安装及配置APISIX 3.0环境
来源:cnblogs  作者:star丶清影  时间:2023/5/10 12:45:45  对本文有异议

最近一直在研究微服务相关内容,通过对比各大API网关,发现新起之秀 APISIX无论从开源程度上来讲还是功能上,都拥有很大的优势。

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

 

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

ETCD官方网址:https://etcd.io/

 

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

根据apisix提供的官方网档,执行以下脚本就可以了:

  1. wget https://github.com/etcd-io/etcd/releases/download/v3.5.8/etcd-v3.5.8-linux-amd64.tar.gz
  2. 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

不知道是我找的资料不对,还是官方精简了一些,本打算使用 systemctl 安装ETCD,但是各种提示报错,经过了大量的资料搜索和文章的研究与尝试,这里需要以下步骤进行安装配置:

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

  1. ETCD_NAME=etcd
  2. ETCD_DATA_DIR=/etc/etcd/data
  3. ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
  4. ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
  5. ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379
  6. ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380
  7. ETCD_INITIAL_CLUSTER_STATE=new
  8. ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster

编写完成后,保存即可。

(2)以服务方式启用及启用加载自启

  1. systemctl start etcd
  2. systemctl enable etcd

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

3、安装APISIX

这一步操作很简单,直接根据官方文档来操作就可以了,安装说明:https://apisix.apache.org/docs/apisix/installation-guide/

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

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

(2)添加APISIX YUM包源

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

(3)执行APISIX安装

  1. # 默认安装
  2. sudo yum install apisix
  3. # 指定版本安装
  4. sudo yum install apisix-3.3.0

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

  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # If you want to set the specified configuration value, you can set the new
  18. # in this file. For example if you want to specify the etcd address:
  19. #
  20. # deployment:
  21. # role: traditional
  22. # role_traditional:
  23. # config_provider: etcd
  24. # etcd:
  25. # host:
  26. # - http://127.0.0.1:2379
  27. #
  28. # To configure via environment variables, you can use `${{VAR}}` syntax. For instance:
  29. #
  30. # deployment:
  31. # role: traditional
  32. # role_traditional:
  33. # config_provider: etcd
  34. # etcd:
  35. # host:
  36. # - http://${{ETCD_HOST}}:2379
  37. #
  38. # And then run `export ETCD_HOST=$your_host` before `make init`.
  39. #
  40. # If the configured environment variable can't be found, an error will be thrown.
  41. #
  42. # Also, If you want to use default value when the environment variable not set,
  43. # Use `${{VAR:=default_value}}` instead. For instance:
  44. #
  45. # deployment:
  46. # role: traditional
  47. # role_traditional:
  48. # config_provider: etcd
  49. # etcd:
  50. # host:
  51. # - http://${{ETCD_HOST:=localhost}}:2379
  52. #
  53. # This will find environment variable `ETCD_HOST` first, and if it's not exist it will use `localhost` as default value.
  54. #
  55. apisix:
  56. node_listen: 8000
  57. deployment:
  58. role: traditional
  59. role_traditional:
  60. config_provider: etcd
  61. etcd:
  62. host:
  63. - http://127.0.0.1:2379
  64. admin:
  65. admin_key:
  66. - name: admin
  67. key: edd1c9f034335f136f87ad84b625c8f1 # using fixed API token has security risk, please update it when you deploy to production environment
  68. role: admin

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

这里配置完成后,我们就可以使用systemctl启动APISIX咯

  1. 使用systemctl APISIX安装为服务
  2. systemctl start apisix
  3. # 添加服务开机自启动
  4. systemctl enable apsix

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

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

同样的,我们根据官方给的文档进行安装,文档地址:https://apisix.apache.org/docs/dashboard/install/

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

  1. 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地址及管理员、用户的账号及密码!

以上操作完成后,同样的执行以下命令,apisix-dashboard也就启动完成,我这里默认开的是9000端口,那么完成后通过浏览器访问 http://127.0.0.1:9000 就可以使用咯

  1. 使用systemctl APISIX-DASHBOARD安装为服务
  2. systemctl start apisix-dashboard
  3. # 添加服务开机自启动
  4. systemctl enable apsix-dashboard

 

 

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

 

原文链接:https://www.cnblogs.com/briny/p/17387663.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号