redhat7.5静默安装oracle 11G R2
本次安装中所需要的所有软件:
链接: https://pan.baidu.com/s/1zw-ehNEkYbUNj-ujaB4WRw
提取码:mpaf
1.配置/etc/hosts文件和关闭seliux和firewall防火墙
#修改服务器名称及配置hosts文件 [root@redhat7 ~]# hostnamectl set-hostname redhat7 [root@redhat7 ~]# echo "192.168.100.35 redhat7">>/etc/hosts #禁用selinux [root@redhat7 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config #关闭防火墙 [root@redhat7 ~]# systemctl stop firewalld [root@redhat7 ~]# systemctl disable firewalld
2.检查安装数据库所需要的包
#所有yum安装都是通过镜像文件搭建的本地yum源安装的 [root@redhat7 ~]# rpm -q binutils compat-libstdc++-33 elfutils-libelf gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers ksh libaio libaio-devel libgomp libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel numactl-devel perl-Env elfutils-libelf-devel readline readline-devel unzip vim | grep "not installed" #安装当前服务器所缺少的包,下面是我服务器所需要安装的包(redhat7.5最小化安装) [root@redhat7 ~]# yum install -y ksh libaio-devel sysstat unixODBC unixODBC-devel numactl-devel perl-Env elfutils-libelf-devel gcc* readline readline-devel unzip vim #其中compat-libstdc++-33需手动下载上传安装 root@redhat7 ~]# rpm -ivh compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm #安装rlwrap,这是一个Linux下使用sqlplus的辅助软件,帮助Linux命令行中sqlplus的上下键退格键 [root@redhat7 ~]# tar -zxvf 12-rlwrap-0.37.tar.gz [root@redhat7 ~]# cd rlwrap-0.37/ [root@redhat7 rlwrap-0.37]# ./configure [root@redhat7 rlwrap-0.37]# make&&make install
3.创建用户和组
[root@redhat7 ~]# groupadd oinstall [root@redhat7 ~]# groupadd dba [root@redhat7 ~]# useradd -g oinstall -G dba oracle [root@redhat7 ~]# passwd oracle
4. 系统参数配置
#编辑/etc/sysctl.conf [root@redhat7 ~]# cat <<END>> /etc/sysctl.conf fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmmax = 4294967295 kernel.shmall = 268435456 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 END [root@redhat7 ~]# sysctl -p #编辑/etc/security/limits.conf [root@redhat7 ~]# cat <<END>>/etc/security/limits.conf oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 oracle soft stack 10240 oracle hard stack 32768 END #编辑/etc/pam.d/login,追加一行 [root@redhat7 ~]# echo "session required /usr/lib64/security/pam_limits.so" >> /etc/pam.d/login 注意pam_limits.so文件的路径,可以先通过find来判断 find / -name pam_limits.so
5.配置oracle用户环境变量
[root@redhat7 ~]# vim /home/oracle/.bash_profile #在文件后添加下面的配置 umask 022 export ORACLE_SID=ykgl #sid export ORACLE_BASE=/data/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS" export TMP=/tmp export TMPDIR=$TMP export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH export EDITOR=vim export TNS_ADMIN=$ORACLE_HOME/network/admin export SQLPATH=$ORACLE_HOME/sqlplus/admin export NLS_LANG="AMERICAN_CHINA.ZHS16GBK" alias sqlplus='rlwrap sqlplus' alias rman='rlwrap rman' alias asmcmd='rlwrap asmcmd'
6. 创建安装目录
#u01是oracle安装目录 [root@redhat7 ~]# mkdir /data/u01 #soft是存放数据库软件的目录 [root@redhat7 ~]# mkdir /data/soft [root@redhat7 ~]# chown -R oracle:oinstall /data
7. 重启系统,切换oracle用户安装软件
#将数据库软件上传到/data/soft/目录下,解压安装包 [oracle@redhat7 ~]$ cd /data/soft/ [oracle@redhat7 soft]$ unzip p13390677_112040_Linux-x86-64_1of7.zip && unzip p13390677_112040_Linux-x86-64_2of7.zip [oracle@redhat7 soft]$ ls database p13390677_112040_Linux-x86-64_1of7.zip p13390677_112040_Linux-x86-64_2of7.zip
8. 编辑静默安装的应答文件db_install.rsp,此文件位于/data/soft/database/response/目录下
[oracle@redhat7 soft] cp database/response/netca.rsp /home/oracle/ #编辑应答文件 [oracle@redhat7 database]$ sed -i '/^#/d' /home/oracle/db_install.rsp # 将文件中的注释删除 [oracle@redhat7 database]$ sed -i '/^$/d' /home/oracle/db_install.rsp # 将文件中的空白行删除 [oracle@redhat7 database]$ vim /home/oracle/db_install.rsp #设置以下内容根据实际情况和需要修改 oracle.install.option=INSTALL_DB_SWONLY ORACLE_HOSTNAME=redhat7 UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/data/u01/app/oracle/inventory SELECTED_LANGUAGES=en,zh_CN ORACLE_HOME=/data/u01/app/oracle/product/11.2.0/dbhome_1 ORACLE_BASE=/data/u01/app/oracle oracle.install.db.InstallEdition=EE oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=dba DECLINE_SECURITY_UPDATES=true
9. 执行静默安装(需要开启交换分区swap,否则会报错)
[oracle@redhat7 database]$ ./runInstaller -silent -responseFile /home/oracle/db_install.rsp -ignorePrereq Starting Oracle Universal Installer... Checking Temp space: must be greater than 120 MB. Actual 14307 MB Passed Checking swap space: must be greater than 150 MB. Actual 4095 MB Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-10-28_02-28-55PM. Please wait ...[oracle@redhat7 database]$ [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/u01/app/oracle/inventory/logs/installActions2019-10-28_02-28-55PM.log The installation of Oracle Database 11g was successful. Please check '/data/u01/app/oracle/inventory/logs/silentInstall2019-10-28_02-28-55PM.log' for more details. As a root user, execute the following script(s): 1. /data/u01/app/oracle/inventory/orainstRoot.sh 2. /data/u01/app/oracle/product/11.2.0/dbhome_1/root.sh Successfully Setup software.另开个终端,使用root账户按顺序执行上面的两个脚本 [root@redhat7 ~]# /data/u01/app/oracle/inventory/orainstRoot.sh Changing permissions of /data/u01/app/oracle/inventory. Adding read,write permissions for group. Removing read,write,execute permissions for world. Changing groupname of /data/u01/app/oracle/inventory to oinstall. The execution of the script is complete. [root@redhat7 ~]# /data/u01/app/oracle/product/11.2.0/dbhome_1/root.sh Check /data/u01/app/oracle/product/11.2.0/dbhome_1/install/root_henry_2019-10-28_14-36-30.log for the output of root script
10. 编辑静默建库应答文件dbca.rsp
#复制建库应答文件dbca.rsp到oracle家目录下 [oracle@redhat7 database]$ cp response/dbca.rsp /home/oracle/ [oracle@redhat7 database]$ sed -i '/^#/d' /home/oracle/dbca.rsp #将文件中的注释删除 [oracle@redhat7 database]$ sed -i '/^$/d' /home/oracle/dbca.rsp #将文件中的空白行删除 [oracle@redhat7 database]$ vim /home/oracle/dbca.rsp #修改下面这些内容可根据需要修改 GDBNAME = "ykgl" #服务名 SID = "ykgl" #sid SYSPASSWORD = "oracle" #sys密码 SYSTEMPASSWORD = "oracle" #ststem密码 DATAFILEDESTINATION =/data/u01/app/oracle/oradata RECOVERYAREADESTINATION=/data/u01/app/oracle/fast_recovery_area CHARACTERSET = "AL32UTF8" DATABASETYPE = "OLTP" TOTALMEMORY = "2048"
11.执行静默建库
[oracle@redhat7 ~]$ dbca -silent -responseFile /home/oracle/dbca.rsp Copying database files 1% complete 3% complete 37% complete Creating and starting Oracle instance 40% complete 45% complete 50% complete 55% complete 56% complete 57% complete 60% complete 62% complete Completing Database Creation 66% complete 70% complete 73% complete 85% complete 96% complete 100% complete Look at the log file "/data/u01/app/oracle/cfgtoollogs/dbca/ykgl/ykgl.log" for further details.
12. 配置监听,将配置监听的应答文件netca.rsp复制oracle用户的家目录下,不用做修改
[oracle@redhat7 ~]$ cp /data/soft/database/response/netca.rsp home/oracle/ [oracle@redhat7 ~]$ netca -silent -responseFile /home/oracle/netca.rsp Parsing command line arguments: Parameter "silent" = true Parameter "responsefile" = /home/oracle/netca.rsp Done parsing command line arguments. Oracle Net Services Configuration: Profile configuration complete. Oracle Net Listener Startup: Running Listener Control: /data/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start LISTENER Listener Control complete. Listener started successfully. Listener configuration complete. Oracle Net Services configuration successful. The exit code is 0 在/data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/目录下会新增listener.ora 和sqlnet.ora两个文件 [oracle@redhat7 ~]$ ls /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/ listener.ora samples shrept.lst sqlnet.ora [oracle@redhat7 ~]$ cat /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # listener.ora Network Configuration File: /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = ====>这个字符串就是监听名 (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = henry)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /data/u01/app/oracle #这是个动态监听,监听创建后就已启动。启动,停止,查看监听状态。 #查看监听状态 [oracle@redhat7 ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 29-OCT-2019 09:57:37 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 29-OCT-2019 09:29:29 Uptime 0 days 0 hr. 28 min. 8 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora Listener Log File /data/u01/app/oracle/diag/tnslsnr/henry/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=henry)(PORT=1521))) Services Summary... Service "ykgl" has 1 instance(s). Instance "ykgl", status READY, has 1 handler(s) for this service... Service "ykglXDB" has 1 instance(s). Instance "ykgl", status READY, has 1 handler(s) for this service... The command completed successfully #停止监听 [oracle@redhat7 ~]$ lsnrctl stop LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 29-OCT-2019 10:00:10 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) The command completed successfully #启动监听 [oracle@redhat7 ~]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 29-OCT-2019 10:00:46 Copyright (c) 1991, 2013, Oracle. All rights reserved. Starting /data/u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 11.2.0.4.0 - Production System parameter file is /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora Log messages written to /data/u01/app/oracle/diag/tnslsnr/henry/listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=henry)(PORT=1521))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 29-OCT-2019 10:00:46 Uptime 0 days 0 hr. 0 min. 0 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora Listener Log File /data/u01/app/oracle/diag/tnslsnr/henry/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=henry)(PORT=1521))) The listener supports no services The command completed successfully
13. 登入数据库
[oracle@redhat7 ~]$ sqlplus /nolog SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 29 10:13:50 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. SQL> conn / as sysdba Connected. SQL> show user; USER is "SYS" SQL> show parameter db_name; NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ db_name string ykgl SQL> select status from v$instance; STATUS ------------------------ OPEN sql> select instance_name from v$instance; INSTANCE_NAME ---------------- ykgl
14.扩展一,将默认监听端口1521修改成11521和配置远程连接的监听
#先停止监听 [oracle@redhat7 ~]$ lsnrctl stop #修改监听文件 [oracle@redhat7 ~]$ vim /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # listener.ora Network Configuration File: /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. #注意文件中的括号需要对齐,也就是上下两个监听的缩进需要保持一致,和k8s中的YAML文件有点类似 LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC11521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.35)(PORT = 11521)) ) ) ADR_BASE_LISTENER = /data/u01/app/oracle SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = ykgl ) (ORACLE_HOME =/data/u01/app/oracle/product/11.2.0/dbhome_1) (SID_NAME = ykgl ) ) )
15.扩展二,创建数据库分配表和用户名密码
SQL> create tablespace TABLESPACE_YKGL_SHANXI datafile '/data/u01/app/oracle/oradata/tablespace_ykgl_shanxi.dbf' size 500M autoextend on next 5m maxsize unlimited; SQL> create user ykgl_shanxi identified by "Hn@jin20tvlhw" default tablespace TABLESPACE_YKGL_SHANXI temporary tablespace TEMP profile default; SQL> grant connect,resource,dba to ykgl_shanxi; SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; SQL> commit;