Linux與雲計算——第二階段Linux服務器架設
第一十二章:數據庫搭建—Oracle Database 12c
3.1 預需求
安裝 Oracle Database 12c.
在安裝之前,更改一些安裝Oracle數據時的要求設置
[1] 安裝 Desktop Environment, refer to here.
[2] 安裝required.
[root@server ~]# yum -y install binutils compat-libcap1 gcc gcc-c++ glibc glibc.i686 glibc-devel glibc.i686 ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++l7.i686 libstdc++-devel libstdc++-devel.i686 compat-libstdc++-33 compat-libstdc++-33.i686 libXi libXi.i686 libXtst libXtst.i686 make sysstat
[3] 編輯內核參數.
[root@server ~]# MEMTOTAL=$(free -b | sed -n '2p' | awk '{print $2}')
[root@server ~]# SHMMAX=$(expr $MEMTOTAL / 2)
[root@server ~]# SHMMNI=4096
[root@server ~]# PAGESIZE=$(getconf PAGE_SIZE)
[root@server ~]# cat >> /etc/sysctl.conf << EOF
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmmax = $SHMMAX
kernel.shmall = `expr \( $SHMMAX / $PAGESIZE \) \* \( $SHMMNI / 16 \)`
kernel.shmmni = $SHMMNI
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 = 1048576
EOF
[root@server ~]# sysctl -p
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmmax = 6274715648
kernel.shmall = 392169728
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 = 1048576
[4] 爲數據庫創建用戶和組
[root@server ~]# i=54321; for group in oinstall dba backupdba oper dgdba kmdba; do
groupadd -g $i $group; i=`expr $i + 1`
done
[root@server ~]# useradd -u 1200 -g oinstall -G dba,oper,backupdba,dgdba,kmdba -d /home/oracle oracle
[root@server ~]# passwd oracle
Changing password for user oracle.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@server ~]# mkdir -p /u01/app/oracle
[root@server ~]# chown -R oracle:oinstall /u01/app
[root@server ~]# chmod -R 775 /u01
[root@server ~]# vi /etc/pam.d/login
# near line 14: add
session required pam_selinux.so open
session required pam_namespace.so
session required pam_limits.so
session optional pam_keyinit.so force revoke
session include system-auth
-session optional pam_ck_connector.so
[root@server ~]# vi /etc/security/limits.conf
# 結尾處加入:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
[5] 用oracle用戶登錄,設置環境變量
dlp login: oracle
Password:
[oracle@server ~]$ vi ~/.bash_profile
#結尾處添加:
umask 022
export ORACLE_BASE=/u01/app/oracle
# 爲安裝創建一個臨時目錄
[oracle@server ~]$ mkdir tmp
3.2 安裝Oracle 12c
[1] 用之前在設置中創建的用戶登錄來管理數據庫。
[2]在linux操作系統上傳和下載Oracle Databse 12c
http://www.oracle.com/technology/software/products/database/index.html
[3] Oracle文件上傳後,將其移到tmp目錄並運行如下的安裝程序。
[oracle@server ~]$ cd tmp
[oracle@server tmp]$ unzip linuxamd64_12102_database_1of2.zip
[oracle@server tmp]$ unzip linuxamd64_12102_database_2of2.zip
[oracle@server tmp]$ ./database/runInstaller
[4] 安裝程序啓動如下。首先,從Oracle安全問題接收一些信息設置您的電子郵件地址和密碼等。
[5]在這個界面, 選擇 "Install database software only".
[6]選擇"Single Instance Database ***".
[7]選擇語言.
[8] 選擇你要安裝的版本
[9] 爲“甲骨文”指定基本目錄和文件。在這個例子中,默認情況下,繼續進行下一個。
[10] 指定已經安裝的目錄,默認繼續.
[11]指定特權組,默認繼續.
[12] 檢查前的要求。如果有些設置沒有按照建議配置,就會出來相關的通知,請再次確認它們。
[13] 配置文件的總結。選擇安裝,就OK了.
[14]開始安裝
[15] 下面的界面出現之後,找到一個終端開始用root用戶執行下面的操作.
[root@server ~]# /u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.
[root@server ~]#
[root@server ~]# /u01/app/oracle/product/12.1.0/dbhome_1/root.sh
Performing root user operation.
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/12.1.0/dbhome_1
Enter the full pathname of the local bin directory: [/usr/local/bin]: # Enter
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...
Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
[16] 安裝完成,點擊關閉。
[17] 爲oracle用戶設置環境變量
[oracle@server ~]$ vi ~/.bash_profile
# 結尾處添加
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
[oracle@server ~]$ source ~/.bash_profile
[oracle@server ~]$ rm -rf tmp
3.3 增加Oracle Net Listener
在oracle網絡上創建oracle監聽
[1]登錄oracle界面,輸入netca命令
[2]檢查 "Listener Configuration"
[3]一直next下去.
[4] 輸入監聽名字,任意選擇一個。
[5] 默認"TCP".
[6] Set a port. This example goes next
[7] If you'd like to create more with keeping default. Listeners, Answer "Yes". This example selects "No".
[8]配置完成.
[9] 在創建監聽器,tnslsnr偵聽端口配置如下。
[oracle@server~]$ ss -napt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
ESTAB 0 52 10.0.0.30:22 10.0.0.5:50113
LISTEN 0 128 :::1521 :::* users:(("tnslsnr",3988,9))
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
[oracle@server ~]$ tnsping localhost
TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 04-JUL-2015 01:03:07
Copyright (c) 1997, 2014, Oracle. All rights reserved.
Used parameter files:
Used HOSTNAME adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)
(PORT=1521)))
OK (0 msec)
3.4 創建數據庫
[1] 登錄數據庫,並且輸入以下的命令。
[2] Select "Create Database" and go next.
[3] On this example, select "Advanced Mode" and go next.
[4] This example selects "General
[5] Set Grobal Database name and SID Purpose ***" and go next. like follows. Input any one you like.
[6] This example goes next with keeping
[7] Set passwords. Please set a default.password for a user for security.
[8]配置監聽.
[9]配置內存設置.
[10] 配置簡單的示例和腳本
[11]配置 memory
[12] 指定最大進程
[13] 字符設置
[14] 選擇連接模式。如果您的服務器沒有多客戶端,請選擇“專用服務器模式”。如果您的服務器有許多客戶端,請選擇“共享服務器”
[15]繼續
[16]配置完成,選擇“finish”
[17] 數據庫開始創建.
[18] 點擊關閉。
[19] 添加SID到數據庫
[oracle@dserver~]$ vi /etc/oratab
#更改如下
dlp:/u01/app/oracle/product/12.1.0/dbhome_1:Y
[oracle@server ~]$ vi ~/.bash_profile
# 結尾添加
export ORACLE_SID=dlp
3.5 使用企業管理器
使用企業管理器,它有可能在圖像化界面管理數據庫
[1]創建完成數據庫之後,數據庫服務是運行狀態也有可能訪問企業管理器。訪問數據庫創建完成時所顯示的網址,然後顯示登錄表單,並有可能與數據庫用戶登錄。
[2]登錄成功後,就可以開始管理了
3.6 創建Systemd file
爲數據庫服務創建系統目錄。
[1] Login as root user and create Systemd files.
[root@server ~]# vi /etc/sysconfig/dlp.oracledb
# 創建新的:定義環境變量
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
ORACLE_SID=dlp
#配置監聽服務
[root@server ~]# vi /usr/lib/systemd/system/[email protected]
# this is an example, modify for free
[Unit]
Description=oracle net listener
After=network.target
[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/dlp.oracledb
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
# configure database service
[root@server ~]# vi /usr/lib/systemd/system/[email protected]
# this is an example, modify for free
[Unit]
Description=oracle net listener
After=network.target lsnrctl.service
[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/dlp.oracledb
ExecStart=/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart /u01/app/oracle/product/12.1.0/dbhome_1
ExecStop=/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbshut /u01/app/oracle/product/12.1.0/dbhome_1
User=oracle
[Install]
WantedBy=multi-user.target
[root@server ~]# systemctl daemon-reload
[root@server ~]# systemctl enable dlp@lsnrctl dlp@oracledb