麒麟 Linux arm64 安装 Redis、nginx、oceanbase

首先确认系统架构uname -m:

[root@localhost sbin]# uname -m
aarch64

这里看到是aarch64那么就是arm架构,否则会显示x86_64

1.安装redis

操作流程:

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

tar xvzf redis-6.2.12.tar.gz

cd redis-6.2.12/

make -j$(nproc)

make install

vim redis.conf #配置参数,可以忽略

./src/redis-server

2.安装nginx

nginx麻烦一点,需要配置一些参数:

官网下载源码:http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.26.3.tar.gz
tar zxvf nginx-1.26.3.tar.gz
useradd -s /sbin/nologin -M nginx

#安装目录在/data/server/nginx
cd nginx-1.26.3

#配置参数

./configure \
–prefix=/data/server/nginx \
–with-http_ssl_module \
–with-http_v2_module \
–with-http_realip_module \
–with-threads \
–with-file-aio \
–with-stream \
–with-http_stub_status_module \
–user=nginx \
–group=nginx

#编译安装
make && make install

接着进入sbin启动nginx即可。

配置参数有点多,找了点资料记录:

–prefix=  指向安装目录。

–sbin-path=  指定执行程序文件存放位置。

–modules-path=  指定第三方模块的存放路径。

–conf-path= 指定配置文件存放位置。

–error-log-path=  指定错误日志存放位置。

–pid-path=  指定pid文件存放位置。

–lock-path=  指定lock文件存放位置。

–user=  指定程序运行时的非特权用户。

–group=  指定程序运行时的非特权用户组。

–builddir=  指向编译目录。

–with-rtsig_module  启用rtsig模块支持。

–with-select_module  启用select模块支持,一种轮询处理方式,不推荐在高并发环境中使用,禁用:–without-select_module。

–with-poll_module  启用poll模块支持,功能与select相同,不推荐在高并发环境中使用。

–with-threads 启用thread pool支持。

–with-file-aio  启用file aio支持。

–with-http_ssl_module 启用https支持。

–with-http_v2_module    启用ngx_http_v2_module支持。

–with-ipv6    启用ipv6支持。

–with-http_realip_module    允许从请求报文头中更改客户端的ip地址,默认为关。

–with-http_addition_module    启用ngix_http_additon_mdoule支持(作为一个输出过滤器,分部分响应请求)。

–with -http_xslt_module    启用ngx_http_xslt_module支持,过滤转换XML请求 。

–with-http_image_filter_mdoule  启用ngx_http_image_filter_module支持,传输JPEG\GIF\PNG图片的一个过滤器,默认不启用,需要安装gd库。

–with-http_geoip_module  启用ngx_http_geoip_module支持,用于创建基于MaxMind GeoIP二进制文件相配的客户端IP地址的ngx_http_geoip_module变量。

–with-http_sub_module  启用ngx_http_sub_module支持,允许用一些其他文本替换nginx响应中的一些文本。

–with-http_dav_module  启用ngx_http_dav_module支持,增加PUT、DELETE、MKCOL创建集合,COPY和MOVE方法,默认为关闭,需要编译开启。

–with-http_flv_module  启用ngx_http_flv_module支持,提供寻求内存使用基于时间的偏移量文件。

–with-http_mp4_module  启用ngx_http_mp4_module支持,启用对mp4类视频文件的支持。

–with-http_gzip_static_module  启用ngx_http_gzip_static_module支持,支持在线实时压缩输出数据流。

–with-http_random_index_module  启用ngx_http_random_index_module支持,从目录中随机挑选一个目录索引。

–with-http_secure_link_module  启用ngx_http_secure_link_module支持,计算和检查要求所需的安全链接网址。

–with-http_degradation_module  启用ngx_http_degradation_module 支持允许在内存不足的情况下返回204或444代码。

–with-http_stub_status_module  启用ngx_http_stub_status_module 支持查看nginx的状态页。

–without-http_charset_module  禁用ngx_http_charset_module这一模块,可以进行字符集间的转换,从其它字符转换成UTF-8或者从UTF8转换成其它字符。它只能从服务器到客户端方向,只有一个字节的字符可以转换。

–without-http_gzip_module  禁用ngx_http_gzip_module支持,同–with-http_gzip_static_module功能一样。

–without-http_ssi_module  禁用ngx_http_ssi_module支持,提供了一个在输入端处理服务器包含文件(SSI)的过滤器。

–without-http_userid_module  禁用ngx_http_userid_module支持,该模块用来确定客户端后续请求的cookies。

–without-http_access_module  禁用ngx_http_access_module支持,提供了基于主机ip地址的访问控制功能。

–without-http_auth_basic_module  禁用ngx_http_auth_basic_module支持,可以使用用户名和密码认证的方式来对站点或部分内容进行认证。

–without-http_autoindex_module  禁用ngx_http_authindex_module,该模块用于在ngx_http_index_module模块没有找到索引文件时发出请求,用于自动生成目录列表。

–without-http_geo_module  禁用ngx_http_geo_module支持,这个模块用于创建依赖于客户端ip的变量。

–without-http_map_module  禁用ngx_http_map_module支持,使用任意的键、值 对设置配置变量。

–without-http_split_clients_module 禁用ngx_http_split_clients_module支持,该模块用于基于用户ip地址、报头、cookies划分用户。

–without-http_referer_module  禁用ngx_http_referer_modlue支持,该模块用来过滤请求,报头中Referer值不正确的请求。

–without-http_rewrite_module  禁用ngx_http_rewrite_module支持。该模块允许使用正则表达式改变URI,并且根据变量来转向以及选择配置。如果在server级别设置该选项,那么将在location之前生效,但如果location中还有更进一步的重写规则,location部分的规则依然会被执行。如果这个URI重写是因为location部分的规则造成的,那么location部分会再次被执行作为新的URI,这个循环会被执行10次,最后返回一个500错误。

–without-http_proxy_module  禁用ngx_http_proxy_module支持,http代理功能。

–without-http_fastcgi_module  禁用ngx_http_fastcgi_module支持,该模块允许nginx与fastcgi进程交互,并通过传递参数来控制fastcgi进程工作。

–without-http_uwsgi_module  禁用ngx_http_uwsgi_module支持,该模块用来使用uwsgi协议,uwsgi服务器相关。

–without-http_scgi_module  禁用ngx_http_scgi_module支持,类似于fastcgi,也是应用程序与http服务的接口标准。

–without-http_memcached_module  禁用ngx_http_memcached支持,用来提供简单的缓存,提高系统效率。

–without-http_limit_conn_module  禁用ngx_http_limit_conn_module支持,该模块可以根据条件进行会话的并发连接数进行限制。

–without-http_limit_req_module  禁用ngx_limit_req_module支持,该模块可以实现对于一个地址进行请求数量的限制。

–without-http_empty_gif_module  禁用ngx_http_empty_gif_module支持,该模块在内存中常驻了一个1*1的透明gif图像,可以被非常快速的调用。

–without-http_browser_module  禁用ngx_http_browser_mdoule支持,创建依赖于请求报头的值 。如果浏览器为modern,则$modern_browser等于modern_browser_value的值;如果浏览器为old,则$ancient_browser等于$ancient_browser_value指令分配的值;如果浏览器为MSIE,则$msie等于1。

–without-http_upstream_ip_hash_module 禁用ngx_http_upstream_ip_hash_module支持,该模块用于简单的负载均衡。

–with-http_perl_module  启用ngx_http_perl_module支持,它使nginx可以直接使用perl或通过ssi调用perl。

–with-perl_modules_path=  设定perl模块路径

–with-perl=  设定perl库文件路径

–http-log-path=  设定access log路径

–http-client-body-temp-path=  设定http客户端请求临时文件路径

–http-proxy-temp-path=  设定http代理临时文件路径

–http-fastcgi-temp-path=  设定http fastcgi临时文件路径

–http-uwsgi-temp-path=  设定http scgi临时文件路径

–http-scgi-temp-path=  设定http scgi临时文件路径

–without-http  禁用http server功能

–without-http-cache  禁用http cache功能

–with-mail  启用POP3、IMAP4、SMTP代理模块

–with-mail_ssl_module  启用ngx_mail_ssl_module支持

–without-mail_pop3_module  禁用pop3协议。

–without-mail_iamp_module  禁用iamp协议。

–without-mail_smtp_module  禁用smtp协议。

–with-google_perftools_module  启用ngx_google_perftools_mdoule支持,调试用,可以用来分析程序性能瓶颈。

–with-cpp_test_module 启用ngx_cpp_test_module支持。

–add-module=  指定外部模块路径,启用对外部模块的支持。

–with-cc=  指向C编译器路径。

–with-cpp=  指向C预处理路径。

–with-cc-opt=  设置C编译器参数,指定–with-cc-opt=”-I /usr/lcal/include”,如果使用select()函数,还需要同时指定文件描述符数量–with-cc-opt=”-D FD_SETSIZE=2048″。 (PCRE库)

–with-ld-opt=  设置连接文件参数,需要指定–with-ld-opt=”-L /usr/local/lib”。(PCRE库)

–with-cpu-opt=  指定编译的CPU类型,如pentium,pentiumpro,…amd64,ppc64…

–without-pcre  禁用pcre库。

–with-pcre  启用pcre库。

–with-pcre=  指向pcre库文件目录。

–with-pcre-opt=  在编译时为pcre库设置附加参数 。

–with-md5=  指向md5库文件目录。

–with-md5-opt=  编译时为md5库设置附加参数。

–with-md5-asm  使用md5汇编源。

–with-sha1=  指向sha1库文件目录。

–with-sha1-opt=  编译时为sha1库设置附加参数。

–with-sha1-asm  使用sha1汇编源。

–with-zlib=  指向zlib库文件目录。

–with-zlib-opt=  在编译时为zlib设置附加参数。

–with-zlib-asm=  为指定的CPU使用汇编源进行优化。

–with-libatomic  为原子内存的更新操作的实现提供一个架构。

–with-libatomic=  指向libatomic_ops的安装目录。

–with-openssl=  指向openssl安装目录。

–with-openssl-opt=  在编译时为openssl设置附加参数。

–with-debug  启用debug日志。

默认with或without的选项

选项(功能) with without 默认
prefix N/A N/A /usr/local/nginx
sbin-path N/A N/A prefix/sbin/nginx
conf-path N/A N/A prefix/conf/nginx.conf
pid-path N/A N/A prefix/logs/nginx.pid
error-log-path N/A N/A prefix/logs/error.log
http-log-path N/A N/A prefix/logs/access.log
user N/A N/A nobody
group N/A N/A nobody
select_module with without 如果平台不支持kqueue,epoll,/dev/poll,它将作为自动选择的事务处理方式
poll_module with without 如果平台不支持kqueue,epoll,/dev/poll,它将作为自动选择的事务处理方式
file_aio with N/A 关闭
ipv6 with N/A 关闭
http_ssl_module with N/A 关闭
http_realip_module with N/A 关闭
http_addition_module with N/A 关闭
http_xslt_module with N/A 关闭
http_image_filter_module with N/A 关闭
http_geoip_module with N/A 关闭
http_sub_module with N/A 关闭
http_dav_module with N/A 关闭
http_flv_module with N/A 关闭
http_gzip_static_module with N/A 关闭
http_random_index_module with N/A 关闭
http_secure_link_module with N/A 关闭
http_degradation_module with N/A 关闭
http_stub_status_module with N/A 关闭
http_charset_module N/A without 启用
http_gzip_module N/A without 启用
http_ssi_module N/A without 启用
http_userid_module N/A without 启用
http_access_module N/A without 启用
http_auth_basic_module N/A without 启用
http_autoindex_module N/A without 启用
http_geo_module N/A without 启用
http_map_module N/A without 启用
http_split_clients_module N/A without 启用
http_referer_module N/A without 启用
http_rewrite_module N/A without 启用
http_proxy_module N/A without 启用
http_fastcgi_module N/A without 启用
http_uwsgi_module N/A without 启用
http_scgi_module N/A without 启用
http_memcached_module N/A without 启用
http_limit_conn_module N/A without 启用
http_limit_req_module N/A without 启用
http_empty_gif_module N/A without 启用
http_brower_module N/A without 启用
http_upstream_ip_hash_module N/A without 启用
http_perl_module with N/A 禁用
http N/A without 启用
http-cache N/A without 启用
mail with N/A 禁用
pcre with without N/A
stream with N/A 禁用

3.安装oceanbase

安装包提前在官网下载的,

tar zxvf ./oceanbase-standalone-all-in-one-4.2.5_bp6_hotfix1_20251009.el7.aarch64.tar.gz

cd oceanbase-standalone-all-in-one/

bash bin/install_obd.sh

该脚本会安装 obd 和 OBClient,并将安装目录下 rpms 目录中的所有安装包复制到 obd 的本地镜像库中,同时关闭远程镜像库。执行成功后输出如下,您可复制并执行输出中的 source ~/.oceanbase-all-in-one/bin/env.sh 命令以应用环境配置。

启动交互式安装:

在 oceanbase-standalone-all-in-one 的安装目录下,执行 install_ob.sh 脚本启动交互式安装流程。

  1. 填写当前用户信息。
  2. 修改系统参数
  3. 配置集群信息。
  4. (可选)配置租户信息。
  5. 控制是否开启密码加密功能。
  6. (可选)配置监控信息。
  7. 确认配置。
  8. 部署成功。

当看到确认配置,基本上就成功了:

#Saved configurations:
cluster name: myoceanbase2
mysql port: 2881
rpc port: 2882
obshell port: 2886
cpu count: 16
memory limit: 22G
home path: /root/myoceanbase2/oceanbase_name
data dir: /data/1/myoceanbase2
log dir: /data/log1/myoceanbase2
datafile maxsize: 312G
log disk size: 54G
enable auto start: True
tenant name: ship
tenant cpu: 4
tenant memory: 8G
tenant log disk size: 51G

 

 

 

 

 

 

Nginx反向代理数据处理不过来:net::ERR_INCOMPLETE_CHUNKED_ENCODING

net::ERR_INCOMPLETE_CHUNKED_ENCODING

在浏览器上调用接口,响应被打断了,报错误:net::ERR_INCOMPLETE_CHUNKED_ENCODING

通过IDEA的http接口测试,会报错误:

org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected

报错解释:

net::ERR_INCOMPLETE_CHUNKED_ENCODING 错误表明浏览器在尝试使用分块传输编码(Chunked Transfer Encoding)读取响应时遇到了问题。分块传输编码是一种传输内容的方法,它将 HTTP 响应分成多个部分,也就是“块”。这种编码方法用于流媒体或者不能立即确定内容大小的情况。

这里的解决方案Google的:

You might want to check if the user that is running the Nginx worker owns the directory /var/lib/nginx (or /var/cache/nginx in some distros).

I’ve learned that when you give a response too big for Nginx, it uses this directory to write as a working directory for temporary files. If the worker process cannot access it, Nginx will terminate the transmission before it completes, thus the error INCOMPLETE_CHUNKED_ENCODING.

另外一种,就是设置buffer:

server {
    ...

    location / {
        ...
        proxy_buffers 8 1024k;  
        proxy_buffer_size 1024k;
    }
}
server {
        listen      0000; #//port give by your need
        server_name  aa.com;
        proxy_buffers 16 4k;
        proxy_buffer_size 2k;


        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location ~ ^/hello/{
            proxy_buffering off;
            proxy_pass http://127.0.0.1:1111; #//port give by your need
            proxy_redirect     off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Connection keep-alive; 
        }

https://stackoverflow.com/questions/29789268/neterr-incomplete-chunked-encoding-nginx

我们遇到的问题,可能是因为磁盘空间满或者日志文件过大导致。

Nginx配置通道Buffer nginx proxy buffer

 proxy_buffering设置

proxy_buffering主要是实现被代理服务器的数据和客户端的请求异步。
为了方便理解,我们定义三个角色,A为客户端,B为代理服务器,C为被代理服务器。

当proxy_buffering开启,A发起请求到B,B再到C,C反馈的数据先到B的buffer上,
然后B会根据proxy_busy_buffer_size来决定什么时候开始把数据传输给A。在此过程中,如果所有的buffer被
写满,数据将会写入到temp_file中。相反,如果proxy_buffering关闭,C反馈的数据实时地通过B传输给A

1. proxy_buffering on;

该参数设置是否开启proxy的buffer功能,参数的值为on或者off。 如果这个设置为off,那么proxy_buffers
和proxy_busy_buffers_size这两个指令将会失效。 但是无论proxy_buffering是否开启
proxy_buffer_size都是生效的。

2. proxy_buffer_size 4k;

该参数用来设置一个特殊的buffer大小的。 从被代理服务器(C)上获取到的第一部分响应数据内容到代理服
务器(B)上,通常是header,就存到了这个buffer中。 如果该参数设置太小,会出现502错误码,这是因为
这部分buffer不够存储header信息。建议设置为4k。

3. proxy_buffers 8 4k;

这个参数设置存储被代理服务器上的数据所占用的buffer的个数和每个buffer的大小。 所有buffer的大小为
这两个数字的乘积。

4. proxy_busy_buffer_size 16k;

在所有的buffer里,我们需要规定一部分buffer把自己存的数据传给A,这部分buffer就叫做busy_buffer
。proxy_busy_buffer_size参数用来设置处于busy状态的buffer有多大。 对于B上buffer里的数据何时传输
给A:
1)如果完整数据大小小于busy_buffer大小,当数据传输完成后,马上传给A; 
2)如果完整数据大小不少于busy_buffer大小,则装满busy_buffer后,马上传给A;

5. proxy_temp_path 1 2;

语法:proxy_temp_path path [level1 level2 level3] 定义proxy的临时文件存在目录以及目录的层级。
例:proxy_temp_path /usr/local/nginx/proxy_temp 1 2; 其中/usr/local/nginx/proxy_temp为临时
件所在目录,1表示层级1的目录名为一个数字(0-9),2表示层级2目录名为2个数字(00-99)

6. proxy_max_temp_file_size ;

设置临时文件的总大小,例如 proxy_max_temp_file_size 100M; 7. proxy_temp_file_wirte_size 设置同
时写入临时文件的数据量的总大小。通常设置为8k或者16k。

proxy_buffer示例

server
{
      listen 80;
      server_name www.bfd-wyl.cn;
      proxy_buffering on;
      proxy_buffer_size 4k;
      proxy_buffers 2 4k;
      proxy_busy_buffers_size 4k;
      proxy_temp_path /tmp/nginx_proxy_tmp 1 2;
      proxy_max_temp_file_size 20M;
      proxy_temp_file_write_size 8k;
	
	location /
	{
	    proxy_pass      http://106.12.74.123:8080/;
        proxy_set_header Host   $host;
        proxy_set_header X-Real-IP      $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

	}

}

Nginx负载均衡策略

负载均衡用于从“upstream”模块定义的后端服务器列表中选取一台服务器接受用户的请求。一个最基本的upstream模块是这样的,模块内的server是服务器列表:

    #动态服务器组
    upstream dynamic_zuoyu {
        server localhost:8080;  #tomcat 7.0
        server localhost:8081;  #tomcat 8.0
        server localhost:8082;  #tomcat 8.5
        server localhost:8083;  #tomcat 9.0
    }

在upstream模块配置完成后,要让指定的访问反向代理到服务器列表:

        #其他页面反向代理到tomcat容器
        location ~ .*$ {
            index index.jsp index.html;
            proxy_pass http://dynamic_zuoyu;
        }

这就是最基本的负载均衡实例,但这不足以满足实际需求;目前Nginx服务器的upstream模块支持6种方式的分配:

轮询 默认方式
weight 权重方式
ip_hash 依据ip分配方式
least_conn 最少连接方式
fair(第三方) 响应时间方式
url_hash(第三方) 依据URL分配方式

在这里,只详细说明Nginx自带的负载均衡策略,第三方不多描述。

1、轮询

最基本的配置方法,上面的例子就是轮询的方式,它是upstream模块默认的负载均衡默认策略。每个请求会按时间顺序逐一分配到不同的后端服务器。

有如下参数:

fail_timeout 与max_fails结合使用。
max_fails
设置在fail_timeout参数设置的时间内最大失败次数,如果在这个时间内,所有针对该服务器的请求都失败了,那么认为该服务器会被认为是停机了,
fail_time 服务器会被认为停机的时间长度,默认为10s。
backup 标记该服务器为备用服务器。当主服务器停止时,请求会被发送到它这里。
down 标记服务器永久停机了。

注意:

  • 在轮询中,如果服务器down掉了,会自动剔除该服务器。
  • 缺省配置就是轮询策略。
  • 此策略适合服务器配置相当,无状态且短平快的服务使用。

2、weight

权重方式,在轮询策略的基础上指定轮询的几率。例子如下:

    #动态服务器组
    upstream dynamic_zuoyu {
        server localhost:8080   weight=2;  #tomcat 7.0
        server localhost:8081;  #tomcat 8.0
        server localhost:8082   backup;  #tomcat 8.5
        server localhost:8083   max_fails=3 fail_timeout=20s;  #tomcat 9.0
    }

在该例子中,weight参数用于指定轮询几率,weight的默认值为1,;weight的数值与访问比率成正比,比如Tomcat 7.0被访问的几率为其他服务器的两倍。

注意:

  • 权重越高分配到需要处理的请求越多。
  • 此策略可以与least_conn和ip_hash结合使用。
  • 此策略比较适合服务器的硬件配置差别比较大的情况。

3、ip_hash

指定负载均衡器按照基于客户端IP的分配方式,这个方法确保了相同的客户端的请求一直发送到相同的服务器,以保证session会话。这样每个访客都固定访问一个后端服务器,可以解决session不能跨服务器的问题。

#动态服务器组
    upstream dynamic_zuoyu {
        ip_hash;    #保证每个访客固定访问一个后端服务器
        server localhost:8080   weight=2;  #tomcat 7.0
        server localhost:8081;  #tomcat 8.0
        server localhost:8082;  #tomcat 8.5
        server localhost:8083   max_fails=3 fail_timeout=20s;  #tomcat 9.0
    }

注意:

  • 在nginx版本1.3.1之前,不能在ip_hash中使用权重(weight)。
  • ip_hash不能与backup同时使用。
  • 此策略适合有状态服务,比如session。
  • 当有服务器需要剔除,必须手动down掉。

4、least_conn

把请求转发给连接数较少的后端服务器。轮询算法是把请求平均的转发给各个后端,使它们的负载大致相同;但是,有些请求占用的时间很长,会导致其所在的后端负载较高。这种情况下,least_conn这种方式就可以达到更好的负载均衡效果。

    #动态服务器组
    upstream dynamic_zuoyu {
        least_conn;    #把请求转发给连接数较少的后端服务器
        server localhost:8080   weight=2;  #tomcat 7.0
        server localhost:8081;  #tomcat 8.0
        server localhost:8082 backup;  #tomcat 8.5
        server localhost:8083   max_fails=3 fail_timeout=20s;  #tomcat 9.0
    }

注意:

  • 此负载均衡策略适合请求处理时间长短不一造成服务器过载的情况。

5、第三方策略

第三方的负载均衡策略的实现需要安装第三方插件。

①fair

按照服务器端的响应时间来分配请求,响应时间短的优先分配。

    #动态服务器组
    upstream dynamic_zuoyu {
        server localhost:8080;  #tomcat 7.0
        server localhost:8081;  #tomcat 8.0
        server localhost:8082;  #tomcat 8.5
        server localhost:8083;  #tomcat 9.0
        fair;    #实现响应时间短的优先分配
    }

②url_hash

按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,要配合缓存命中来使用。同一个资源多次请求,可能会到达不同的服务器上,导致不必要的多次下载,缓存命中率不高,以及一些资源时间的浪费。而使用url_hash,可以使得同一个url(也就是同一个资源请求)会到达同一台服务器,一旦缓存住了资源,再此收到请求,就可以从缓存中读取。

    #动态服务器组
    upstream dynamic_zuoyu {
        hash $request_uri;    #实现每个url定向到同一个后端服务器
        server localhost:8080;  #tomcat 7.0
        server localhost:8081;  #tomcat 8.0
        server localhost:8082;  #tomcat 8.5
        server localhost:8083;  #tomcat 9.0
    }
 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |