centos7静默安装oracle11gR2,安装前需要确定硬件是否支持。因为是静默安装,所以我们不需要安装图形界面。
环境要求 交换空间
内存要求 内存最小1G,推荐2G或者更高
swap分区查看 先用命令查看自己的swap多大 -> free -m ,没有设置分区的话需要设置一下。1 2 3 4 5 dd if=/dev/zero of=/swap bs=1024 count=2048000 mkswap /swap chmod 600 /swap swapon /swap echo "/swap swap swap default 0 0">>/etc/fstab #设置成自动挂载
下载Oracle 下载文件需要注册oracle账户,从浏览器的下载点下载软件。官方网站:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/ 根据自己服务器配置,下载相应的软件,我的系统是64位的,所以下载的是 Linux x86-64的,下载完的两个文件如下:
linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip
环境配置 Java JDK 安装 1 2 3 4 5 6 yum -y install java-1.8.0-openjdk* 安装结果: java -version openjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-b04) OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
配置hostname 1 2 hostnamectl set-hostname oracledb echo "10.1.1.5 oracledb" >>/etc/hosts
关闭selinux 1 2 sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config setenforce 0
检查软件依赖环境 注意:从Oracle 11g 11.2.0.2版本开始,在Linux x86_64上安装时,只需要安装64位的软件包,但是,对于11.2.0.2之前的任何Oracle database 11g,下表中列出的32位和64位的安装包都必须安装,需要安装的依赖包(版本号只能大于规定的版本,不能小于)1 2 3 4 # 检查软件依赖环境 rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel | grep "not installed" # 安装依赖 yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel
创建所需的操作系统组和用户 Oracle inventory组(通常为 oinstall),OSDBA组 (通常为 dba),OSOPER组 (通常为 oper),Oracle软件所有者(通常为 oracle)1 2 3 4 5 6 7 #添加 groupadd oinstall groupadd dba groupadd oper useradd -g oinstall -G dba oracle # 修改密码 passwd oracle
配置内核参数和资源限制 在/etc/sysctl.conf添加如下参数,如果系统中某个参数高于下面的参数的值 ,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 # 调整内容 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 = 1048576 # 使内核参数生效 sysctl -p # 在/etc/security/limits.conf中添加如下参数 oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 # 在/etc/pam.d/login文件中,添加下面内容 session required /lib64/security/pam_limits.so session required pam_limits.so # /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文件生效 source /etc/profile
禁用使用Transparent HugePages Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages)1 2 3 4 # 查看是否启用 如果显示 [always]说明启用了 cat /sys/kernel/mm/transparent_hugepage/enabled # 禁用Transparent HugePages,在/etc/grub.conf添加如下内容 echo never > /sys/kernel/mm/transparent_hugepage/enabled
重新启动系统以使更改成为永久更改。
ORACLE 安装配置 创建oracle安装目录 1 2 3 4 5 6 7 8 9 10 11 12 13 14 # 程序目录 mkdir -p /usr/local/app/ # 其他子目录 mkdir -p /usr/local/app/oracle mkdir -p /usr/local/app/etc mkdir -p /usr/local/app/oracle/product mkdir -p /usr/local/app/oracle/product/11.2.0 mkdir -p /usr/local/app/oracle/fast_recovery_area mkdir -p /usr/local/app/oracle/inventory mkdir -p /usr/local/app/oracle/oradata # 改变组和权限 chown -R oracle:oinstall /usr/local/app/ chmod -R 775 /usr/local/app/
解压文件改配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 unzip -q linux.x64_11gR2_database_1of2.zip -d /home/software/ unzip -q linux.x64_11gR2_database_2of2.zip -d /home/software/ cp /home/software/database/response/* /usr/local/app/etc # 在/usr/local/app/etc/db_install.rsp修改以下变量的值 oracle.install.option=INSTALL_DB_SWONLY DECLINE_SECURITY_UPDATES=true UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/usr/local/app/oracle/inventory SELECTED_LANGUAGES=en,zh_CN ORACLE_HOSTNAME=oracledb ORACLE_HOME=/usr/local/app/oracle/product/11.2.0 ORACLE_BASE=/usr/local/app/oracle oracle.install.db.InstallEdition=EE oracle.install.db.isCustomInstall=true oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=dba
开始安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # 安装 su - oracle cd /home/software/database/ ./runInstaller -silent -responseFile /usr/local/app/etc/db_install.rsp -ignorePrereq # 安装过程日志查看 tail -f /usr/local/app/oracle/inventory/logs/installActions2019-06-02_06-03-30PM.log # 如果有类似如下提示,说明安装完成 The following configuration scripts need to be executed as the "root" user. #!/bin/sh #Root scripts to run /usr/local/app/oraInventory/orainstRoot.sh /usr/local/app/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.
用户环境变量配置 文件/home/oracle/.bash_profile里添加下面内容(具体值根据实际情况修改)1 2 3 4 5 6 7 8 9 10 umask 022 export ORACLE_HOSTNAME=oracledb export ORACLE_BASE=/usr/local/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/ export ORACLE_SID=ORCL export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH export LC_ALL="en_US" export LANG="en_US" export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK" export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
使用root用户执行脚本 1 2 3 su - root sh /usr/local/app/oracle/inventory/orainstRoot.sh sh /usr/local/app/oracle/product/11.2.0/root.sh
配置监听程序 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 # su - oracle netca /silent /responsefile /usr/local/app/etc/netca.rsp # 输出 Parsing command line arguments: Parameter "silent" = true Parameter "responsefile" = /usr/local/app/etc/netca.rsp Done parsing command line arguments. Oracle Net Services Configuration: Profile configuration complete. Oracle Net Listener Startup: Running Listener Control: /usr/local/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER Listener Control complete. Listener started successfully. Listener configuration complete. Oracle Net Services configuration successful. The exit code is 0 # 查看监听端口 netstat -tnpl | grep 1521
静默创建数据库 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 # 修改文件 [GENERAL] RESPONSEFILE_VERSION = "11.2.0" OPERATION_TYPE = "createDatabase" [CREATEDATABASE] GDBNAME = "orcl" SID = "orcl" SYSPASSWORD = "oracle" SYSTEMPASSWORD = "oracle" SYSMANPASSWORD = "oracle" DBSNMPPASSWORD = "oracle" DATAFILEDESTINATION =/usr/local/app/oracle/oradata RECOVERYAREADESTINATION=/usr/local/app/oracle/fast_recovery_area CHARACTERSET = "AL32UTF8" TOTALMEMORY = "1638" # 执行静默建库 su - oracle dbca -silent -responseFile /usr/local/app/etc/dbca.rsp # 等待执行结果 Copying database files 1% complete 3% complete 11% complete 18% complete # 查看进程 ps -ef | grep ora_ | grep -v grep # 监听状态 lsnrctl status
启动连接 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 su - oracle sqlplus / as sysdba select status from v$instance; # 报错的解决方式 SQL>statup SQL>startup # 解决方式 [oracle@oracledb ~]$ find /usr/local/app/oracle/ -name *init.ora* /usr/local/app/oracle/product/11.2.0/dbs/init.ora /usr/local/app/oracle/product/11.2.0/srvm/admin/init.ora /usr/local/app/oracle/admin/orcl/pfile/init.ora.522019234840 # cp /usr/local/app/oracle/admin/orcl/pfile/init.ora.522019234840 /usr/local/app/oracle/product/11.2.0/dbs/initORCL.ora # 查看数据库版本 select * from v$version
激活scott用户 1 2 3 4 激活scott用户 alter user scott account unlock; alter user scott identified by tiger; select username,account_status from dba_users;
设置Oracle开机启动 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 # 修改/usr/local/app/oracle/product/11.2.0/bin/dbstart ORACLE_HOME_LISTNER=$ORACLE_HOME # 修改/usr/local/app/oracle/product/11.2.0/bin/dbshut ORACLE_HOME_LISTNER=$ORACLE_HOME # vi /etc/oratab orcl:/usr/local/app/oracle/product/11.2.0:Y 新建文件/etc/rc.d/init.d/oracle #! /bin/bash # oracle: Start/Stop Oracle Database 11g R2 # # chkconfig: 345 90 10 # description: The Oracle Database is an Object-Relational Database Management System. # # processname: oracle . /etc/rc.d/init.d/functions LOCKFILE=/var/lock/subsys/oracle ORACLE_HOME=/usr/local/app/oracle/product/11.2.0 ORACLE_USER=oracle case "$1" in 'start') if [ -f $LOCKFILE ]; then echo $0 already running. exit 1 fi echo -n $"Starting Oracle Database:" su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start" su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole" touch $LOCKFILE ;; 'stop') if [ ! -f $LOCKFILE ]; then echo $0 already stopping. exit 1 fi echo -n $"Stopping Oracle Database:" su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop" su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut" su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole" rm -f $LOCKFILE ;; 'restart') $0 stop $0 start ;; 'status') if [ -f $LOCKFILE ]; then echo $0 started. else echo $0 stopped. fi ;; *) echo "Usage: $0 [start|stop|status]" exit 1 esac exit 0 # 给/etc/init.d/oracle添加执行权限 chmod +x /etc/init.d/oracle # 开机启动oracle systemctl enable oracle 或 chkconfig oracle on 给启动文件加权限 cd /usr/local/app/oracle/product/11.2.0/bin/ chmod 6751 oracle cd /var/tmp chown -R oracle:oinstall .oracle # 防火墙配置放开Oracle的端口 firewall-cmd --zone=public --add-port=1521/tcp --permanent firewall-cmd --reload
配置ORACLE远程连接 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 # 需要配置的文件如下 -rw-r--r-- 1 oracle oinstall 731 Jun 3 04:29 listener.ora drwxr-xr-x. 2 oracle oinstall 61 Jun 2 23:14 samples -rw-r--r--. 1 oracle oinstall 187 May 7 2007 shrept.lst -rw-r--r-- 1 oracle oinstall 265 Jun 3 05:33 sqlnet.ora -rw-r----- 1 oracle oinstall 325 Jun 3 04:18 tnsnames.ora # listener.ora LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.1.5 )(PORT = 1521)) ) ) SID_LIST_LISTENER= (SID_LIST= (SID_DESC= #BEQUEATH CONFIG (GLOBAL_DBNAME=orcl) (SID_NAME=orcl) (ORACLE_HOME=/usr/local/app/oracle/product/11.2.0) #PRESPAWN CONFIG (PRESPAWN_MAX=20) (PRESPAWN_LIST= (PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1)) ) ) ) ADR_BASE_LISTENER = /usr/local/app/oracle # tnsnames.ora ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.1.5 )(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
数据库启动及状态查看 1 2 3 4 5 6 7 8 9 10 # 启动后挂载open 状态查看 SQL>startup mount; SQL>alter database open; SQL>shutdown immediate #关闭 SQL>select status from v$instance;--查看数据库状态 # 监听状态查看/启动/关闭 lsnrctl status/start/stop # SQLPlus 登陆 sqlplus / nolog connect / as sysdba