Linux环境搭建:CentOS7安装Oracle

CentOS7 安装Oracle 11.2.0

材料


[root@bogon yum.repos.d]# rpm -qi centos-release 
Name        : centos-release
Version     : 7
Release     : 2.1511.el7.centos.2.10
Architecture: x86_64
Install Date: Tue 27 Jun 2017 11:37:39 PM PDT
Group       : System Environment/Base
Size        : 36019
License     : GPLv2
Signature   : RSA/SHA256, Wed 09 Dec 2015 02:01:49 AM PST, Key ID 24c6a8a7f4a80eb5
Source RPM  : centos-release-7-2.1511.el7.centos.2.10.src.rpm
Build Date  : Wed 09 Dec 2015 01:59:15 AM PST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
Summary     : CentOS Linux release file
Description :
CentOS Linux release files

环境设置

修改操作系统核心参数

  • 修改用户的SHELL的限制,修改/etc/security/limits.conf文件追加以下内容,设置系统进程的最大数目、打开文件的最大数目 参考资料
[root@bogon oracle]# vim /etc/security/limits.conf
oracle   soft    nproc    2047
oracle   hard    nproc    16384
oracle   soft    nofile    10240
oracle   hard    nofile    65536
  1. 修改/etc/pam.d/login 文件 参考资料
[root@bogon oracle]# vim /etc/pam.d/login
# oracle 安装使用到
session   required    /lib/security/pam_limits.so
session   required    pam_limits.so
  1. 修改linux内核,修改/etc/sysctl.conf文件
[root@bogon oracle]# vim /etc/sysctl.conf
# oracle 安装追加
fs.file-max = 6815744 
fs.aio-max-nr = 1048576 
kernel.shmall = 2097152 
kernel.shmmax = 2147483648 
kernel.shmmni = 4096 
kernel.sem = 250 32000 100 128 
net.ipv4.ip_local_port_range = 9000 65500 
net.core.rmem_default = 4194304 
net.core.rmem_max = 4194304 
net.core.wmem_default = 262144 
net.core.wmem_max = 1048576
  1. 要使 /etc/sysctl.conf 更改立即生效
[root@bogon oracle]# sysctl -p
fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
  1. 编辑 /etc/profile
[root@bogon oracle]# vim /etc/profile
#Oracle环境变量
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then 
  ulimit -p 16384
  ulimit -n 65536
else
  ulimit -u 16384 -n 65536
fi

fi

Oracle用户操作

  1. 新增oracle用户和组
[root@bogon ~]# groupadd  oinstall 
[root@bogon ~]# groupadd  dba
[root@bogon ~]# useradd -g oinstall -G dba -m oracle
[root@bogon ~]# passwd  oracle
Changing password for user oracle.
New password: 'orcl'
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:'orcl'
passwd: all authentication tokens updated successfully.
  1. 创建数据库软件目录和数据文件存放目录,目录的位置,根据自己的情况来定,注意磁盘空间即可
[root@bogon ~]# mkdir /home/oracle/app
[root@bogon ~]# mkdir /home/oracle/app/oracle
[root@bogon ~]# mkdir /home/oracle/app/oradata
[root@bogon ~]# mkdir /home/oracle/app/oracle/product
  1. 更改目录属主为Oracle用户所有
[root@bogon app]# chown -R oracle:oinstall /home/oracle/app

[root@bogon home]# ll
total 8
drwx------.  4 oracle   dba        84 Jun 28 04:46 oracle
drwx------.  9 weblogic weblogic 4096 Jun 28 04:10 weblogic
drwx------. 16 zhuoqi   zhuoqi   4096 Jun 28 04:42 zhuoqi

[root@bogon oracle]# ll
total 0
drwxr-xr-x. 4 oracle oinstall 33 Jun 28 04:46 app
  1. 配置oracle用户的环境变量 .bash_profile 追加一下内容
[oracle@bogon ~]$ vim .bash_profile 
umask 022
export ORACLE_BASE=/home/oracle/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
  1. 重启计算机

安装oracle

  1. 从其他目录转移Weblogic的安装包,重新赋值权限
[root@bogon oracle]# chown oracle:oinstall linux.x64_11gR2_database_* 
[root@bogon oracle]# ll
total 2295592
drwxr-xr-x. 4 oracle oinstall         33 Jun 28 04:46 app
-rw-rw-r--. 1 oracle oinstall 1239269270 Jun 28 05:27 linux.x64_11gR2_database_1of2.zip
-rw-rw-r--. 1 oracle oinstall 1111416131 Jun 28 05:26 linux.x64_11gR2_database_2of2.zip
  1. 解压
[oracle@bogon ~]$ unzip linux.x64_11gR1_database_2of2.zip 
[oracle@bogon ~]$ unzip linux.x64_11gR2_database_2of2.zip 
[oracle@bogon database]$ ll
total 24
drwxr-xr-x. 12 oracle dba 4096 Aug 16  2009 doc
drwxr-xr-x.  4 oracle dba 4096 Aug 15  2009 install
drwxrwxr-x.  2 oracle dba   58 Aug 15  2009 response
drwxr-xr-x.  2 oracle dba   33 Aug 15  2009 rpm
-rwxr-xr-x.  1 oracle dba 3226 Aug 15  2009 runInstaller
drwxrwxr-x.  2 oracle dba   28 Aug 15  2009 sshsetup
drwxr-xr-x. 14 oracle dba 4096 Aug 15  2009 stage
-rw-r--r--.  1 oracle dba 5402 Aug 17  2009 welcome.html
  1. 运行./runInstaller
[oracle@bogon database]$ ./runInstaller 

只记录一些注意点,

  1. 分组有问题,导致(OSOPER Group)不能选择oinstall(只有dba可以选择)组,做了以下调整
[oracle@bogon oradata]$ id oracle
uid=1002(oracle) gid=1003(dba) groups=1003(dba)
[root@bogon ~]# usermod -g oinstall -G dba oracle

[root@bogon ~]# id oracle
uid=1002(oracle) gid=1002(oinstall) groups=1002(oinstall),1003(dba)

  1. 安装oracle需要的支持包,oracle提供了一个简化的rpm
    部分rpm可以忽略 参考:https://dba.stackexchange.com/questions/58835/oracle-installation-requires-old-rpm-versions-what-to-do
在线安装
[root@bogon ~]# yum -y  install glibc.i686
离线安装
 INFO: Error Message:PRVF-7532 : Package "libaio-0.3.105 (i386)" is missing on node "<node_name>"
INFO: Error Message:PRVF-7532 : Package "compat-libstdc++-33-3.2.3 (i386)" is missing on node "<node_name>"
INFO: Error Message:PRVF-7532 : Package "libaio-devel-0.3.105 (i386)" is missing on node "<node_name>"
INFO: Error Message:PRVF-7532 : Package "libgcc-3.4.6 (i386)" is missing on node "<node_name>"
INFO: Error Message:PRVF-7532 : Package "libstdc++-3.4.6 (i386)" is missing on node "<node_name>"
INFO: Error Message:PRVF-7532 : Package "unixODBC-2.2.11 (i386)" is missing on node "<node_name>"
INFO: Error Message:PRVF-7532 : Package "unixODBC-devel-2.2.11 (i386)" is missing on node "<node_name>"
INFO: Error Message:PRVF-7532 : Package "pdksh-5.2.14" is missing on node "<node_name>"
  1. 如何简化 Oracle Linux 6 上的 Oracle Database 11g 安装
    需要GPG签字支持 :http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol7 存放路径/etc/pki/rpm-gpg/名称为RPM-GPG-KEY-oracle
[root@bogon rpm-gpg]# yum install oracle-rdbms-server-11gR2-preinstall `运行时报错`
GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle"
  1. 冲突的ksh,但是卸载时没有找到,升级了pdksh的包
[root@bogon rpm]# rpm -i pdksh-5.2.14-30-mdv2011.0.x86_64.rpm 
warning: pdksh-5.2.14-30-mdv2011.0.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 70771ff3: NOKEY
    file /usr/bin/ksh conflicts between attempted installs of pdksh-5.2.14-30.x86_64 and pdksh-5.2.14-30.x86_64
[root@bogon rpm]# rpm -e ksh*
error: package ksh* is not installed


[root@bogon rpm]# rpm -i pdksh-5.2.14-37.el5_8.1.i386.rpm 
warning: pdksh-5.2.14-37.el5_8.1.i386.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
  1. 安装完成后,系统会提示你需要用root权限执行2个shell脚本。按照其提示的路径,找到其所在的位置,
    如: /home/oracle/app/oracle/product/11.2.0/dbhome_1/root.sh/home/oracle/oraInventory/orainstRoot.sh
[root@bogon dbhome_1]# pwd
/home/oracle/app/oracle/product/11.2.0/dbhome_1
[root@bogon dbhome_1]# sh 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.

[root@bogon oraInventory]# pwd
/home/oracle/oraInventory
[root@bogon oraInventory]# sh 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.

数据库建库

oracle用户下执行dbca
实例的配置信息(用于问题排查):/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/spfiletest.ora

创建实例

不指定快速恢复和归档

去掉不常用的模块

内存分配及指定字符集

检测安装情况

  1. 测试连接,不能执行SQL;因为.bash_profile配置的SID跟创建时使用的test不一致,需要调整.bash_profile
oracle@bogon database]$  sqlplus "/ as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 29 03:51:44 2017

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

Connected to an idle instance.

SQL> select * from usesr_tables;
select * from usesr_tables
*
ERROR at line 1:
ORA-01034: ORACLE not available`执行报错,找不到有效的Oracle`
Process ID: 0
Session ID: 0 Serial number: 0
  1. 修改SID的值跟创建oracle库使用匹配 (思考,如何启用2个oracle实例,.bash_profile只能配置一个sid)
[oracle@bogon ~]$ vim .bash_profile 
export ORACLE_SID=test
  • .bash_profile修改后生效的三种命令

    ..bash_profile
    source .bash_profile
    exec bash --login

配置监听

oracle用户下执行dbca
采用主机名称

外部网络连接,需要开通防火墙,并重启防火墙

[root@bogon oraInventory]# firewall-cmd --permanent --zone=public --add-port=1521/tcp
[root@bogon oraInventory]# firewall-cmd --permanent --zone=public --add-port=1521/udp
[root@bogon oraInventory]# systemctl restart firewalld.service

Linux下Oracle常用管理命令

参考

打开图形化窗口:
$ dbca (Database Configuration Assistant windows  添加数据库实例)
$ netmgr
$ netca  (配置监听Oracle Net Configuration Assistant windows )

常用命令:
$ lsnrctl start|stop|status                  (启动|停止|活动状态 监听)
$ isqlplusctl start|stop                      (启动|停止 isqlplus 可以在浏览器登录 5560端口)
$ sqlplus /nolog                              (以不连接数据库的方式启动sqlplus)
$ sqlplus system/manager @ file.sql           (执行sql脚本文件)
$ sqlplus system/manager                      (使用system用户登录sqlplus)
$ imp system/manager file=/tmp/expfile.dmp log=/tmp/implogfile.log ignore=y fromuser=expuser touser=impuser  (用户模式表数据导入,如果没有特别指定值,就使用默认的值)     
$ exp username/password file=/tmp/expfile.dmp log=/tmp/proV114_exp.log                                       (用户模式表数据导出,这是最简单的导出方法)

SQL> conn / as sysdba                                  (以sysdba用户连接)
SQL> startup
SQL> shutdown
SQL> shutdown immediate                                (立即关闭实例)
SQL> desc dba_users;                                   (查询dba_users表结构)
SQL> select username from dba_users;                   (查询当前sid下的所有用户的username)
SQL> select count(*) from username.tablename;          (查询tablename表的行数)
SQL> drop user username cascade;                       (删除名称为username的oracle用户)
SQL> select distinct table_name from user_tab_columns; (查看当前user模式下所有表名)

Linux下同时启动2个Oracle实例

在重启操作系统之后,Oracle默认是没有启动的。使用如下命令查看Oracle相关服务是否已启动:

“`
ps aux | grep ora_ #若无ora_**_**相关的进程,则oracle数据库实例未启动
netstat -tlnup | grep 1521 #若无任何显示,则监听器未启动
lsnrctl status #查看监听器状态
netstat -tlnup | grep 1158 #若无任何显示,则EM未启动
emctl status dbconsole #查看EM状态

“`

1.切换Oracle用户:

2.切换到Oracle目录下:

3.执行配置文件 .bash_profile

[oracle@db ~]$ ..bash_profile

4.查看参数是否已经配置成功

echo $oracle_home

echo $oracle_sid

5.启动数据库实例

#sqlplus  /nolog

#conn /as sysdba

#startup

#exit

6.启动监听程序

 lsnrctl start

7.启动另外一个数据库,先修改参数


export ORACLE_SID=devdb

然后重复步骤4-6

“`

[oracle@bogon admin]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Sat Jul 1 13:26:23 2017

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

SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@bogon admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 01-JUL-2017 13:27:13

Copyright (c) 1991, 2009, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bogon)(PORT=1521)))
STATUS of the LISTENER


Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 01-JUL-2017 13:23:17
Uptime 0 days 0 hr. 3 min. 56 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/bogon/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bogon)(PORT=1521)))
Services Summary…
Service “test” has 1 instance(s).
Instance “test”, status READY, has 1 handler(s) for this service…
Service “test1” has 1 instance(s).
Instance “test1”, status READY, has 1 handler(s) for this service…
Service “test1XDB” has 1 instance(s).
Instance “test1”, status READY, has 1 handler(s) for this service…
Service “testXDB” has 1 instance(s).
Instance “test”, status READY, has 1 handler(s) for this service…
The command completed successfully

“`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值