KONG

KONG

八月 13, 2019

KONG

一、OpenResty安装

1.编译环境的部署

1
2
3
4
5
6
7
8
[nginx@lp home]#yum install -y gcc gcc-c++ make zlib
zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng
libpng-devel freetype freetype-devel libxml2 libxml2-
devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-
devel ncurses ncurses-devel curl curl-devel e2fsprogs
e2fsprogs-devel krb5 krb5-devel openssl openssl-devel
openldap openldap-devel nss_ldap openldap-clients
openldap-servers # 编译环境

2.必备插件

1
2
3
4
5
[kong@nginx1 ~]$ yum install -y readline-devel pcredevel
openssl-devel
[kong@nginx1 ~]$ wget
https://openresty.org/download/openresty-1.13.6.2.tar.gz
[kong@nginx1 ~]$ tar xvf openresty-1.13.6.2.tar.gz

3.安装

到openresty下载安装最新的编译版本,然后进行编译。
在这之前需要更改.c文件,把响应头当中的nginx的版本号隐藏,这个是必须
的!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[kong@nginx1 openresty-1.13.6.2]$ vim ./bundle/nginx-
1.13.6/src/http/ngx_http_header_filter_module.c
static u_char ngx_http_server_string[] = "Server:
opresty " CRLF;
static u_char ngx_http_server_full_string[] = "Server "
NGINX_VER CRLF;
static u_char ngx_http_server_build_string[] = "Server "
NGINX_VER_BUILD CRLF;

# 更改成下面那样!!!然后再编译

static u_char ngx_http_server_string[] = "Server: Egaga-
Web" CRLF;
static u_char ngx_http_server_full_string[] = "Server:
Egaga-Web" NGINX_VER CRLF;
static u_char ngx_http_server_build_string[] = "Server:
Egaga-Web" NGINX_VER_BUILD CRLF;

更改404版本的信息,只需要在nginx.conf当中配置server_tokens off;

开始编译

我在网站当中把这个下载下来了,然后进入到openresty,这里面有很多

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
文件,其中进入bundle,然后下载必要的模块,然后添加到当中
[kong@nginx1 ~]$ cd nginx/openresty-1.13.6.1/
[kong@nginx1 openresty-1.13.6.2]$ ls
build bundle configure COPYRIGHT Makefile patches
README.markdown README-win32.txt util
[kong@nginx1 openresty-1.13.6.2]$ cd bundle/
[kong@nginx1 bundle]$wget
http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
[kong@nginx1 bundle]$ tar -zxvf ngx_cache_purge-
2.3.tar.gz
[kong@nginx1 bundle]$ wget
https://github.com/yaoweibin/nginx_upstream_check_module
/archive/v0.3.0.tar.gz
[kong@nginx1 bundle]$ tar -zxvf v0.3.0.tar.gz
[kong@nginx1 bundle]$ wget
https://codeload.github.com/weibocom/nginx-upsyncmodule/
zip/master
[kong@nginx1 bundle]$ mv master nginx-upsync-modulemaster.
zip
[kong@nginx1 bundle]$ unzip nginx-upsync-modulemaster.
zip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[kong@nginx1 bundle]$ wget
https://codeload.github.com/gnosek/nginx-upstreamfair/
zip/master
[kong@nginx1 bundle]$ mv master nginx-upstream-fairmaster.
zip
[kong@nginx1 bundle]$ unzip nginx-upstream-fairmaster.
zip
[kong@nginx1 bundle]$ vim nginx-upstream-fair-master
[kong@nginx1 bundle]$ vim nginx-upstream-fairmaster/
ngx_http_upstream_fair_module.c

# 注意安装之前,需要更改配置,把其中的一段配置更改为后面的配置,才

可以顺利编译!!!

# 更改前:

if (us->port == 0 && us->default_port == 0) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"no port in upstream \"%V\" in
%s:%ui",
&us->host, us->file_name, us-

> line);
> return NGX_ERROR;
> }
> ngx_memzero(&u, sizeof(ngx_url_t));
> u.host = us->host;
> u.port = (in_port_t) (us->port ? us->port : us-
> default_port);

# 更改后:

if (us->port == 0) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"no port in upstream \"%V\" in
%s:%ui",
&us->host, us->file_name, us-

> line);
> return NGX_ERROR;
> }
> ngx_memzero(&u, sizeof(ngx_url_t));
> u.host = us->host;
> u.port = us->port;
> [nginx@lp bundle]# cd ..

# 编译策略①
1
2
3
4
5
6
7
8
9
10
11
12
[kong@nginx1 openresty-1.13.6.2]$ ./configure --
prefix=/home/kong/openresty/openresty_1.13.6.2 --withluajit
--with-http_ssl_module --user=nginx --group=nginx
--with-http_realip_module --with-threads --withhttp_
auth_request_module --with-stream --withstream_
ssl_module --with-stream_realip_module --withpcre
--with-pcre-jit --with-http_stub_status_module -
-add-module=./bundle/ngx_cache_purge-2.3/ --addmodule=./
bundle/nginx_upstream_check_module-0.3.0/ --
add-module=./bundle/nginx-upstream-fair-master --addmodule=./
bundle/nginx-upsync-module-master && make &&
make install
注意:软件的安装路径一定是提前设定好的,不能再编译安装好了以后,改变
文件的位置,比如放在更底下的子目录,会导致Nginx无法启动

二、安装包管理工具

1
2
3
4
5
6
7
8
9
[kong@nginx1 ~]$ wget
https://luarocks.org/releases/luarocks-3.0.4.tar.gz
[kong@nginx1 ~]$ tar xvf luarocks-3.0.4.tar.gz
[kong@nginx1 ~]$ cd luarocks-3.0.4/
[kong@nginx1 ~]$ ./configure --
prefix=/home/kong/luarocks && make && make install
[kong@nginx1 ~]$ vim .bash_profile
PATH=$PATH:/home/kong/luarocks/bin
[kong@nginx1 ~]$ source .bash_profile

三、安装KONG

1
2
3
4
5
6
[kong@nginx1 ~]$ wget
https://codeload.github.com/Kong/kong/zip/master
[kong@nginx1 ~]$ mv master kong-master.zip
[kong@nginx1 ~]$ unzip kong-master.zip
[kong@nginx1 ~]$ vim .bash_profile
PATH=$PATH:/home/kong/kong-master/bin

四、安装数据库postgresql

1.编译安装

1
2
3
4
5
6
7
8
9
10
11
12
[kong@nginx1 ~]$
https://ftp.postgresql.org/pub/source/v11.0/postgresql-
11.0.tar.gz
[kong@nginx1 ~]$ tar xvf postgresql-11.0.tar.gz
[kong@nginx1 ~]$ cd postgresql-11.0/
[kong@nginx1 ~]$ ./configure --
prefix=/home/kong/postgresql/pgsql11.0 --withpgport=
5432 --with-perl --with-python --with-tcl --withopenssl
--with-pam --without-ldap --with-libxml --
with-libxslt --enable-thread-safety --with-walblocksize=
16 --with-blocksize=16 --enable-dtrace --
enable-debug

2.安装systemtap插件

[root@nginx1 ~]# yum install systemtap systemtap-sdtdevel
[root@nginx1 ~]# yum update -y kernel
[root@nginx1 ~]# yum install -y kernel.x86_64 kerneldevel.
x86_64

检验是否成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@nginx1 ~]# stap -ve 'probe begin { log("hello
world") exit() }'
Pass 1: parsed user script and 473 library scripts using
240244virt/42156res/3428shr/38788data kb, in
150usr/160sys/369real ms.
Pass 2: analyzed script: 1 probe, 2 functions, 0 embeds,
0 globals using 241168virt/43204res/3596shr/39712data
kb, in 0usr/0sys/4real ms.
Pass 3: translated to C into
"/tmp/stapIsCD4v/stap_852a2c38932b1a2bc2f953ac41c15db2_1
139_src.c" using 241168virt/43812res/4176shr/39712data
kb, in 0usr/0sys/0real ms.
Pass 4: compiled C into
"stap_852a2c38932b1a2bc2f953ac41c15db2_1139.ko" in
5760usr/1600sys/7781real ms.
Pass 5: starting run.
hello world
Pass 5: run completed in 10usr/30sys/314real ms.

3.其他常见问题解决方式

1
2
3
4
5
[root@nginx1 ~]# yum -y install perl-ExtUtils-Embed
readline readline-devel zlib zlib-devel openssl
openssl-devel pam pam-devel libxml2 libxml2-devel
libxslt libxslt-devel tcl tcl-devel openldap openldapdevel
python python-devel gcc-c++

4.开始编译

1
2
[kong@nginx1 postgresql-11.0]$ gmake world && gmake
install-world

5.添加环境变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[kong@nginx1 ~]$ vim .bash_profile

# add PG env

export PGHOME=/home/kong/postgresql/pgsql11.0
export PGDATA=/home/kong/postgresql/db/pgdata
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.utf8
export DATE=`date +"%Y-%m-%d %H:%M:%S"`
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
alias rm='rm -i'
alias ll='ls -lh'
#alias pg_start='pg_ctl start -D $PGDATA'
#alias pg_stop='pg_ctl stop -D $PGDATA -m fast'
#psql -h 主机名 -p 端口号 -U 用户名 -W(强制口令提示) [-d]数据
库名
#psql -h $GHOST -p $PGPORT -U $PGUSER -W -d $PGDATABASE
#PGHOST 设置数据库服务器名。 如果它以一个斜杠开头,那么它声明一个
Unix 域套接字而不是 TCP/IP 通讯; 其值就是该套接字文件存储的目录
(在缺省安装中,这个目录会是 /tmp)
#export PGHOST=$PGDATA
export PGHOST=localhost
#PGPORT 设置 TCP 端口号或者设置与 PostgreSQL 通讯的 Unix 域套
接字的文件扩展。
export PGPORT=5432
export PGUSER=kong #用于与数据库连接的用户名,initdb -U
posgtres指定
#export PGDATABASE=demo#数据库名
[kong@nginx1 ~]$ source .bash_profile

# 记得创建相关文件夹

6.检验数据库版本

1
2
[kong@nginx1 ~]$ psql -V
psql (PostgreSQL) 11.0

7.初始化数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[kong@nginx1 ~]$ initdb -D $PGDATA -E UTF8 --locale=C -U
postgres -W
The files belonging to this database system will be
owned by user "kong".
This user must also own the server process.
The database cluster will be initialized with locale
"C".
The default text search configuration will be set to
"english".
Data page checksums are disabled.
Enter new superuser password:
Enter it again:
creating directory /home/kong/db/pgdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local
connections
You can change this by editing pg_hba.conf or using the
option -A, or
--auth-local and --auth-host, the next time you run
initdb.
Success. You can now start the database server using:
pg_ctl -D /home/kong/db/pgdata -l logfile start

8.启动数据库

1
2
3
[kong@nginx1 ~]$ pg_ctl start -D $PGDATA -l pgsql.log
waiting for server to start.... done
server started

9.检查启动后的数据库

1
2
3
4
5
6
[kong@nginx1 ~]$ pg_ctl status
pg_ctl: server is running (PID: 12446)
/home/kong/postgresql/pgsql11.0/bin/postgres
[kong@nginx1 ~]$ pg_ctl stop
waiting for server to shut down.... done
server stopped

五、启动KONG

1.添加OpenResty的环境变量

1
2
3
[kong@nginx1 ~]$ vim .bash_profile
PATH=$PATH:/home/kong/openresty/openresty_1.13.6.2/bin/
[kong@nginx1 ~]$ source .bash_profile