Linux與雲計算——第二階段Linux服務器架設 第一十二章:數據庫搭建—Oracle Database 12c

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] 用之前在設置中創建的用戶登錄來管理數據庫。

wKiom1eugVGjYkm_AAKvMxgmDCc439.png-wh_50[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安全問題接收一些信息設置您的電子郵件地址和密碼等。

 wKioL1eugcDi_YgsAADGVvCs118396.png-wh_50

 [5]在這個界面, 選擇 "Install database software only". 

wKioL1eugczxs-kBAACyZ4IAXoE166.png-wh_50

[6]選擇"Single Instance Database ***".

 wKiom1eugeOQDw_AAAC1droA0vc787.png-wh_50

[7]選擇語言.

wKioL1eugiTBAtrGAADpjhQNpf4226.png-wh_50

 [8] 選擇你要安裝的版本

wKiom1eugjuzmqtpAAD2EAWeVCk603.png-wh_50

 [9] 爲“甲骨文”指定基本目錄和文件。在這個例子中,默認情況下,繼續進行下一個。

 wKioL1eugk_SmWNYAADiHRHltKI970.png-wh_50

[10] 指定已經安裝的目錄,默認繼續.

 wKiom1eugoaSy08zAADf8QkNMpU916.png-wh_50

 [11]指定特權組,默認繼續.

wKioL1eugpjSUDGYAAELk78O0rM466.png-wh_50

[12] 檢查前的要求。如果有些設置沒有按照建議配置,就會出來相關的通知,請再次確認它們。

wKioL1eugvyjsIs6AAD8COHVK38095.png-wh_50

[13] 配置文件的總結。選擇安裝,就OK了.

wKiom1eugxHSU6dDAAD4PgBiD_E856.png-wh_50

[14]開始安裝

wKiom1eugyTTeZHsAAE5_-vlhkU517.png-wh_50

[15]  下面的界面出現之後,找到一個終端開始用root用戶執行下面的操作.

 wKioL1eugzayanMmAABdDkdt9GA968.png-wh_50

[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] 安裝完成,點擊關閉。

 wKiom1eug0uxmnqWAACfAL5TnLI435.png-wh_50

[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命令

wKiom1euhK_haroVAAGeLB6InLo678.png-wh_50

[2]檢查 "Listener Configuration"  

wKioL1euhL2z2eF6AAEgcpVJLW0067.png-wh_50

[3]一直next下去.

wKioL1euhMrhyheXAAEC1PxzQDo874.png-wh_50

[4] 輸入監聽名字,任意選擇一個。    

wKiom1euhNfB1Pn0AADzfRno-SM163.png-wh_50    

[5] 默認"TCP".   

wKiom1euhOXAikobAADfUEDwJ9Q436.png-wh_50                                  

[6] Set a port. This example goes next   

wKioL1euhPOz3Q8CAADsbAPDzyU944.png-wh_50

 [7] If you'd like to create more with keeping default.  Listeners, Answer "Yes". This example selects "No".

wKioL1euhQKjt9BlAAD7rgTS36Y114.png-wh_50

[8]配置完成. 

wKiom1euhRKi16brAADlgdGvTEU908.png-wh_50

[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] 登錄數據庫,並且輸入以下的命令。

wKioL1euhcST_XsrAAEX20xISsw405.png-wh_50

 [2] Select "Create Database" and go next.

wKiom1euhdLQWaDoAACmxUieBxo913.png-wh_50

[3] On this example, select "Advanced Mode" and go next.

wKiom1euhd6RmuKrAADs-ssq0L8374.png-wh_50

[4] This example selects "General   

wKioL1euheyRjDoiAADp5M3WqC8967.png-wh_50      

[5] Set Grobal Database name and SID Purpose ***" and go next.  like follows. Input any one you like.

wKiom1euhfzDhVUoAAEAArXe4h0958.png-wh_50

[6] This example goes next with keeping  

wKioL1euhgig6URcAADWA7trvEM109.png-wh_50 

[7] Set passwords. Please set a default.password for a user for security. 

wKiom1euhhfCIZCRAADZ1FuOV1k889.png-wh_50

[8]配置監聽. 

wKioL1euhiSDMEkGAADkCjlaqZM438.png-wh_50

[9]配置內存設置.

wKiom1euhjqROZqmAAEcmmMt3ks006.png-wh_50

[10] 配置簡單的示例和腳本     

wKiom1euhkqzRMFvAAD_3_BsAhc244.png-wh_50        

[11]配置 memory

wKioL1euhliyPvlhAAEKVWFtLds112.png-wh_50

[12] 指定最大進程                     

wKiom1euhmzBPLusAADr8QIoXV8202.png-wh_50

[13] 字符設置

wKiom1euhoqzrC2uAAEX11PLqq0911.png-wh_50

[14] 選擇連接模式。如果您的服務器沒有多客戶端,請選擇“專用服務器模式”。如果您的服務器有許多客戶端,請選擇“共享服務器”

wKioL1euhpezPUsyAAEUjw0qQJU667.png-wh_50

[15]繼續

wKioL1euhqPSY5THAADh1ctXl3E584.png-wh_50

[16]配置完成,選擇“finish”

wKiom1euhrCg36D-AAFEkKjXS4o233.png-wh_50

[17] 數據庫開始創建. 

wKiom1euhrzyu7khAADT1JCKcys783.png-wh_50

 [18] 點擊關閉。

wKioL1euhsfgViW4AAEOOqK8lF8358.png-wh_50

[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]創建完成數據庫之後,數據庫服務是運行狀態也有可能訪問企業管理器。訪問數據庫創建完成時所顯示的網址,然後顯示登錄表單,並有可能與數據庫用戶登錄。

wKioL1euhwLCNDxrAAEkq11HsOM018.png-wh_50

[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

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章