linux 安装Oracle 11g
安装包
linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip
需要的软件包支持:
通过查看Oracle安装文档中列出的Package Requirements可以查看在不同平台上需要的软件包,下面列出Asianux 3, Oracle Enterprise Linux 5.0, and Red Hat Enterprise Linux 5.0的要求,检查
下系统是否安装过这些包,如果没在对应的系统光盘查找对应的rpm包并安装。
检查工作:依次执行:rpm -qa | grep 下面软件包
binutils-2.17.50.0.6
compat-libstdc++-33-3.2.3
elfutils-libelf-0.125
elfutils-libelf-devel-0.125
elfutils-libelf-devel-static-0.125
gcc-4.1.2
gcc-c++-4.1.2
glibc-2.5-24
glibc-common-2.5
glibc-devel-2.5
glibc-headers-2.5
kernel-headers-2.6.18
ksh-20060214
libaio-0.3.106
libaio-devel-0.3.106
libgcc-4.1.2
libgomp-4.1.2
libstdc++-4.1.2
libstdc++-devel-4.1.2
make-3.81
sysstat-7.0.2
unixODBC-2.2.11
unixODBC-devel-2.2.11
1 安装前准备
- Linux操作系统的内核至少为2.6. 16.21。查看操作系统内核版本的命令如下:
uname –r
- Linux主机内存必须大于等于1G,交换空间swap的大小为4G(内存为1~2G时,swap为起1.5倍,如果大于2G,swap等于内存大小)。
- /tmp的空间需要大于500M,不少于1G。
- 系统磁盘空间不能少于6G空间。
2 创建用户组和用户
- 创建oracle和oinstall组
[root@oracle ~]# groupadd dba [root@oracle ~]# groupadd oinstall [root@oracle ~]# useradd -g oinstall -G dba oracle [root@oracle ~]# passwd oracle Changing password for user oracle.. New password: BAD PASSWORD: The password is shorter than 8 characters Retype new password: passwd: all authentication tokens updated successfully. [root@oracle ~]#
修改内核参数
root用户:修改 /etc/sysctl.conf 文件,加上如下参数
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
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
# /sbin/sysctl -p vm.swappiness = 0 net.core.somaxconn = 1024 net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.tcp_max_syn_backlog = 1024 fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152 kernel.shmmax = 536870912 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
修改用户限制
root用户:修改 /etc/security/limits.conf 文件,加上下面的参数
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
创建安装目录、修改文件权限
# mkdir -p /data/oracle # chown -R oracle:oinstall /data/oracle/ # chmod -R 775 /data/oracle/
创建/etc/oraInst.loc文件
# vi /etc/oraInst.loc nventory_loc=/data/oracle/oraInventory inst_group=oinstall # chown oracle:oinstall /etc/oraInst.loc # chmod 664 /etc/oraInst.loc
官网下载64位的oracle软件包,并上传到 /data/oracle目录下(xftp上传)
# ll linux.x64_11gR2_database* -rw-r--r-- 1 root root 1239269270 Jan 20 16:29 linux.x64_11gR2_database_1of2.zip -rw-r--r-- 1 root root 1111416131 Jan 20 16:30 linux.x64_11gR2_database_2of2.zip
解压oracle软件包
# unzip linux.x64_11gR2_database_1of2.zip
# unzip linux.x64_11gR2_database_2of2.zip
切换到oracle用户,设置oracle用户环境变量,添加以下内容:
# su - oracle $ vim .bash_profile export ORACLE_BASE=/data/oracle export ORACLE_SID=orcl $ source .bash_profile
复制响应文件模板
# mkdir /data/oracle/etc # cp /data/oracle/database/response/* /data/oracle/etc/ # chown -R oracle:oinstall /data/oracle/ # chmod -R 775 /data/oracle/
编辑 /data/oracle/database/etc/db_install.rsp文件,修改以下参数
# chmod 700 /data/oracle/etc/*.rsp # su - oracle $ vim /data/oracle/etc/db_install.rsp oracle.install.option=INSTALL_DB_SWONLY // 安装类型 ORACLE_HOSTNAME=oracle // 主机名称(hostname查询,这里要注意,主机名要在 /etc/hosts 文件中配置好ip对应关系,否则安装会报错) UNIX_GROUP_NAME=oinstall // 安装组 INVENTORY_LOCATION=/data/oracle/oraInventory //INVENTORY目录(不填就是默认值) SELECTED_LANGUAGES=en,zh_CN,zh_TW // 选择语言 ORACLE_HOME=/data/oracle/product/11.2.0/db_1 // oracle_home ORACLE_BASE=/data/oracle // oracle_base oracle.install.db.InstallEdition=EE // oracle版本 oracle.install.db.isCustomInstall=false //自定义安装,否,使用默认组件 oracle.install.db.DBA_GROUP=dba // dba用户组 oracle.install.db.OPER_GROUP=oinstall // oper用户组 oracle.install.db.config.starterdb.type=GENERAL_PURPOSE //数据库类型 oracle.install.db.config.starterdb.globalDBName=orcl //globalDBName(这里要和第8步配置的sid一致) oracle.install.db.config.starterdb.SID=orcl //SID(这里要和第8步配置的sid一致) oracle.install.db.config.starterdb.memoryLimit=81920 //自动管理内存的内存(M) oracle.install.db.config.starterdb.password.ALL=123456//设定所有数据库用户使用同一个密码 SECURITY_UPDATES_VIA_MYORACLESUPPORT=false(手动写了false) DECLINE_SECURITY_UPDATES=true //设置安全更新(貌似是有bug,这个一定要选true,否则会无限提醒邮件地址有问题,终止安装。PS:不管地址对不对)
根据响应文件安装oracle 11g
# su - oracle $ cd /data/oracle/database/ $ ./runInstaller -silent -ignorePrereq -responseFile /data/oracle/etc/db_install.rsp Starting Oracle Universal Installer... Checking Temp space: must be greater than 120 MB. Actual 255428 MB Passed Checking swap space: must be greater than 150 MB. Actual 999 MB Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2022-01-20_07-31-19PM. Please wait ...[oracle@ecs-shuxiaoer-bi database]$ [WARNING] [INS-32055] The Central Inventory islocated in the Oracle base. CAUSE: The Central Inventory is located in the Oracle base. ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory. [WARNING] [INS-32055] The Central Inventory is located in the Oracle base. CAUSE: The Central Inventory is located in the Oracle base. ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory. You can find the log of this install session at: /data/oracle/oralnventory/logs/installActions2022-01-20_07-31-19PM.log The following configuration scripts need to be executed as the "root" user. #!/bin/sh #Root scripts to run /data/oracle/product/11.2.0/db_1/root.sh To execute the configuration scripts: 1. Open a terminal window 2. Log in as "root" 3. Run the scripts 4. Return to this window and hit "Enter" key to continue Successfully Setup Software.
看安装日志
# tail -200f /data/oracle/oralnventory/logs/installActions2022-01-20_07-31-19PM.log
执行配置脚本
# /data/oracle/product/11.2.0/db_1/root.sh Check /data/oracle/product/11.2.0/db_1/install/root_ecs-shuxiaoer-bi_2022-01-20_19-43-15.log for the output of root script
执行 su - oracle 命令,用 oracle 用户登陆
vi ~/.bash_profile 在后面追加下面配置
# su - oracle $ vim ~/.bash_profile export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 export TNS_ADMIN=$ORACLE_HOME/network/admin export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin export PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/lib export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE/lib export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib export LIBPATH=${CLASSPATH}:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib export ORACLE_OWNER=oracle export SPFILE_PATH=$ORACLE_HOME/dbs export ORA_NLS10=$ORACLE_HOME/nls/data $ source ~/.bash_profile
到这里,oracle 11g 的数据库实例就算是装好了
配置数据库实例的基本参数文件
$ cd $ORACLE_HOME/dbs $ $ cat init.ora | grep -v ^# | grep -v ^$ | cat > init$ORACLE_SID.ora $ ls init.ora initorcl.ora $ vim initorcl.ora db_name='oracl' memory_target=1G processes = 150 audit_file_dest= '/data/oracle/admin/orcl/adump' audit_trail ='db' db_block_size=8192 db_domain='' db_recovery_file_dest='/data/oracle/flash_recovery_area' db_recovery_file_dest_size=2G diagnostic_dest='/data/oracle' dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)' open_cursors=300 remote_login_passwordfile='EXCLUSIVE' undo_tablespace='UNDOTBS1' control_files = (ora_control1, ora_control2) compatible ='11.2.0'
$ mkdir -p /data/oracle/admin/orcl/adump $ mkdir -p /data/oracle/flash_recovery_area $ mkdir -p /data/oracle/oradata
执行命令 vi /data/oracle/script.sql 编辑sql脚本文件,内容如下
$ vim /data/oracle/script.sql CREATE DATABASE orcl USER SYS IDENTIFIED BY sys USER SYSTEM IDENTIFIED BY system LOGFILE GROUP 1 ('/data/oracle/oradata/redo01.log') SIZE 1024M, GROUP 2 ('/data/oracle/oradata/redo02.log') size 1024m, GROUP 3 ('/data/oracle/oradata/redo03.log') size 1024m, GROUP 4 ('/data/oracle/oradata/redo04.log') size 1024m, GROUP 5 ('/data/oracle/oradata/redo05.log') size 1024m MAXLOGFILES 5 MAXLOGMEMBERS 5 MAXLOGHISTORY 200 MAXDATAFILES 10000 MAXINSTANCES 1 CHARACTER SET ZHS16GBK NATIONAL CHARACTER SET AL16UTF16 datafile '/data/oracle/oradata/system01.dbf' size 2048M REUSE EXTENT MANAGEMENT LOCAL sysaux datafile '/data/oracle/oradata/sysaux01.dbf' size 2048M REUSE default temporary tablespace temp tempfile '/data/oracle/oradata/temp01.dbf' size 2048M REUSE undo tablespace UNDOTBS1 datafile '/data/oracle/oradata/undotbs01.dbf' size 4096M REUSE AUTOEXTEND off default tablespace DATA datafile '/data/oracle/oradata/data01.dbf' size 8192M REUSE EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
执行命令 sqlplus / as sysdba 登陆 oracle 数据库
登陆成功后执行 startup nomount; 启动数据库,注意必须包含有分号,否则oracle不执行。
执行第配置的脚本,这个脚本执行过程很长,而且没有任何提示,等显示 Database created. 就成功了。
$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 20 20:26:21 2022 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount; ORACLE instance started. Total System Global Area 1068937216 bytes Fixed Size 2220200 bytes Variable Size 616566616 bytes Database Buffers 444596224 bytes Redo Buffers 5554176 bytes SQL> @/data/oracle/script.sql; Database created. SQL>
创建数据字典和pl/sql包
SQL> @/data/oracle/product/11.2.0/db_1/rdbms/admin/catalog.sql0; SQL> @/data/oracle/product/11.2.0/db_1/rdbms/admin/catproc.sql; SQL> @/data/oracle/product/11.2.0/db_1/rdbms/admin/utlrp.sql; SQL> conn system/system; SQL> @/data/oracle/product/11.2.0/db_1/sqlplus/admin/pupbld.sql; SQL> exit
前两个脚本执行过程很长。
创建完成后先执行 exit 命令退出,然后再执行 sqlplus / as sysdba 登陆数据库;
然后执行 shutdown immediate; 命令关闭数据库;
再执行 startup; 启动oracle数据库。先退出再登陆是因为conn system/system之后,当前用户就变成了system,而system没有关闭数据库权限。
$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 20 20:37:05 2022 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 SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup; ORACLE instance started. Total System Global Area 1068937216 bytes Fixed Size 2220200 bytes Variable Size 616566616 bytes Database Buffers 444596224 bytes Redo Buffers 5554176 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
配置监听器文件
# vim /data/oracle/product/11.2.0/db_1/network/admin/listener.ora # listener.ora Network Configuration File: /app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 【计算机名】)(PORT = 1521))(这里的HOST要填本机的计算机名) ) ) ADR_BASE_LISTENER = /app/oracle
$ vi /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora # tnsnames.ora Network Configuration File: /app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. QXT = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ecs)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) # listener.ora Network Configuration File: /app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ecs)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /app/oracle
启动监听器
$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 20-JAN-2022 20:47:03 Copyright (c) 1991, 2009, Oracle. All rights reserved. Starting /data/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 11.2.0.1.0 - Production System parameter file is /data/oracle/product/11.2.0/db_1/network/admin/listener.ora Log messages written to /data/oracle/product/11.2.0/db_1/network/log/listener.log Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ecs)(PORT=1521))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ecs)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 20-JAN-2022 20:47:03 Uptime 0 days 0 hr. 0 min. 16 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /data/oracle/product/11.2.0/db_1/network/log/listener.log Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ecs)(PORT=1521))) The listener supports no services The command completed successfully
$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 20-JAN-2022 20:50:22 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ecs)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 20-JAN-2022 20:47:03 Uptime 0 days 0 hr. 3 min. 19 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /data/oracle/product/11.2.0/db_1/network/log/listener.log Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ecs)(PORT=1521))) Services Summary... Service "ORCLXDB" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... Service "orcl" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... The command completed successfully
创建用户
$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 20 20:51:24 2022 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 SQL> create user test identified by test123; User created. SQL> grant connect, resource to test; Grant succeeded. SQL> grant create session to test; Grant succeeded. SQL> create tablespace test_DATA datafile '/data/oracle/oradata/test_001.dbf' size 16G; Tablespace created. SQL> alter user test default tablespace test_DATA temporary tablespace TEMP; User altered. SQL>
*补充一个异常:安装时如果提示swap空间为0M,需要做如下配置:
dd if=/dev/zero of=/home/swapfile bs=1M count=4096
mkswap /home/swapfile
swapon /home/swapfile
vi /etc/fstab
/home/swapfile swap swap defaults 0 0
和11g相比,12c的db_install.rsp配置文件除了11g的参数外,还要额外设置下面参数,否则会报错
oracle.install.db.BACKUPDBA_GROUP=dba
oracle.install.db.DGDBA_GROUP=dba
oracle.install.db.KMDBA_GROUP=dba
————————————————