
本文是鋼哥的Oracle APEX系列文章中的第五篇,完整 Oracle APEX 系列文章如下:
- Oracle APEX 系列文章1:Oracle APEX, 讓你秒變?nèi)珬i_發(fā)的黑科技
- Oracle APEX 系列文章2:在阿里云上打造屬于你自己的APEX完整開發(fā)環(huán)境 (準(zhǔn)備工作)
- Oracle APEX 系列文章3:在阿里云上打造屬于你自己的APEX完整開發(fā)環(huán)境 (安裝CentOS, Tomcat, Nginx)
- Oracle APEX 系列文章4:在阿里云上打造屬于你自己的APEX完整開發(fā)環(huán)境 (安裝XE, ORDS, APEX)
- Oracle APEX 系列文章5:在阿里云上打造屬于你自己的APEX完整開發(fā)環(huán)境 (進(jìn)一步優(yōu)化)
- Oracle APEX 系列文章6:Oracle APEX 到底適不適合企業(yè)環(huán)境?
引言
在這一章節(jié)里,鋼哥將帶領(lǐng)大家進(jìn)一步優(yōu)化我們的開發(fā)環(huán)境,讓我們的免費(fèi)開發(fā)環(huán)境更“生產(chǎn)”,優(yōu)化思路和方法也完全可以用在生產(chǎn)環(huán)境。
優(yōu)化 Tomcat
刪除Tomcat自帶的不必要的文件是有必要的,最大限度保證系統(tǒng)安全。
rm -Rf /u01/tomcat/webapps/examples
由于我們的 Oracle XE 數(shù)據(jù)庫跟 Tomcat 都是開機(jī)自啟動(dòng)的,但在數(shù)據(jù)庫啟動(dòng)完畢之前,部署在 Tomcat 服務(wù)器上的 ORDS 應(yīng)用就會(huì)隨著 Tomcat 的啟動(dòng)而進(jìn)行初始化了,這時(shí)候初始化肯定不正常(連接池報(bào)錯(cuò)等),不得不重啟 Tomcat 服務(wù)才行。所以我們要對 tomcat.service進(jìn)行必要的修改,讓tomcat等待數(shù)據(jù)庫啟動(dòng)完畢再啟動(dòng)。
/etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat 8 Servlet Container
After=syslog.target network.target oracle-xe.service
Wants=oracle-xe.service
加載啟動(dòng)腳本,下次重啟就會(huì)按照新的自啟動(dòng)腳本啟動(dòng)了。
systemctl daemon-reload
優(yōu)化 Oracle XE 數(shù)據(jù)庫
切換到 oracle 賬戶,用 sqlplus 登錄數(shù)據(jù)庫,進(jìn)行必要的優(yōu)化。
su - oracle
sqlplus / as sysdba
-- 禁用匿名數(shù)據(jù)庫賬號(hào)
alter user anonymous account lock;
-- 刪除自帶的數(shù)據(jù)庫schema
drop user hr cascade;
-- 修改默認(rèn)的密碼規(guī)則(默認(rèn)180天要重新修改所有密碼的)
alter profile default limit password_life_time unlimited;
-- 優(yōu)化數(shù)據(jù)庫核心參數(shù)
alter system set sessions=250 scope=spfile;
alter system set processes=200 scope=spfile;
alter system set memory_target=1G scope=spfile;
alter system set memory_max_target=1G scope=spfile;
alter system set job_queue_processes=100 scope=spfile;
-- 為我們后面新建的APEX workspace創(chuàng)建單獨(dú)的表空間
create tablespace apex datafile '/u01/app/oracle/oradata/XE/apex.dbf' size 256M reuse autoextend on next 100M maxsize unlimited;
-- 為APEX workspaces創(chuàng)建單獨(dú)的數(shù)據(jù)庫schema
create user apex identified by "YourPasswordHere" default tablespace apex temporary tablespace temp;
alter user apex quota unlimited on apex;
grant unlimited tablespace to apex;
grant create session to apex;
grant create cluster to apex;
grant create dimension to apex;
grant create indextype to apex;
grant create job to apex;
grant create materialized view to apex;
grant create operator to apex;
grant create procedure to apex;
grant create sequence to apex;
grant create snapshot to apex;
grant create synonym to apex;
grant create table to apex;
grant create trigger to apex;
grant create type to apex;
grant create view to apex;
-- 重啟數(shù)據(jù)庫
shutdown immediate
startup
-- 退出
exit
優(yōu)化 ORDS 配置
調(diào)整/u01/ords/config/ords/defaults.xml中的參數(shù)值,具體如下:
<entry key="jdbc.InitialLimit">10</entry>
<entry key="jdbc.MinLimit">10</entry>
<entry key="jdbc.MaxLimit">60</entry>
重啟 tomcat 服務(wù)以便使 ORDS 配置生效
systemctl restart tomcat
優(yōu)化 Nginx
修改/etc/nginx/nginx.conf,以下是我的nginx.conf文件內(nèi)容:
user nginx;
worker_processes auto;
worker_rlimit_nofile 10000;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
#==告訴nginx收到一個(gè)新鏈接通知后接受盡可能多的鏈接
multi_accept on;
#==設(shè)置用于復(fù)用客戶端線程的輪訓(xùn)方法
use epoll;
}
http {
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;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset UTF-8;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
#==設(shè)置nginx采用gzip壓縮的形式發(fā)送數(shù)據(jù),減少發(fā)送數(shù)據(jù)量,但會(huì)增加請求處理時(shí)間及CPU處理時(shí)間,需要權(quán)衡
gzip on;
#==加vary給代理服務(wù)器使用,針對有的瀏覽器支持壓縮,有個(gè)不支持,根據(jù)客戶端的HTTP頭來判斷是否需要壓縮
gzip_vary on;
gzip_http_version 1.0;
gzip_types text/plain application/javascript application/x-javascript text/css;
gzip_min_length 1024;
gzip_comp_level 3;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
# 增加了/i/目錄的請求轉(zhuǎn)發(fā)規(guī)則,/i/目錄是APEX默認(rèn)的靜態(tài)文件目錄別名。
location ^~ /i/ {
alias /u01/tomcat/webapps/i/;
}
# 增加/ords/目錄的請求轉(zhuǎn)發(fā)規(guī)則,所有形如http://xxx.xxx.xxx.xxx/ords/的請求都會(huì)自動(dòng)轉(zhuǎn)發(fā)到http://xxx.xxx.xxx.xxx:8080/ords/上
# 即APEX請求都會(huì)由Tomcat接管
location ^~ /ords/ {
proxy_pass http://localhost:8080/ords/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 20m;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
重啟 Nginx 服務(wù)
systemctl restart nginx
最終測試 APEX
打開瀏覽器,再次訪問 http://47.100.207.171/ords,應(yīng)該可以看到APEX的登錄頁面了。

總結(jié)
本章節(jié)主要帶著大家過了一遍APEX常見的服務(wù)器優(yōu)化配置,這些用于個(gè)人開發(fā)已經(jīng)足夠了。如果搭建生產(chǎn)環(huán)境,還需要配置SSL證書等操作,有興趣的同學(xué)可以看這篇文章:申請 Let's Encrypt 的免費(fèi)通配符證書。
關(guān)于 Oracle APEX 的使用,大家可以參考 Oracle Learning Library 上面的 Oracle APEX 5.1 系列教程。
后面我也會(huì)給大家?guī)砀嘤嘘P(guān) Oracle APEX 使用方面的文章,以及一些個(gè)人工作中遇到的問題和經(jīng)驗(yàn)積累,請大家拭目以待。