在虛擬機RHEL 7.3安裝Oracle 11g
- . Linux.
- 設置爲靜態IP地址,並將DNS設置爲與主機一致,
- 修改主機名
[root@localhost ~]# hostname
localhost.localdomain ##Oracle數據庫的安裝在生產中要慎重考慮主機名,避免二次修改。
[root@localhost ~]# hostnamectl set-hostname ynosb
[root@localhost ~]# hostnamectl ##驗證是否成功
- 在/etc/hosts文件中設置主機域名解析
# vi /etc/hosts
192.168.59.144 dbserver
- 安裝相關包
- Oracle官方文檔中確定要安裝的包如下:
binutils-2.17.50.0.6
compat-libstdc++-33-3.2.3
compat-libstdc++-33-3.2.3 (32 bit)
elfutils-libelf-0.125
elfutils-libelf-devel-0.125
gcc-4.1.2
gcc-c++-4.1.2
glibc-2.5-24
glibc-2.5-24 (32 bit)
glibc-common-2.5
glibc-devel-2.5
glibc-devel-2.5 (32 bit)
glibc-headers-2.5
ksh-20060214
libaio-0.3.106
libaio-0.3.106 (32 bit)
libaio-devel-0.3.106
libaio-devel-0.3.106 (32 bit)
libgcc-4.1.2
libgcc-4.1.2 (32 bit)
libstdc++-4.1.2
libstdc++-4.1.2 (32 bit)
libstdc++-devel-4.1.2
make-3.81
numactl-devel-0.9.8.x86_64
sysstat-7.0.2
- 檢查上述系統中上述包的安裝情況
# rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel
# rpm -q glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make numactl-devel sysstat
- 安裝上述包中系統未安裝的包
從rhel-server-7.3-x86_64-dvd.iso的packages文件夾中拷貝下文件到虛擬機面機進行安裝。
順序很重要,如下:
#rpm -ivh glibc-2.17-157.el7.i686.rpm nss-softokn-freebl-3.16.2.3-14.4.el7.i686.rpm
#rpm -ivh glibc-devel-2.17-157.el7.i686.rpm
#rpm -ivh libgcc-4.8.5-11.el7.i686.rpm
#rpm -ivh compat-libstdc++-33-3.2.3-69.el6.i686.rpm
#rpm -ivh compat-libstdc++-33-3.2.3-69.el6.x86_64.rpm
#rpm -ivh pkgconfig-0.27.1-4.el7.x86_64.rpm
#rpm -ivh zlib-devel-1.2.7-17.el7.x86_64.rpm
#rpm -ivh elfutils-libelf-devel-0.166-2.el7.x86_64.rpm
#rpm -ivh ksh-20120801-26.el7.x86_64.rpm
#rpm -ivh libaio-0.3.109-13.el7.i686.rpm
#rpm -ivh libstdc++-4.8.5-11.el7.i686.rpm
#rpm -ivh numactl-devel-2.0.9-6.el7_2.x86_64.rpm
#rpm -ivh sysstat-10.1.5-11.el7.x86_64.rpm
#rpm -ivh libaio-devel-0.3.109-13.el7.x86_64.rpm
#rpm -ivh libaio-devel-0.3.109-13.el7.i686.rpm
- 創建Oracle組和用戶帳戶
# groupadd oinstall
# groupadd dba
# useradd -g oinstall -G dba oracle
# passwd oracle
- 配置內核參數
- 修改文件/etc/sysctl.conf,添加以下內容:
# /etc/sysctl.conf
# for oracle
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
# 官方文檔kernel.shmmax = 536870912,實際軟件中需要kernel.shmmax = 980742144
kernel.shmmax = 980742144
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
執行以下命令時參數生效:
# /sbin/sysctl -p
注: 內核參數設置可以在安裝Oracle時產生的腳本修復。
- 修改文件/etc/security/limits.conf,添加以下內容:
#vi /etc/security/limits.conf
# for oracle
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
- 修改/etc/pam.d/login,# vi /etc/pam.d/login,在文本末尾加上:
session required /lib64/security/pam_limits.so
session required pam_limits.so
(以上可批量執行)
- 編輯Oracle用戶環境,編輯.bash_profile文件
# su - oracle
$ vi .bash_profile
編輯.bash_profile文件,添加以下內容
export ORACLE_BASE=/home/oracle/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl #SID注意和自己即將建立的SID對應
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export ORACLE_UNQNAME=$ORACLE_SID
存盤。
$ source .bash_profile
關閉此終端。
- 解壓
將linux.x64_11gR2_database_1of2.zip和linux.x64_11gR2_database_2of2.zip粘貼到桌面,再移動到/home/oracle中,解壓的文件在/home/oracle/database目錄中。進入/home/oracle目錄,執行# unzip linux.x64_11gR2_database_1of2.zip和# unzip linux.x64_11gR2_database_2of2.zip,解壓的文件在/home/oracle/database目錄中。解壓完成後可刪除兩個zip文件。
- 重啓並以oracle用戶的身份登錄並開始安裝
進入/home/oracle/database目錄,執行$ ./runInstaller
,當檢查均通過,會出現oracle安裝界面。
安裝時有出現一個錯誤:
Error in invoking target 'agent nmhs' of makefile '/home/oracle/app/oracle/product/11.2.0/dbhome_1/sysman/lib/ins_emagent.mk'...
保留安裝過程,另外開啓一個終端窗口,將ins_emagent.mk文件中的$(MK_EMAGENT_NMECTL)更改爲$(MK_EMAGENT_NMECTL) -lnnz11,然後在安裝過程中點擊Retry即可。
[root@localhost oraInventory]# ./orainstRoot.sh
Changing permissions of /home/oracle/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /home/oracle/oraInventory to oinstall.
The execution of the script is complete.
[root@localhost dbhome_1]# ./root.sh
Running Oracle 11g root.sh script...
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /home/oracle/app/oracle/product/11.2.0/dbhome_1
Enter the full pathname of the local bin directory: [/usr/local/bin]:
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.sh script.
Now product-specific root actions will be performed.
Finished product-specific root actions.
以下參照https://www.cnblogs.com/zzuyczhang/p/5681299.html
- 檢查
- 檢查監聽狀態 [oracle@ynosb ~]$ lsnrctl status
- 如未啓動,則顯示:
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-DEC-2018 14:12:20
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbserver)(PORT=152
- 如已啓動,則顯示:
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-DEC-2018 14:16:12
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbserver)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 05-DEC-2018 14:15:57
Uptime 0 days 0 hr. 0 min. 15 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /home/oracle/app/diag/tnslsnr/ynosb/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ynosb)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
- 停止監聽
[oracle@ynosb ~]$ lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-DEC-2018 14:18:58
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbserver)(PORT=1521)))
The command completed successfully
- 啓動監聽
[oracle@ynosb ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-DEC-2018 14:20:16
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Starting /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /home/oracle/app/diag/tnslsnr/ynosb/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ynosb)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbserver)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 05-DEC-2018 14:20:16
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /home/oracle/app/diag/tnslsnr/ynosb/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ynosb)(PORT=1521)))
The listener supports no services
The command completed successfully
- 測試oracle監聽:
- 本機上監聽
[oracle@ynosb ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 5 14:22:18 2018
Copyright (c) 1982, 2009, Oracle. All rights reserved..
SQL> quit
- 網絡監聽
在本機上執行了lsnrctl start且關閉本機防火牆時(用# systemctl stop firewalld),找一臺windows平臺電腦,telnet oracle主機IP地址:1521,通的話,會出現一個黑屏,光標一閃一閃。
- linux下創建oracle用戶表空間
就是在已有的數據庫實例上創建一個新的帳號,訪問一些新的表
操作步驟如下:
(1)登錄linux,以oracle用戶登錄(如果是root用戶登錄的,登錄後用 su - oracle命令切換成oracle用戶)
(2)以sysdba方式來打開sqlplus,命令如下: sqlplus "/as sysdba"
[oracle@ynosb ~]$ sqlplus " / as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 5 11:45:42 2018
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
(3)查看我們常規將用戶表空間放置位置:
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/app/oradata/orcl/system01.dbf
/home/oracle/app/oradata/orcl/sysaux01.dbf
/home/oracle/app/oradata/orcl/undotbs01.dbf
/home/oracle/app/oradata/orcl/users01.dbf
(4)創建用戶表空間:
SQL> CREATE TABLESPACE NOTIFYDB DATAFILE '/home/oracle/app/oradata/orcl/scsdb.dbf' SIZE 200M AUTOEXTEND ON EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
Tablespace created.
(5)創建用戶,指定密碼和上邊創建的用戶表空間
SQL> CREATE USER scs IDENTIFIED BY scs DEFAULT TABLESPACE NOTIFYDB;
User created.
(6)賦予權限
SQL> grant connect,resource to scs;
Grant succeeded.
SQL> grant unlimited tablespace to scs;
Grant succeeded.
SQL> grant create database link to scs;
Grant succeeded.
SQL> grant select any sequence,create materialized view to scs;
Grant succeeded.
--經過以上操作,我們就可以使用scs/scs登錄指定的實例,創建我們自己的表了