0.前提
- ssh免密,改端口,禁用root登录
- 防火墙配置
- 添加用户,赋权
- Oracle 数据库本次是四个对应不同连接
- Oracle 19c数据库 test162 (非CDB/PDB模式)
- Oracle 19c数据库 testdb (CDB/PDB模式 165)
- Oracle 19c数据库 test163 (CDB/PDB模式)
- Oracle 19c数据库 test164 (CDB/PDB模式)
- Oracle 驱动环境Oracle Client 下载 - 官方安装参考
- SQLcl (可选) 官方文档
- jdk-16 Oracle JDK 下载
- tomcat-9.0.45 Tomcat 9 下载
- nginx-1.19.9 下载 wget http://nginx.org/download/nginx-1.19.10.tar.gz
- ords 下载地址 - 官方文档
- APEX 下载地址 - 官方文档
- 检查 Oracle字符集 NLS_CHARACTERSET AL32UTF8 后面会涉及到中文乱码
1 | select * from nls_database_parameters where parameter like '%CHARACTERSET%'; |
配置多个数据库
- test162 对应url http://xxxx.com/edex/test162/f?p=4000
- testdb 对应url http://xxxx.com/edex/testdb/f?p=4000
- test163 对应url http://xxxx.com/edex/test163/f?p=4000
- test164 对应url http://xxxx.com/edex/test164/f?p=4000
Oracle
整体架构
1.Tomcat(Java,tomcat)
1.1.JAVA
1 | rpm -ivh jdk-16_linux-x64_bin.rpm |
1.2.Tomcat
1 | unzip apache-tomcat-9.0.45.zip |
1.设置tomcat后台进程及自启 参考
vim /etc/systemd/system/tomcat.service
TODO 参数可能要改
1 | [Unit] |
优化
1
2rm -rf /opt/tomcat/webapps/manager /opt/tomcat/webapps/host-manager
rm -rf ../webapps/docs ../webapps/examplesServer.xml 配置
vim /opt/tomcat/conf/server.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20...
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
scheme="https"
redirectPort="8443" /> <!--奇奇怪怪的oauth2回调跳转 -->
...
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<!-- nginx配置-->
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
internalProxies="127\.0\.0\.1|10\.x\.x\.x"/> <!--nginx服务器地址 -->
</Host>
...
2.Apex
2.1. Oracle Client
Oracle Client 下载 - 官方安装参考 - Oracle Client Sqlplus 下载
1 | mkdir /opt/oracle_client |
2.2. SQLcl(可选)
官方文档 - Oracle-base 文档 - SQLcl这个可爱的小工具,来了解一下呀~ 微信
1 | unzip sqlcl-20.4.2.35.2359.zip |
2.3. Apex
- CDB/PDB模式 PBD 本地安装apex
1 | <!--创建pdb--> |
用户 | 环境 | 密码 | 备注 |
---|---|---|---|
APEX_PUBLIC_USER | testdb(165) | S9dFCaUaC | 最低特权帐户用于通过ords和Oracle进行Application Express配置mod_plsql。 |
- 非CDB/PDB模式安装apex
1 |
|
用户 | 环境 | 密码 | 备注 |
---|---|---|---|
APEX_PUBLIC_USER | test162 | S9dFCaUaC | 最低特权帐户。 |
- 设置internal工作区admin用户,配置RESTful服务
1 |
|
- 安装中文支持
1 | <!--如果需要 PDB模式 切换库(PDB)--> |
APEX打补丁
unzip p30392181_1920_Generic.zip
cat 30392181/README.txt
按照说明执行
1
2
3
4
5
6
7
8...
sqlplus "sys/ as sysdba"
<!--切SESSION -->
<!--以下任选其一-->
1. @catpatch.sql -- 适用于Oracle数据库11.2及更早版本,适用于非CDB,以及APEX没有安装在根目录下的CDB
2. @catpatch_con.sql -- for CDB where Application Express is installed in the root
3. @catpatch_appcon.sql -- for installations where Application Express is installed in an application container
...验证补丁
1
select APEX_INSTANCE_ADMIN.GET_PARAMETER( 'APEX_19_2_0_PATCH_30392181' ) from dual;
备注留用
1 | <!--删除Apex--> |
Apex ACl 配置
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
47ALTER SESSION SET CONTAINER = testDB;
declare
l_acl_name varchar2(30) := 'HttpsServiceACLConfig.xml';
l_principal varchar2(20) := 'APEX_190200';
begin
begin
dbms_network_acl_admin.drop_acl(acl => l_acl_name);
exception
when others then
null; -- ACL does not exist yet
end;
dbms_network_acl_admin.create_acl(
acl => l_acl_name
, description => 'ding ding https'
, principal => l_principal
, is_grant => true
, privilege => 'connect'
, start_date => systimestamp
, end_date => null
);
dbms_network_acl_admin.add_privilege(
acl => l_acl_name
, principal => l_principal
, is_grant => true
, privilege => 'resolve'
, start_date => systimestamp
, end_date => null
);
-- 添加钉钉
dbms_network_acl_admin.assign_acl(
acl => l_acl_name
, host => '*.dingtalk.com'
, lower_port => 443
, upper_port => 443
);
-- 添加
dbms_network_acl_admin.assign_acl(
acl => l_acl_name
, host => '*.oracle.com'
, lower_port => 443
, upper_port => 443
);
-- 删除
-- DBMS_NETWORK_ACL_ADMIN.UNASSIGN_ACL(host =>'*.oracle.com');
commit;
end;Apex wallet 配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15cd $ORACLE_HOME
pwd
<!--创建wallet目录-->
mkdir wallets
<!--创建wallet-->
orapki wallet create -wallet /xx/xx/xx/xx/xxx/xxx/wallets/https_wallet -pwd xxxxxxxx -auto_login
<!--复制证书--> # 可以参考 7. 服务器验证证书 第一个 ---BEGIN CERTIFICATE---END CERTIFICATE---
<!--授权-->
chown -R oracle:oinstall /u01/ssl
<!--添加证书-->
orapki wallet add -wallet /xx/xx/xx/xx/xxx/xxx/wallets/https_wallet -trusted_cert -cert "/u01/ssl/sts.cer" -pwd xxxxxxxx
<!--查看wallet-->
orapki wallet display -wallet /xx/xx/xx/xx/xxx/xxx/wallets/https_wallet
<!--清空wallet-->
orapki wallet remove -wallet /xx/xx/xx/xx/xxx/xxx/wallets/https_wallet -trusted_cert_all -pwd xxxxx验证https
1
2
3
4
5select
apex_web_service.make_rest_request(p_url=>'https://xxxxx.xxxx.com/adfs/oauth2/token',
p_http_method => 'GET',
p_wallet_path => 'file:/xx/xx/xx/xx/xxx/xxx/wallets/https_wallet')
from dual;
8.1. 正常请求post接口
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
declare
l_clob1 clob;
l_response_json_clob clob;
L_1 clob := '';
begin
apex_json.initialize_clob_output;
apex_json.open_object;
apex_json.write('AppId', '');
apex_json.write('AppSecret', 'B');
apex_json.open_array('Email');
for i in 1..2
loop
apex_json.open_object;
apex_json.write('from', '@.com');
apex_json.write('to', '@.com');
apex_json.write('subject', '下');
apex_json.write('body', L_1);
apex_json.close_object;
end loop;
apex_json.close_array;
apex_json.close_object;
l_clob1 := apex_json.get_clob_output;
apex_json.free_output;
apex_web_service.g_request_headers(1).name := 'Content-Type';
apex_web_service.g_request_headers(1).VALUE := 'application/json';
l_response_json_clob := apex_web_service.make_rest_request(
p_url => 'http://xxxx/api/EmailSender/SendEmail',
p_http_method => 'POST',
p_body => l_clob1);
apex_debug.warn(l_response_json_clob);
end;
服务器验证证书
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
49
50
51
52
53
54
55
56
57
58
59
60openssl s_client -connect www.dingtalk.com:443 -tls1 -showcerts
...
CONNECTED(00000003)
depth=2 C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CA
verify return:1
depth=1 C = BE, O = GlobalSign nv-sa, CN = GlobalSign Organization Validation CA - SHA256 - G2
verify return:1
depth=0 C = CN, ST = ZheJiang, L = HangZhou, O = "Alibaba (China) Technology Co., Ltd.", CN = *.dingtalk.com
verify return:1
---
Certificate chain
0 s:/C=CN/ST=ZheJiang/L=HangZhou/O=Alibaba (China) Technology Co., Ltd./CN=*.dingtalk.com
i:/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Organization Validation CA - SHA256 - G2
-----BEGIN CERTIFICATE-----
MIIGYDCCBUigAwIBAgIMCZwLPIt+KS8mrSqZMA0GCSqGSIb3DQEBCwUAMGYxCzAJ
......
Dn6XwwJTuLDHvdZhE54cswjBpc0OizT63hRg6X+C5syJB8CKLSJxJGmPThWuNbpI
MVUwRA==
-----END CERTIFICATE-----
1 s:/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Organization Validation CA - SHA256 - G2
i:/C=BE/O=GlobalSign nv-sa/OU=Root CA/CN=GlobalSign Root CA
-----BEGIN CERTIFICATE-----
MIIEaTCCA1GgAwIBAgILBAAAAAABRE7wQkcwDQYJKoZIhvcNAQELBQAwVzELMAkG
.....
SOlCdjSXVWkkDoPWoC209fN5ikkodBpBocLTJIg1MGCUF7ThBCIxPTsvFwayuJ2G
K1pp74P1S8SqtCr4fKGxhZSM9AyHDPSsQPhZSZg=
-----END CERTIFICATE-----
---
Server certificate
subject=/C=CN/ST=ZheJiang/L=HangZhou/O=Alibaba (China) Technology Co., Ltd./CN=*.dingtalk.com
issuer=/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Organization Validation CA - SHA256 - G2
---
No client certificate CA names sent
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 3453 bytes and written 315 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1
Cipher : ECDHE-RSA-AES128-SHA
Session-ID: 795C7128D1F65CD328662802B1DCD0DC2D753A185568EE1A9BC9ED8172078942
Session-ID-ctx:
Master-Key: B5BE8CAF4C8CE29D0945324B39FEDC3E40B293DD7A5B8395248169B8AAC3587134E6D3B9D0ADFA75E3ADFB251233185D
Key-Arg : None
Krb5 Principal: None
PSK identity: None
PSK identity hint: None
TLS session ticket lifetime hint: 600 (seconds)
TLS session ticket:
0000 - 86 a7 5b 81 b5 e0 db 84-29 fd 41 bd cb 2c 65 fc ..[.....).A..,e.
Start Time: 1585991577
Timeout : 7200 (sec)
Verify return code: 0 (ok)
3.Ords
-1. 注意如果是多个环境需要验证下ords的版本 java -jar edex.war version
- 设置URL前缀
1 | <!--xxxx.com/ords 将变成 xxxx.com/edex--> |
0.1. 安装或升级 ordsjava -jar edex.war schema --database test162
- 添加数据库 test162 官方提示说明
1 | <!--配置ords连接数据库 test162--> |
- 配置指向 如:
xxx.com/edex/test162
将指向 test162这个数据库
1 | java -jar edex.war map-url --type base-path /test162 test162 |
- 添加Ords相关配置(实测影响挺大的.) 官方文档
1 | ls /opt/ords/conf/ords/ |
3.Nginx
安装基础环境
- GCC编辑器
yum install -y gcc
- gcc-c++ 自定义Nginx Http模块
yum install -y gcc-c++
- PCRE 函数库支持正则表达式
yum install -y pcre pcre-devel
- zlib HTTP包gzip压缩
yum install -y zlib zlib-devel
- OpenSSL 开发库Https支持
yum install -y openssl openssl-devel
- GCC编辑器
解压
tar -zxvf nginx-1.19.10.tar.gz
- 参数说明见官网文档
- –with-debug
- –with-http_ssl_module
- –with-http_v2_module
- –with-http_realip_module
- –with-http_gzip_static_module
- –with-http_stub_status_module
- –with-http_sub_module
1
2
3
4
5
6
7
8
9cd nginx-1.19.10
<!--编译三部曲-->
./configure --with-debug --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_sub_module
<!--查看编译后的插件-->
cat auto/options | grep YES --color
make
4.1. 升级
备份旧版本和配置文件(可选)
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old拷贝新版本
cp ./objs/nginx /usr/local/nginx/sbin/nginx验证配置文件
/usr/local/nginx/sbin/nginx -t通知正在运行的Nginx
kill -s SIGUSR2(nginx会将/usr/local/nginx/logs/pid文件重命名) 退出旧版本
kill -s SIGQUIT <旧版本Nginx master pid>清理旧版本
4.2. 新安装 make install
- nginx配置
1 | user nginx; |
拷贝apex静态文件
cp -fr /opt/tomcat/webapps/i /usr/local/nginx/html
SSL配置
1
2
3
4
5
6server {
listen 443 ssl http2;
ssl_certificate /etc/nginx/certificate/crt_2021/wcom.crt;
ssl_certificate_key /etc/nginx/certificate/crt_2021/wcom.key;
ssl_session_cache shared:SSL:1m;
ssl_prefer_server_ciphers on;
后期处理
常见问题
使用Oauth2 认证时出现奇奇怪怪的重定向
如:redirect_uri=https://xx.xx.com:80/ords
解决办法 tomcat server.xml 配置 添加scheme="https"
1
2
3
4
5<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
proxyPort="443"
scheme="https"
redirectPort="8443" />