在虚拟机RHEL 7.3安装Oracle 11g
在虚拟机RHEL 7.3安装Oracle 11g
- . Linux.
- 设置为静态IP地址,并将DNS设置为与主机一致,
- 修改主机名
[[email protected] ~]# hostname
localhost.localdomain ##Oracle数据库的安装在生产中要慎重考虑主机名,避免二次修改。
[[email protected] ~]# hostnamectl set-hostname ynosb
[[email protected] ~]# 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即可。
[[email protected] 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.
[[email protected] 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
- 检查
- 检查监听状态 [[email protected] ~]$ 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
- 停止监听
[[email protected] ~]$ 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
- 启动监听
[[email protected] ~]$ 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监听:
- 本机上监听
[[email protected] ~]$ 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"
[[email protected] ~]$ 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登录指定的实例,创建我们自己的表了