安装Apisix

安装文档:https://apisix.apache.org/zh/docs/apisix/installation-guide/

如果当前系统没有安装 OpenResty,请使用以下命令来安装 OpenResty 和 APISIX 仓库:

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

如果已安装 OpenResty 的官方 RPM 仓库,请使用以下命令安装 APISIX 的 RPM 仓库:

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

查询可安装的版本

yum search apisix --showduplicates

安装

yum install -y apisix-2.15.3

安装后的目录是/usr/local/apisix和/usr/local/openresty

启动apisix

systemctl daemon-reload
systemctl enable apisix
systemctl start apisix
# apisix网关地址:http://x.x.x.x:9080
# apisix api地址:http://x.x.x.x:9180/apisix/admin

安装Apisix-Dashboard

安装到/usr/local/apisix/dashboard目录
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
systemctl enable apisix-dashboard
systemctl start apisix-dashboard

apisix-dashboard地址:http://x.x.x.x:9000
systemctl restart apisix-dashboard

1)安装依赖

yum install -y make cmake gcc gcc-c++ autoconf automake libpng-devel libjpeg-devel zlib libxml2-devel ncurses-devel bison libtool-ltdl-devel libiconv libmcrypt mhash mcrypt pcre-devel openssl-devel freetype-devel libcurl-devel lua-devel readline-devel curl wget

2)源码构建

wget https://openresty.org/download/openresty-1.21.4.1.tar.gz
tar -xzvf openresty-1.21.4.1.tar.gz
cd openresty-1.21.4.1/
./configure --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-http_ssl_module
sudo make
sudo make install

3)修改nginx.conf

user  nobody;
worker_processes  auto;
worker_rlimit_nofile 65535;
 
error_log  /var/log/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
pid        /run/nginx.pid;
 
events {
    worker_connections  65535;
    multi_accept on;
    use epoll;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;
 
    server_names_hash_max_size 1024;
#    server_names_hash_bucket_size 128;
 
   set_real_ip_from 100.125.0.0/16;
    real_ip_header X-Forwarded-For;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    log_format  main    '$remote_addr - $remote_user [$time_local] "$request" '
            '$status $body_bytes_sent "$http_referer" '
            '"$http_user_agent" "$http_x_forwarded_for"';
 
    access_log  /var/log/nginx/access.log  main;
 
    sendfile    on;
    tcp_nopush  on;
    tcp_nodelay on;
    types_hash_max_size 4096;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    gzip  on;
#    gzip_static on;
    gzip_min_length 1k;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript application/xml application/xml+rss text/javascript application/x-javascript;
 
    include /etc/nginx/conf.d/*.conf;
 
    server {
        listen       80;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

# Redis releases:
https://download.redis.io/releases/

wget https://download.redis.io/releases/redis-6.2.5.tar.gz

# To compile Redis, first the tarball, change to the root directory, and then run make:
tar -zxvf redis-6.2.5.tar.gz
cd redis-6.2.5
make MALLOC=libc

# If the compile succeeds, you'll find several Redis binaries in the src directory, including:
redis-server: the Redis Server itself
redis-cli is the command line interface utility to talk with Redis.

# To install these binaries in /usr/local/bin, run:
sudo make install

# Starting Redis
redis-server
或
redis-server redis.conf

wget http://nginx.org/download/nginx-1.21.5.tar.gz
tar -xvf nginx-1.21.5.tar.gz
cd nginx-1.21.5
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install

cat /dev/null > /etc/apt/sources.list

Debian 11 修改sources.list

cat <<EOT >> /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
  
deb http://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
  
deb http://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
  
deb http://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
EOT

Debian 12 修改sources.list

cat <<EOT >> /etc/apt/sources.list
deb https://mirrors.aliyun.com/debian bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm-updates main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian bookworm-proposed-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm-proposed-updates main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm-backports main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian bookworm-backports-sloppy main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm-backports-sloppy main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian-security bookworm-security main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian-security bookworm-security main non-free non-free-firmware contrib
EOT

修改时区

1)sudo dpkg-reconfigure tzdata
2)timedatectl set-timezone Asia/Shanghai
3)echo Asia/Shanghai > /etc/timezone && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

安装常用工具

apt update
apt install -y procps telnet inetutils-ping net-tools vim wget
apt clean

Ubuntu修改时区

FROM ubuntu:latest
 
ENV TZ=Asia/Shanghai
 
RUN apt-get update && apt-get install -y tzdata
RUN echo ${TZ} > /etc/timezone && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && dpkg-reconfigure -f noninteractive tzdata