1安装环境
本文在虚拟机CentOS系统上安装oracle数据库,具体版本信息如下
软件 |
版本 |
文件名 |
备注 |
Vmware workstation |
12.0.0 |
VMware-workstation-full-12.0.0-2985596.exe |
|
CentOS |
7.2 |
CentOS-7.2-x86_64-DVD-1511.iso |
|
Oracle database |
11.2.0.4 |
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip |
Linux 版本 |
2系统配置
2.1创建oracle用户和组
2.1.1创建用户和组
[root@centos-y ~]# groupaddoinstall #创建用户组oinstall
[root@centos-y ~]# groupadd dba #创建用户组dba
[root@centos-y ~]# useradd -goinstall -G dba -m oracle #创建oracle用户,并加入到oinstall和dba用户组(-g主组-G副组)
一般还应该创建oper用户组,并将oracle用户添加进来(如下操作),这里省去。
groupadd dba
useradd -g oinstall -G dba,oper -m oracle
2.1.2查询用户组是否授权成功
[root@centos-y ~]# groupsoracle
oracle : oinstall dba
[root@centos-y ~]# id oracle
uid=1003(oracle) gid=1003(oinstall)groups=1003(oinstall),1004(dba)
2.1.3设置用户oracle的登陆密码
不设置密码,在CentOS的图形界面没法登陆
[root@centos-y ~]# passwdoracle
Changing password for useroracle.
New password:
BAD PASSWORD: The password isshorter than 8 characters
Retype new password:
passwd: all authenticationtokens updated successfully.
查看新建的oracle用户
[root@centos-y ~]# id oracle
uid=1003(oracle) gid=1004(dba)groups=1004(dba)
2.2创建数据库安装目录
2.2.1创建安装目录
在根目录创建oracle数据库安装目录,为后续安装做准备
[root@centos-y ~]# cd / #进入根目录
[root@centos-y /]# mkdir -p/u01/app/oracle #oracle数据库安装目录
[root@centos-y /]# mkdir -p/u01/app/oraInventory #oracle数据库配置文件目录
[root@centos-y /]# mkdir -p/u01/app/database #oracle数据库软件包解压目录
2.2.2设置目录权限
[root@centos-y /]# chown -Roracle:oinstall /u01/
[root@centos-y /]# ll /u01/ #查看权限
total 0
drwxr-xr-x. 5 oracle oinstall53 Oct 17 16:51 app
2.2.3上传安装文件并解压
可通过WinSCP等工具将数据库安装文件上传到Linux系统。
将安装文件夹解压到之前创建的目录。
unziplinux.x64_11gR2_database_1of2.zip -d /u01/app/database/ #解压文件1
unzip linux.x64_11gR2_database_2of2.zip-d /u01/app/database/ #解压文件2
2.3修改OS系统标识
oracle默认不支持CentOS系统安装,修改文件/etc/RedHat-release 内容为RedHat-7
[root@centos-y /]# vi/etc/redhat-release
entOS Linux release 7.2.1511(Core)
查看修改结果
[root@centos-y /]# cat /etc/redhat-release
redhat-7
2.4安装依赖包
CentOS7安装oracle数据库需要以下依赖包:
binutils-2.23.52.0.1-12.el7.x86_64
compat-libcap1-1.10-3.el7.x86_64
gcc-4.8.2-3.el7.x86_64
gcc-c++-4.8.2-3.el7.x86_64
glibc-2.17-36.el7.i686
glibc-2.17-36.el7.x86_64
glibc-devel-2.17-36.el7.i686
glibc-devel-2.17-36.el7.x86_64
ksh
libaio-0.3.109-9.el7.i686
libaio-0.3.109-9.el7.x86_64
libaio-devel-0.3.109-9.el7.i686
libaio-devel-0.3.109-9.el7.x86_64
libgcc-4.8.2-3.el7.i686
libgcc-4.8.2-3.el7.x86_64
libstdc++-4.8.2-3.el7.i686
libstdc++-4.8.2-3.el7.x86_64
libstdc++-devel-4.8.2-3.el7.i686
libstdc++-devel-4.8.2-3.el7.x86_64
libXi-1.7.2-1.el7.i686
libXi-1.7.2-1.el7.x86_64
libXtst-1.2.2-1.el7.i686
libXtst-1.2.2-1.el7.x86_64
make-3.82-19.el7.x86_64
sysstat-10.1.5-1.el7.x86_64
这里可以查看官网上的详细说明:
https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#BABCFJFG
联网状态下,可使用以下命令统一安装:
yum install binutils-*.x86_64compat-libcap1-*.x86_64 gcc-*.x86_64 gcc-c++-*.x86_64 glibc-*.i686glibc-*.x86_64 glibc-devel-*.i686 glibc-devel-*.x86_64 ksh-* libaio-*.i686libaio-*.x86_64 libaio-devel-*.i686 libaio-devel-*.x86_64 libgcc-*.i686libgcc-*.x86_64 libstdc++-*.i686 libstdc++-*.x86_64 libstdc++-devel-*.i686libstdc++-devel-*.x86_64 libXi-*.i686 libXi-*.x86_64 libXtst-*.i686 libXtst-*.x86_64make-*.x86_64 sysstat-*.x86_64
2.5防火墙和SELINUX设置
2.5.1查看防火墙状态
[root@centos-y ~]# systemctlstatus firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded(/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active(running) since Wed 2017-10-18 09:03:53 CST; 54min ago#运行中
Main PID: 802 (firewalld)
CGroup: /system.slice/firewalld.service
└─802 /usr/bin/python -Es/usr/sbin/firewalld --nofork --nopid
Oct 18 09:03:42 centos-ysystemd[1]: Starting firewalld - dynamic firewall .....
Oct 18 09:03:53 centos-ysystemd[1]: Started firewalld - dynamic firewall d...n.
Hint: Some lines wereellipsized,use -l to show in full.
2.5.2临时关闭防火墙
这样只能暂时关闭防火墙,重启后失效。
[root@centos-y ~]# systemctlstop firewalld.service
查看防火墙状态。
[root@centos-y ~]# systemctlstatus firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded(/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Wed 2017-10-1809:58:49 CST; 6s ago#已关闭
Process: 802 ExecStart=/usr/sbin/firewalld--nofork --nopid $FIREWALLD_ARGS (code=exited,status=0/SUCCESS)
Main PID: 802 (code=exited,status=0/SUCCESS)
Oct 18 09:03:42 centos-ysystemd[1]: Starting firewalld - dynamic firewall .....
Oct 18 09:03:53 centos-ysystemd[1]: Started firewalld - dynamic firewall d...n.
Oct 18 09:58:49 centos-ysystemd[1]: Stopping firewalld - dynamic firewall .....
Oct 18 09:58:49 centos-ysystemd[1]: Stopped firewalld - dynamic firewall d...n.
Hint: Some lines wereellipsized,use -l to show in full.
2.5.3禁止使用防火墙
永久关闭防火墙,重启后仍然生效。
[root@centos-y ~]# systemctldisable firewalld.service
Removed symlink/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink/etc/systemd/system/basic.target.wants/firewalld.service.
2.5.4关闭selinux
修改“/etc/selinux/config“,将SELINUX的值“enforcing“修改为”disabled“。需重启才能生效。
[root@centos-y ~]# vi/etc/selinux/config
# This file controls the stateof SELinux on the system.
# SELINUX= can take one ofthese three values:
# enforcing - SELinux security policy isenforced.
# permissive - SELinux prints warningsinstead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one ofthree two values:
# targeted - Targeted processes areprotected,
# minimum - Modification of targeted policy.Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
2.6修改内核参数
打开“/etc/sysctl.conf“,在文本最后添加配置参数
[root@localhost~]# vi /etc/sysctl.conf
net.ipv4.icmp_echo_ignore_broadcasts= 1
net.ipv4.conf.all.rp_filter = 1
fs.file-max = 6815744 #设置最大打开文件数
fs.aio-max-nr = 1048576
kernel.shmall = 2097152 #共享内存的总量,8G内存设置:2097152*4k/1024/1024
kernel.shmmax = 2147483648 #最大共享内存的段大小
kernel.shmmni = 4096 #整个系统共享内存段的最大数
kernel.sem = 250 32000 100 128 #信号量有关的参数
net.ipv4.ip_local_port_range =9000 65500 #可使用的IPv4端口范围
net.core.rmem_default = 262144
net.core.rmem_max= 4194304
net.core.wmem_default= 262144
net.core.wmem_max= 1048576
保存退出,执行“sysctl-p“加载系统参数使配置生效
[root@localhost~]# sysctl -p
net.ipv4.icmp_echo_ignore_broadcasts= 1
net.ipv4.conf.all.rp_filter = 1
sysctl: setting key"fs.file-max": Invalid argument
fs.file-max = 6815744
fs.aio-max-nr = 1048576
sysctl: setting key"kernel.shmall": Invalid argument
kernel.shmall = 2097152
sysctl: setting key"kernel.shmmax": Invalid argument
kernel.shmmax = 2147483648
sysctl: setting key"kernel.shmmni": Invalid argument
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
sysctl: setting key"net.ipv4.ip_local_port_range": Invalid argument
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
提示 sysctl: settingkey "……": Invalid argument,这里可以忽略,不影响后续安装。
2.7进程会话配置
在文件“/etc/security/limits.conf “中添加以下内容
[root@centos-y /]# vi /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
说明:“/etc/security/limits.conf ”是 Linux 资源使用配置文件,用来限制用户对系统资源的使用
2.8配置oracle用户环境变量
在文件“/home/oracle/.bash_profile”添加以下内容
[root@centos-y ~]# vi /home/oracle/.bash_profile
export ORACLE_BASE=/u01/app/oracle#oracle数据库安装目录
exportORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1#oracle数据库路径
export ORACLE_SID=orcl #oracle启动数据库实例名
export ORACLE_TERM=xterm #xterm窗口模式安装
exportPATH=$PATH:HOME/bin:$ORACLE_HOME/bin #添加系统环境变量
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib #添加系统环境变量
export LANG=C #防止安装过程出现乱码
exportNLS_LANG=AMERICAN_AMERICA.ZHS16GBK #设置Oracle客户端字符集,必须与Oracle安装时设置的字符集保持一致
注意,上述添加的内容中:ORACLE_SID=orcl ,orcl要与待创建的oracle实例名称一致。
配置完成,保存退出(:wq!)。运行以下命令,使配置生效
[root@centos-y ~]# source/home/oracle/.bash_profile
vim /etc/profile
if [ $USER = "oracle"]; then
if [ $SHELL = "/bin/ksh" ];then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
关于“/etc/profile”可参考以下文章:
《Linux/etc/profile文件详解》:http://www.linuxidc.com/Linux/2010-08/27742.htm
2.9其他配置
vim /etc/pam.d/login
session required/lib/security/pam_limits.so
session requiredpam_limits.so
IP和主机名:
[root@localhost db_1]# vi/etc/hosts
# Do not remove the followingline,or varIoUs programs
# that require networkfunctionality will fail.
127.0.0.1 localhost.localdomainlocalhost
192.168.1. 99 CentOS-y
3安装配置
3.1安装数据库软件
3.1.1设置图形界面
查看root用户下是否已设置DISPLAY变量
[oracle@centos-y database]$echo $DISPLAY
如果有值(比如“:0.0”)出现,则说明已设置DISPLAY变量;否则,执行以下命令
[oracle@centos-y database]$export DISPLAY=:0.0
测试图形界面是否能正常显示
[oracle@centos-y database]$xclock
显示时钟,则正常
3.1.2安装过程
[oracle@centos-y database]$ cd/u01/app/database/
2) 执行安装指令
尝试执行“./runInstaller “命令安装,但安装过程中出现图形界面显示异常,弹出窗口缩成一块,无法放大。故改为以下命令安装:
“./runInstaller -jreLoc/usr/lib/jvm/jre-1.8.0“
[oracle@centos-y database]$./runInstaller -jreLoc /usr/lib/jvm/jre-1.8.0
Starting Oracle UniversalInstaller...
Checking Temp space: must begreater than 120 MB. Actual 7696MB Passed
Checking swap space: must begreater than 150 MB. Actual 1739MB Passed
Checking monitor: must beconfigured to display at least 256 colors.Actual 16777216 Passed
Preparing to launch OracleUniversal Installer from /tmp/OraInstall2017-10-19_02-45-50PM. Please wait ...
3) 填写邮箱,跳过即可。
确认不提供邮箱
4) 下载更新,跳过。
5) 仅安装数据库软件
6) 安装单实例数据库
7) 选择语言
8) 选择版本
9) 选择安装位置
软件会自动读取之前创建的目录
10) 选择存放目录位置
11) 选择系统组
关于用户、群组及相关oracle inventory,可参考:
http://blog.csdn.net/yunzhiyu/article/details/50752989
12) 安装前检查
13) 开启安装
/u01/oraInventory/orainstRoot.sh
/u01/oracle/product/11.2.0/db_1/root.sh
14) 安装完成
3.2配置监听listener
[oracle@centos-y ~]$ netca
Oracle Net ServicesConfiguration:
Configuring Listener:LISTENER
Listener configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/u01/app/oracle/product/11.2.0/db_1/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Oracle Net Servicesconfiguration successful. The exit code is 0
配置过程与windows系统完全一样,一直Next即可。
查看监听状态
[oracle@centos-y ~]$ lsnrctlstatus
LSNRCTL for Linux: Version11.2.0.4.0 - Production on 20-OCT-2017 10:56:45
Copyright (c) 1991,2013,Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=CentOS-y)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version11.2.0.4.0 - Production
Start Date 20-OCT-2017 10:51:45
Uptime 0 days 0 hr. 4 min. 59 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File/u01/app/oracle/diag/tnslsnr/centos-y/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=CentOS-y)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports noservices
The command completedsuccessfully
3.3创建数据库实例
[oracle@centos-y ~]$ dbca
具体创建过程与windows系统相同。
连接数据库,查看相关信息:
[oracle@centos-y ~]$ sqlplus /as sysdba
sql> selectinstance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orcl OPEN
sql> selectdatabase_name,open_mode from v$database;
DATABASE_NAME OPEN_MODE
---------------- ------------
ORCL READ WRITE
3.4数据库启动与关闭
3.4.1启动数据库
在Oracle用户下执行以下操作
1) 启动监听
[oracle@centos-y ~]$ lsnrctl start
LSNRCTL for Linux: Version11.2.0.4.0 - Production on 24-OCT-2017 17:32:24
Copyright (c) 1991,Oracle. All rights reserved.
Starting/u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version11.2.0.4.0 - Production
System parameter file is/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Log messages written to/u01/app/oracle/diag/tnslsnr/centos-y/listener/alert/log.xml
Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=CentOS-y)(PORT=1521)))
Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=CentOS-y)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version11.2.0.4.0 - Production
Start Date 24-OCT-2017 17:32:25
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File/u01/app/oracle/diag/tnslsnr/centos-y/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=CentOS-y)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports noservices
The command completedsuccessfully
2) 查看监听
[oracle@centos-y ~]$ lsnrctl status
[oracle@centos-y ~]$ sqlplus / as sysdba
sql*Plus: Release 11.2.0.4.0Production on Tue Oct 24 17:32:47 2017
Copyright (c) 1982,Oracle. All rights reserved.
Connected to an idle instance.
4) 启动数据库
sql> startup
ORACLE instance started.
Total System Global Area 759943168 bytes
Fixed Size 2257112 bytes
Variable Size 499126056 bytes
Database Buffers 255852544 bytes
Redo Buffers 2707456 bytes
Database mounted.
Database opened.
3.4.2关闭数据库
[oracle@centos-y ~]$ sqlplus / as sysdba
sql*Plus: Release 11.2.0.4.0Production on Tue Oct 24 17:58:12 2017
Copyright (c) 1982,Oracle. All rights reserved.
Connected to:
Oracle Database 11g EnterpriseEdition Release 11.2.0.4.0 - 64bit Production
With the Partitioning,OLAP,Data Mining and Real Application Testing options
sql> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sql> exit
Disconnected from OracleDatabase 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning,Data Mining and Real Application Testing options
4) 关闭监听
[oracle@centos-y ~]$ lsnrctl stop
LSNRCTL for Linux: Version11.2.0.4.0 - Production on 24-OCT-2017 17:59:08
Copyright (c) 1991,Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=CentOS-y)(PORT=1521)))
The command completed successfully
3.4.3常用参数
1) startup 常用参数
参数 |
说明 |
不带参数 |
|
nomount |
|
mount |
2) shutdown 常用参数
参数 |
说明 |
Normal |
需要等待所有的用户断开连接 |
Immediate |
等待用户完成当前的语句 |
Transactional |
等待用户完成当前的事务 |
Abort |
|
normal |
|
immediate |
|
transactional |
|
abort |
4问题记录
这里对安装过程中出现的一些问题做一些总结,以备后用。
问题1
设置图形界面,提示无法打开显示器:“Can't open display “
解决方案:
[oracle@centos-y database]$xclock
Error: Can't open display:
查看
[oracle@centos-y database]$echo $DISPLAY
不显示信息,则执行以下命令
[oracle@centos-y database]$export DISPLAY=:0.0
再次查看
[oracle@centos-y database]$echo $DISPLAY
:0.0
##(这句话可以写进.bashrc,就可以省去每次设计的麻烦)
参考: http://www.jb51.cc/article/p-cnxqhaoa-bgg.html
问题2
安装检查先决条件,报物理内存不足:
解决方案:
查看当前虚拟内存
[root@centos-y ~]# free –m
total used free sharedbuff/cache available
Mem: 976594 73 18 308181
Swap: 2047 2 2045
#将当前swap空间由2048M 增加
[root@centos-y ~]# ddif=/dev/zero of=/home/swap bs=1024 count=1024000
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB)copied,3.71841 s,282 MB/s
[root@centos-y ~]# mkswap/home/swap
Setting up swapspace version 1,size = 1023996 KiB
no label,UUID=0ba7b683-a66b-4341-befa-4d30cefce918
[root@centos-y ~]# swapon/home/swap
swapon: /home/swap: insecurepermissions 0644,0600 suggested.
查看是否修改
[root@centos-y ~]# free -m
total used free sharedbuff/cache available
Mem: 976 595 103 16 276 187
Swap: 3047 81 2966
问题3
安装oracle11g数据库过程报错:PRVF-0002Could not retrieve local nodename
解决方案:
该错误主要是由于hosts文件配置问题:
vi /etc/hosts
修改hosts文件中添加服务器ip以及hostname即可.
192.168.1. 99 CentOS-y
问题4
安装到%86时报错:Error in invoking target 'agent nmhs' of makefile
解决方案:
保留安装界面,另外开启一个终端窗口,将ins_emagent.mk文件中的 (MK_EMAGENT_NMECTL)更改为$(MK_EMAGENT_NMECTL) -lnnz11,然后在安装过程中点击Retry即可。
[oracle@centos-y ~]$ cd$ORACLE_HOME/sysman/lib
[oracle@centos-y lib]$ viins_emagent.mk
定位到:(MK_EMAGENT_NMECTL),添加 lnnz11
回到安装界面,点击“Retry“,即可正常安装