Ching-Chuan Chen's Blogger

Statistics, Machine Learning and Programming

0%

deployment of Oracle database

這一篇文章主要是在CentOS 7.4最小安裝下去部署Oracle database

我會建立Oracle database的主要原因是

為了下一篇測試從Oracle database拉資料到sqoop

(Note: modified at 2018/04/19)

  1. 準備工作

這部分照著前一篇spark的布置即可

  1. 安裝java
1
2
3
4
5
6
7
8
9
10
# 下載並安裝java
curl -v -j -k -L -H "Cookie: oraclelicense=accept-securebackup-cookie" \
http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.rpm \
-o jdk-8u171-linux-x64.rpm
sudo yum install -y jdk-8u171-linux-x64.rpm
# setup environment
sudo tee -a /etc/profile << "EOF"
export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
EOF
source /etc/profile
  1. 安裝Oracle database

a. set up hostname

sudo hostnamectl set-hostname oracleTest.test.com就會立即生效了

b. 創建Oracle database的group, user

1
2
3
4
5
sudo groupadd oinstall
sudo groupadd dba
sudo useradd -g oinstall -G dba oracle
# 更改密碼
sudo passwd oracle

c. 設定系統變數

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo tee -a /etc/sysctl.conf << "EOF"
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1987162112
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
EOF

可以用sysctl -psysctl -a來確定是否設定成功

d. 設定系統安全性

1
2
3
4
5
6
7
8
9
10
sudo tee -a /etc/security/limits.conf << "EOF"
oracle soft nproc 131072
oracle hard nproc 131072
oracle soft nofile 131072
oracle hard nofile 131072
oracle soft core unlimited
oracle hard core unlimited
oracle soft memlock 50000000
oracle hard memlock 50000000
EOF

e. 修改hosts

1
2
3
sudo tee -a /etc/hosts << "EOF"
192.168.0.120 oracleTest oracleTest.test.com localhost localhost.localdomain
EOF

f. 安裝需要元件

1
2
3
4
5
6
7
sudo yum install -y zip unzip binutils.x86_64 compat-libcap1.x86_64 gcc.x86_64 gcc-c++.x86_64 \
glibc.i686 glibc.x86_64 glibc-devel.i686 glibc-devel.x86_64 ksh compat-libstdc++-33 libaio.i686 \
libaio.x86_64 libaio-devel.i686 libaio-devel.x86_64 libgcc.i686 libgcc.x86_64 libstdc++.i686 \
libstdc++.x86_64 libstdc++-devel.i686 libstdc++-devel.x86_64 libXi.i686 libXi.x86_64 libXtst.i686 \
libXtst.x86_64 make.x86_64 sysstat.x86_64 unixODBC.x86_64 unixODBC-devel.x86_64 libaio.i386
# for installation
sudo yum groupinstall "X Window System" "Fonts" -y

g. 下載安裝檔案

可以從oracle網站點這下載下來,然後用sftp上傳到你的VM

上傳常見的工具是FileZilla,在google很容易找到

至於使用方法搜尋一下也能找的到

假設下載到目前最新版本:12c Release 1

那檔名應該是:linuxamd64_12102_database_1of2.zip跟linuxamd64_12102_database_2of2.zip

h. 解壓縮檔案

1
2
sudo unzip linuxamd64_12102_database_1of2.zip -d /stage/
sudo unzip linuxamd64_12102_database_2of2.zip -d /stage/

i. 建立需要的資料夾

1
2
3
4
5
6
7
8
sudo mkdir /u01
sudo mkdir /u02
sudo chown -R oracle:oinstall /u01
sudo chown -R oracle:oinstall /u02
sudo chmod -R 775 /u01
sudo chmod -R 775 /u02
sudo chmod g+s /u01
sudo chmod g+s /u02

j. 利用Xming安裝 (putty in windows,如果其他系統要再用別的方式)

(i) 下載Xming:https://sourceforge.net/projects/xming/
(ii) 安裝Xming
(iii) Putty設定中的Connection/SSH/X11的分頁裡面,啟用X11,並設定X display location為localhost:0
(iv) 登入伺服器,使用者用oracle
(v) 使用/stage/database/runInstaller (出現要設定DISPLAY問題可以先打xhost +,然後在執行一次)
(vi) 細部的安裝設定可以參考 https://wiki.centos.org/zh-tw/HowTos/Oracle12onCentos7

k. 設定防火牆

1
2
3
4
5
6
7
sudo firewall-cmd --zone=public --add-port=1521/tcp --add-port=1539/tcp \
--add-port=5500/tcp --add-port=5520/tcp --add-port=3938/tcp \
--permanent
sudo firewall-cmd --reload
# 確定有開啟port
sudo firewall-cmd --list-ports
# 1521/tcp 1539/tcp 3938/tcp 5500/tcp 5520/tcp

l. 設定環境變數

1
2
3
4
5
6
7
8
9
10
11
12
13
14
tee -a /home/oracle/.bash_profile << EOF
export TMPDIR=$TMP
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/lib64
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
EOF

tee -a /etc/bashrc << "EOF"
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
EOF
source /etc/bashrc

m. 設定對外連線

編輯/u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora檔案,增加一行:

1
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.120)(PORT = 1539))

n. 設定自動啟動

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
tee /etc/sysconfig/oral_envs << EOF
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
ORACLE_SID=orcl
EOF

tee /usr/lib/systemd/system/oral@lsnrctl.service << EOF
[Unit]
Description=Oracle Net Listener
After=network.target

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/oral_envs
ExecStart=/u01/app/oracle/product/12.1.0/dbhome_1/bin/lsnrctl start
ExecStop=/u01/app/oracle/product/12.1.0/dbhome_1/bin/lsnrctl stop
User=oracle

[Install]
WantedBy=multi-user.target
EOF

tee /usr/lib/systemd/system/oral@oracledb.service << EOF
[Unit]
Description=Oracle Database service
After=network.target lsnrctl.service

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/oral_envs
ExecStart=/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart \$ORACLE_HOME
ExecStop=/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbshut \$ORACLE_HOME
User=oracle

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable oral@lsnrctl oral@oracledb

o. 確定database狀態

確定LISTENER:$ORACLE_HOME/bin/lsnrctl status LISTENER 或是 systemctl status oral@lsnrctl

確定db是否有正常啟動服務:ps -ef | grep ora 或是 systemctl status oral@oracledb

也可以透過$ORACLE_HOME/bin/sqlplus system/password@oracleServer:1539/orcl來連線

(password請記得換成你在安裝時設定的密碼)

去試試看是否有正常啟動,並且也可以寫SQL試試看

正常啟動的文字顯示如下:

1
2
3
4
5
6
7
8
9
10
11
SQL*Plus: Release 12.1.0.2.0 Production on Fri Jul 29 21:27:14 2016

Copyright (c) 1982, 2014, Oracle. All rights reserved.

Last Successful login time: Fri Jul 29 2016 21:20:01 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL>

連上後可以測試看看select OWNER,TABLE_NAME from all_tables;就會跑出所有表格的名字跟主人名字

另外補充一個工具,Oracle PL/SQL Developer,可以從這裡下載到

是一個簡單、方便操作的GUI去查詢SQL,比起直接使用sqlplus良善許多

  1. Reference

    1. http://dbaora.com/install-oracle-11g-release-2-11-2-on-centos-linux-7/
    2. https://www.unixmen.com/how-to-install-oralce-11gr2-database-server-on-centos-6-3/
    3. http://www.linuxidc.com/Linux/2016-04/130559.htm
    4. http://superuser.com/questions/576006/linker-error-while-installing-oracle-11g-on-fedora-18
    5. https://dotblogs.com.tw/jamesfu/2016/02/02/oracle12c_install
    6. https://wiki.centos.org/zh-tw/HowTos/Oracle12onCentos7
    7. http://stackoverflow.com/questions/8937933/installing-oracle-11g-r2-in-ubuntu-10-04 (Err: must be configured to display at least 256 colors)
    8. https://dotblogs.com.tw/jamesfu/2016/02/02/oracle12c_install
    9. http://www.cnblogs.com/interboy/archive/2008/07/24/1250077.html
    10. https://www.server-world.info/en/note?os=CentOS_7&p=oracle12c&f=6