Linux下安装Oracle11gR2 时间:2022-09-30 07:37:40 作者:快盘下载 人气: [TOC]0x00 Linux中Oracle11g安装CentOS 安装 : VM12 + centos7 x86_64_minimal.iso #最小化安装的Centos7 Oracle Version: Oracle Database 11g Release 2 (11.2.0.1.0) #要求: RAW Swap 1G至2G 1.5倍 2G至16G 同RAW相等 16G以上 16G #虚拟机配置: - 60G 硬盘 - 4G ram + 2G swap #项目实施: IP:192.168.136.128 hostname: oracle11 账号密码:root/oracel sySTEM@2019! SID: orcl 服务名称:orcl.db1 密码:sySTEM@2019! 1.安装流程 : #Step1.建立虚拟机导入centos7,minimal镜像并启动 关键点1:系统语言选择要将English勾选上 关键点2:磁盘分区进行手动分区,将交换分区进行调整; $lsb_release -a #查看版本信息 CentOS Linux release 7.6.1810 (Core) 3.10.0-957.el7.x86_64 WeiyiGeek.语言选择WeiyiGeek.磁盘分区#Step2.系统环境调整 步骤1.开启sshd服务并且允许root进行登录 sed -i 's/#PermitRootLogin/PermitRootLogin/g' /etc/ssh/sshd_config systemctl restart sshd 步骤2.安装必要的软件包源和软件与环境调整 # ( 关闭安全措施) sed -i.bak '/SELINUX/s/enforcing/disabled/' /etc/sysconfig/selinux echo "SELINUX=disabled" > /etc/selinux/config echo "#SELINUXTYPE=targeted " >> /etc/selinux/config setenforce 0 systemctl stop firewalld.service systemctl disable firewalld.service systemctl status firewalld.service #重启机器(注意) # 软件源更新 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum clean all && yum makecache yum update -y && yum upgrade -y yum install -y nano vim net-tools tree wget dos2unix unzip ntpdate # From Public Yum or ULN yum -y install autoconf automake binutils binutils-devel bison cpp gcc gcc-c++ lrzsz python-devel compat-db* compat-gcc-34 compat-gcc-34-c++ compat-libcap1 compat-libstdc++-33 compat-libstdc++-33.i686 glibc-* glibc-*.i686 glibc glibc-common glibc-devel glibc-headers libXpm-*.i686 libXp.so.6 libXt.so.6 libXtst.so.6 libXext libXext.i686 libXtst libXtst.i686 libX11 libX11.i686 libXau libXau.i686 libxcb libxcb.i686 libXi libXi.i686 libXtst libstdc++-docs libgcc_s.so.1 libstdc++.i686 libstdc++-devel libstdc++-devel.i686 libaio libaio.i686 libaio-devel libaio-devel.i686 ksh libXp libaio-devel numactl numactl-devel make sysstat unixODBC unixODBC-devel elfutils-libelf-devel-0.97 elfutils-libelf-devel elfutils-libelf elfutils-libelf-devel libgcc expat #检查依赖是否安装完整: rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel | grep "not installed" #系统语言与java环境设置 echo "export LANG=en_US.UTF8" >> ~/.bash_profile source ~/.bash_profile #系统hosts绑定 hostname oracle11 #在/etc/hosts文件中将hostname与回环IP地址对应上就解决了。 echo "192.168.136.128 oracle11" # Java SE Development Kit 8u211 $tar -zxvf jdk-8u211-linux-x64.tar.gz -C /usr/local/ $vi /etc/profile #Java Env export JAVA_HOME=/usr/local/jdk1.8.0_211/ export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar; export PATH=$PATH:$JAVA_HOME/bin #更新环境变量 $source /etc/profile $java -version #验证安装 java version "1.8.0_211" Java(TM) SE Runtime Environment (build 1.8.0_211-b12) Java HoTSPot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode) 步骤3.建立oracle应用账号与组 /usr/sbin/groupadd -g 60001 oinstall /usr/sbin/groupadd -g 60002 dba /usr/sbin/groupadd -g 60003 oper /usr/sbin/groupadd -g 60004 backupdba /usr/sbin/groupadd -g 60005 dgdba /usr/sbin/groupadd -g 60006 kmdba /usr/sbin/useradd -u 61002 -g oinstall -G dba,backupdba,dgdba,kmdba,oper oracle #oracle用户 passwd oracle #设置weiyiegeek@2019 步骤4.使用oracle提供的环境配置工具(速度感人,还是手动调整内核参数) # wget http://public-yum.oracle.com/public-yum-ol7.repo -O /etc/yum.repos.d/public-yum-ol7.repo # wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol7 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle # yum install oracle-rdbms-server-11gR2-preinstall -y 步骤5.建立数据库目录安装 #oracle安装的目录&授权 #/opt/oracle/product/11.2.0.1/db1 家目录 #/opt/oracle/oraInventor 数据库创建及使用过程中的日志目录 #/opt/oracle/oradata 数据目录 #/opt/oracle/tmp 临时目录 #/opt/oracle/recovery_data //数据恢复目录 mkdir -pv /opt/oracle/product/11.2.0.1/db1 /var/oracle /opt/oracle/{oraInventor,oradata,tmp} chown -R oracle:oinstall /var/oracle /opt/oracle/ chmod -R 755 /var/oracle /opt/oracle/ chmod a+wr /opt/oracle/tmp #配置oracle系统配置文件&授权 cat >> /etc/oraInst.loc <<EOF inventory_loc=/opt/oracle/oraInventor inst_group=oinstall EOF chown oracle:oinstall /etc/oraInst.loc && chmod 664 /etc/oraInst.loc #步骤6.调整内核参数(优化配置)- 新手建议不要动实际 $vi /etc/security/limits.conf #ORACLE SETTING grid soft nproc 16384 grid hard nproc 16384 grid soft nofile 65536 grid hard nofile 65536 grid soft stack 32768 grid hard stack 32768 oracle soft nproc 16384 oracle hard nproc 16384 oracle soft nofile 65536 oracle hard nofile 65536 oracle soft stack 32768 oracle hard stack 32768 oracle hard memlock 6000000 oracle soft memlock 6000000 echo "session required pam_limits.so" >> /etc/pam.d/login echo "session required /lib64/security/pam_limits.so" >> /etc/pam.d/login cat /etc/pam.d/login #查看上面即可 vi /etc/sysctl.conf #ORACLE SETTING fs.aio-max-nr = 1048576 fs.file-max = 6815744 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 kernel.panic_on_oops = 1 kernel.shmmax = 2033164800 #kernel.shmmax 参数设置为物理内存的一半 kernel.shmall = 1228800 kernel.shmmni = 4096 vm.nr_hugepages = 1000 #注意实际环境值,系统8G内存的大内存页参数(2500) $sysctl -p #执行查看保存后生效命令 #步骤7.查看内核配置文件是否存在和grup配置 (实际上可以跳过) $cat /sys/kernel/mm/transparent_hugepage/defrag [always] madvise never $cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never $vi /etc/rc.d/rc.local #更改自启判断文件是否存在 if test -f /sys/kernel/mm/transparent_hugepage/enabled;then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi $chmod +x /etc/rc.d/rc.local $vi /etc/default/grub numa=off #(在auto rhgb quiet 后面加上numa=off) GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet" numa=off 配置用户环境: 步骤8.配置用户环境shell $su - oracle #使用Oracle用户登陆: $vi .bash_profile umask 022 export PS1="[`whoami`@`hostname`:"'$PWD]$' export LANG=en_US # +--------------------------+ # | SETUP ORACLE ENVIRONMENT | # +--------------------------+ export TMP=/opt/oracle/tmp export TMPDIR=$TMP ORACLE_HOSTNAME=oracle11 ORACLE_BASE=/opt/oracle ORACLE_HOME=$ORACLE_BASE/product/11.2.0.1/db1 ORACLE_SID=orcl ORACLE_TERM=xterm; PATH=.:$PATH:$HOME/.local/bin:$HOME/bin:$ORACLE_HOME/bin NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS" NLS_LANG=AMERICAN_AMERICA.ZHS16GBK #THREADS_FLAG=native; export THREADS_FLAG export ORACLE_HOSTNAME ORACLE_BASE ORACLE_HOME ORACLE_SID ORACLE_TERM PATH NLS_DATE_FORMAT NLS_LANG $source .bash_profile #执行生效 #配置环境变量shell(Root权限下执行) $vi /etc/profile #增加下面行: if [ $USER = "oracle" ] || [ $USER = "grid" ] ; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi umask 022 fi $source /etc/profile 下载Oracle的Linux版本(并进行解压): 下载地址:https://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html #采用迅雷下载也可以 http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.zip http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_2of2.zip #建VM立共享然后解压oracle安装程序到自定目录 chown -R oracle:oinstall /home/oracle/ #防止权限问题 unzip linux.x64_11gR2_database_1of2.zip -q -d /home/oracle/ unzip linux.x64_11gR2_database_2of2.zip -q -d /home/oracle/ 配置db_install.rsp(自动安装应答文件) #将解压目录中的reponse进行备份 cp -r /home/oracle/database/response/ /home/oracle mkdir -pv /opt/oracle/product/11.2.0.1/db1 /var/oracle /opt/oracle/oraInventor /opt/oracle/oradata /opt/oracle/tmp #配置安装响应文件db_install.rsp文件 这里配置参数先下载到本地 用记事本根据自己情况修改 在上传过去 $cat /home/oracle/response/db_install.rsp | grep -E -v "^#" | tr -s ' ' oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0 oracle.install.option=INSTALL_DB_AND_CONFIG #机器名称和组 ORACLE_HOSTNAME=oracle11 UNIX_GROUP_NAME=oinstall #前面设置的目录 INVENTORY_LOCATION=/opt/oracle/oraInventor SELECTED_LANGUAGES=zh_CN,en #oracle环境基础设置 ORACLE_HOME=/opt/oracle/product/11.2.0.1/db1 ORACLE_BASE=/opt/oracle/product/ oracle.install.db.InstallEdition=EE oracle.install.db.isCustomInstall=true oracle.install.db.customComponents=oracle.server:11.2.0.1.0,oracle.sysman.ccr:10.2.7.0.0,oracle.xdk:11.2.0.1.0,oracle.rdbms.oci:11.2.0.1.0,oracle.network:11.2.0.1.0,oracle.network.listener:11.2.0.1.0,oracle.rdbms:11.2.0.1.0,oracle.options:11.2.0.1.0,oracle.rdbms.partitioning:11.2.0.1.0,oracle.oraolap:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,oracle.rdbms.dv:11.2.0.1.0,orcle.rdbms.lbac:11.2.0.1.0,oracle.rdbms.rat:11.2.0.1.0 oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=oinstall oracle.install.db.CLUSTER_nodeS= oracle.install.db.config.starterdb.type=GENERAL_PURPOSE #服务名 oracle.install.db.config.starterdb.globalDBName=orcl.db1 #实例名称 oracle.install.db.config.starterdb.SID=orcl oracle.install.db.config.starterdb.characterSet=AL32UTF8 oracle.install.db.config.starterdb.memoryOption=true #根据系统实际情况设置我这里分2G给他 oracle.install.db.config.starterdb.memoryLimit=1880 oracle.install.db.config.starterdb.installExampleSchemas=true oracle.install.db.config.starterdb.enableSecuritySettings=true #密码默认设置不设置安装时会提示 oracle.install.db.config.starterdb.password.ALL=Oracle@123 oracle.install.db.config.starterdb.password.SYS= oracle.install.db.config.starterdb.password.SYSTEM= oracle.install.db.config.starterdb.password.SYSMAN= oracle.install.db.config.starterdb.password.DBSNMP= oracle.install.db.config.starterdb.control=DB_CONTROL oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL= oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false oracle.install.db.config.starterdb.dbcontrol.emailAddress= oracle.install.db.config.starterdb.dbcontrol.SMTPServer= oracle.install.db.config.starterdb.automatedBackup.enable=false oracle.install.db.config.starterdb.automatedBackup.osuid= oracle.install.db.config.starterdb.automatedBackup.ospwd= oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/opt/oracle/oradata oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation= oracle.install.db.config.asm.diskGroup= oracle.install.db.config.asm.ASMSNMPPassword= MYORACLESUPPORT_USERNAME= MYORACLESUPPORT_PASSWORD= SECURITY_UPDATES_VIA_MYORACLESUPPORT= DECLINE_SECURITY_UPDATES=true PROXY_HOST= PROXY_PORT= PROXY_USER= PROXY_PWD= 静默安装数据库 #安装 Oracle11g /home/oracle/database/runInstaller -silent -ignorePrereq -responseFile /home/oracle/db_install.rsp # Starting Oracle Universal Installer... # Checking Temp space: must be greater than 120 MB. Actual 53477 MB Passed # Checking swap space: must be greater than 150 MB. Actual 2047 MB Passed # Preparing to launch Oracle Universal Installer from /opt/oracle/tmp/OraInstall2019-06-21_01-28-41AM. # Preparing to launch Oracle Universal Installer from /opt/oracle/tmp/OraInstall2019-06-21_01-37-00AM. Please wait ...[oracle@oracle11:/home/oracle]$You can find the log of this install session at: /opt/oracle/oraInventor/logs/installActions2019-06-21_01-37-00AM.log #新建立一个终端查看安装信息: $tail -f /opt/oracle/oraInventor/logs/installActions2019-06-21_01-37-00AM.log # INFO: Installation in progress # INFO: Extracting files to '/opt/oracle/product/11.2.0.1/db1'. # INFO: Extracting files to '/opt/oracle/product/11.2.0.1/db1'. # INFO: Performing fastcopy operations based on the information in the file 'oracle.server_EE_exp_1.xml'. # INFO: Performing fastcopy operations based on the information in the file 'racfiles.jar'. # INFO: Performing fastcopy operations based on the information in the file 'oracle.server_EE_dirs.lst'. # INFO: Performing fastcopy operations based on the information in the file 'oracle.server_EE_filemap.jar'. # INFO: Performing fastcopy operations based on the information in the file 'oracle.server_EE_1.xml'. # INFO: Performing fastcopy operations based on the information in the file 'setperms1.sh'. # INFO: Number of threads for fast copy :1 # INFO: Validating state <finish> # WARNING: Validation disabled for the state finish # INFO: Completed validating state <finish> # INFO: Terminating all background operations # INFO: Terminated all background operations # INFO: Successfully executed the flow in SILENT mode # INFO: Finding the most appropriate exit status for the current application # INFO: Exit Status is 3 # INFO: Shutdown Oracle Database 11g Release 2 Installer #代表安装成功 # INFO: Unloading Setup Driver WeiyiGeek.开始复制安装#安装完成后切换到root账号 /opt/oracle/product/11.2.0.1/db1/root.sh #Check /opt/oracle/product/11.2.0.1/db1/install/root_oracle11_2019-06-21_20-58-13.log for the output of root script #配置监听启动(他会默认启动) #/app/oracle/product/11.2.0.1/db1/bin/netca /silent /responseFile /home/oracle/response/netca.rsp WeiyiGeek.配置监听2.配置流程数据库的启动&关闭 [root] #修改oracle服务启动配置 vi /etc/oratab orcl:/opt/oracle/product/11.2.0.1/db1:Y # //把“N”改成“Y” [oracle] #切换用户 #启动oracle #因为修改了/etc/oratab N->y 所以启动服务也会同时启动实例的情况不,会同时启动实例 #sqlplus sqlplus登录会提示 an idle instance --> startup启动实 #(1)启动/停止监听 $lsnrctl start $lsnrctl stop #停止监听x #(2)通过dbstart 启动此实例,监听器 # dbstart $ORACLE_HOME # #关闭( oracle的进程关闭,监听器也停止) # dbshut $ORACLE_HOME #(3)切换用户[#oracle] #启动oracle #因为修改了/etc/oratab N->y 所以启动服务也会同时启动实例的情况不,会同时启动实例 #sqlplus sqlplus登录会提示 an idle instance --> startup启动实 $lsnrctl status #查看oracle状态 # LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-JUN-2019 19:49:15 # Copyright (c) 1991, 2009, 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.1.0 - Production # Start Date 21-JUN-2019 19:24:44 # Uptime 0 days 0 hr. 24 min. 30 sec # Trace Level off # Security ON: Local OS Authentication # SNMP OFF # Listener Parameter File /opt/oracle/product/11.2.0.1/db1/network/admin/listener.ora # Listener Log File /opt/oracle/diag/tnslsnr/oracle11/listener/alert/log.xml # Listening Endpoints Summary... # (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) # (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11)(PORT=1521))) # Services Summary... # Service "orcl.db1" has 1 instance(s). # Instance "orcl", status READY(这才是正常状态), has 1 handler(s) for this service... # Service "orclXDB.db1" has 1 instance(s). # Instance "orcl", status READY, has 1 handler(s) for this service... # The command completed successfully #初次登录配置 $ sqlplus /nolog $ sqlplus / as sysdba #是系统用户登录的方式 # 进入系统管理用户 SQL> conn / as sysdba Connected to an idle instance. # 启动oracle实例 SQL> startup; #用户查看 SQL> show user # 实例状态查看 SQL> select HOST_NAME,INSTANCE_NAME,DATABASE_STATUS,STATUS from v$instance; #服务名称查看 SQL> show parameter service_names # 停止oracle实例 SQL> shutdown immediate #远程连接oracle $sqlplus sys/passoracle@192.168.138.136:1521/orcl.db1 as sysdba #orcl.db1是服务名,而orcl是SID $sqlplus sys/passoracle#123@127.0.0.1:1521/orcl.db1 as sysdba $sqlplus sys/passoracle#123@oracle:1521/orcl.db1 as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 21 21:04:53 2019 > conn sys/passoracle@192.168.100.131:1521/ORCL.LAN as sysdba #登录后才能使用 show parameter service_names WeiyiGeek.登录成功采用navicat进行登录: WeiyiGeek.建库实例: #静默dbca建库编辑应答文件(与上面的db_install对应): [oracle@oracle ~]$ vi /etc/dbca.rsp GDBNAME="orcl.oracle" SID="orcl" SYSPASSWORD = "oracle" SYSTEMPASSWORD = "oracle" CHARACTERSET="AL32UTF8" NATIONALCHARACTERSET="UTF8" # 执行至此完成数据库实例的创建。 [oracle@oracle ~]$ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/etc/dbca.rsp #删除实例: [oracle@oracle ~]$ dbca -silent -deleteDatabase -sourcedb orcl #配置监听程序: # [oracle@oracle bin]$ /opt/oracle/product/11.2.0.1/db1/bin/netca /silent /responseFile /home/oracle/etc/netca.rsp 防火墙调整 #防火墙 放行1521端口 firewall-cmd --zone=public --add-port=1521/tcp --permanent #重新加载防火墙规则 firewall-cmd --reload 开机自启 描述:默认以安装ORACLE环境作为演示CentOS7 #Step1.查看ORACLE_HOME是否设置并且编辑/etc/oratab文件设置服务自动启动 echo $ORACLE_HOME /u01/app/oracle/product/11.2.0/dbhome_1 #dbca建库时都会自动创建/etc/oratab文件 #将orcl:/u01/app/oracle/product/11.2.0/dbhome_1:N #将N转换成为Y #Step2.编辑dbstart 数据库自带启动脚本 vim +80 /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart #编辑 dbstart 将 ORACLE_HOME_LISTNER=$1 修改成 ORACLE_HOME_LISTNER=$ORACLE_HOME 前提是$ORACLE_HOME环境设置正确 #Step3.将下数据库自启动命令放入/etc/rc.d/rc.local中 $vim /etc/rc.d/rc.local su oracle -lc "/opt/oracle/product/11.2.0.1/db1/bin/lsnrctl start" su oracle -lc /opt/oracle/product/11.2.0.1/db1/bin/dbstart #Step4.查看数据库是否处于open状态 select status from v$instance Ubuntu 安装环境说明: 1.安装流程2.配置流程–0x01 docker 安装https://hub.docker.com/r/jaspeen/oracle-11g1.安装流程Step 1.Docker 环境得安装(老朋友了不多说)sudo apt-get update sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io (source https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository)Step 2.下载oracle 11g安装包于解压到# Download Oracle installation files https://www.oracle.com/database/technologies/112010-linx8664soft.html unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip ls /data/ └─oracleinstall └─database ├─doc ├─install ├─response ├─rpm ├─sshsetup ├─stage ├─runInstaller └─welcome.html database linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip Step 3.jaspeen/oracle-11g 镜像拉取# 搜索符合条件的镜像 sudo docker search oracle # 镜像拉取 sudo docker pull jaspeen/oracle-11g # 注意点 /data/ 挂载到 install 而 镜像的 安装目录是 /install/database/ 所以不能指定 /data/database sudo docker run -d --privileged --name oracle11g -p 1521:1521 -v /data/:/install -v /app/dpdump:/opt/oracle/dpdump jaspeen/oracle-11g Step 4.查看容器运行以及安装情况于进度# 注意:如果日志长时间没有更新检查docker是否已经死掉, 只有日志里有 100% complete 打印,则代表oracle安装成功 /data# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6f79aada2f12 jaspeen/oracle-11g "/assets/entrypoint.…" 8 minutes ago Up 8 minutes 0.0.0.0:1521->1521/tcp, 8080/tcp oracle11g # 方式1 docker exec -it oracle11g cat /opt/oracle/oraInventory/logs/installActions2021-01-25_08-26-07AM.log # 方式2 docker logs --tail 100 -f oracle11g Step 5.进入容器中连接本地的Oracle查看是否正常sudo docker ps -a Get container [YOUR_CONTAINER_ID] sudo docker exec -it [YOUR_CONTAINER_ID] /bin/bash $ su - oracle $ lsnrctl status # 查看监听 # LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 26-JAN-2021 04:30:32 # Copyright (c) 1991, 2009, Oracle. All rights reserved. # Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) # STATUS of the LISTENER # ------------------------ # Alias LISTENER # Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production # Start Date 25-JAN-2021 08:31:20 # Uptime 0 days 19 hr. 59 min. 11 sec # Trace Level off # Security ON: Local OS Authentication # SNMP OFF # Listener Log File /opt/oracle/app/diag/tnslsnr/6f79aada2f12/listener/alert/log.xml # Listening Endpoints Summary... # (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=6f79aada2f12)(PORT=1521))) # Services Summary... # Service "orcl" has 1 instance(s). # Instance "orcl", status READY, has 1 handler(s) for this service... # Service "orclXDB" has 1 instance(s). # Instance "orcl", status READY, has 1 handler(s) for this service... # The command completed successfully $ sqlplus / as sysdba # 进入数据库 # 启停数据库 # 停止:shutdown immediate # 启动:startup Step 6.使用它例如:连接SqlDeveloper (port 1521, SID orcl),或使用sqlplus# Database located in `/opt/oracle` folder Port: 1521 SID: orcl # 缺省OS用户和DB用户 # OS users: root/install oracle/install # DB users: SYS/oracle Step 7.用户创建和用户解锁# 创建于授权 CREATE USER usedata IDENTIFIED BY weiyigeekcomCn; grant connect, resource to usedata; # 用户解锁 alter user usedata acount unlock; -- 这种方式指定表空间物理文件位置 -- datafile 'F:APPQIUCHANGJINORADATAORCLQCJ_TABLESPACE.dbf' -- 大小 500M,每次 5M 自动增大,最大不限制 create tablespace XK_TABLESPACE datafile 'XK_TABLESPACE.dbf' size 500M autoextend on next 5M maxsize unlimited; CREATE USER xk IDENTIFIED BY Testweiyigeekxk.2021 default tablespace XK_TABLESPACE quota unlimited on XK_TABLESPACE; grant connect,resource to xk; grant unlimited tablespace to xk; Step 8.由于版权问题拉取下来的 docker 镜像是不包含任何版本的 oracle 的,故在启动 docker 后,需要创建一个自己的镜像以备使用;# 提交镜像 docker commit oracle11g oracle11g-installed # 设置一个别名方便进入后续进入容器中 alias oracle='docker exec -it oracle11g bash' 2.配置流程1) 进入容器shell使用内置sqlplus进行连接,并解锁用户外部客户端连接测试 Tips: 可以采用sqlplus或者使用dataGrip连接oracle数据库 docker exec -it oracle11g /bin/bash su - oracle sqlplus / as sysdba SQL> alter user scott account unlock; User altered. SQL> commit; Commit complete. SQL> conn scott/tiger # 首次连接需更改密码 ERROR: ORA-28001: the password has expired Changing password for scott New password: Retype new password: Password changed Connected. WeiyiGeek.外部连接3.入坑出坑1) 为什么要解压成上面的目录结构我们先来看看jaspeen/oracle-11g镜像提供的安装脚本 描述: 从脚本里可以看到它会读取/install/database目录,如果不存在会给出提示Installation files not found. Unzip installation files into mounted(/install) folder; #!/usr/bin/env bash set -e source /assets/colorecho trap "echo_red '******* ERROR: Something went wrong.'; exit 1" SIGTERM trap "echo_red '******* Caught SIGINT signal. Stopping...'; exit 2" SIGINT if [ ! -d "/install/database" ]; then echo_red "Installation files not found. Unzip installation files into mounted(/install) folder" exit 1 fi echo_yellow "Installing Oracle Database 11g" su oracle -c "/install/database/runInstaller -silent -ignorePrereq -waitforcompletion -responseFile /assets/db_install.rsp" /opt/oracle/oraInventory/orainstRoot.sh /opt/oracle/app/product/11.2.0/dbhome_1/root.sh 例如: 挂在文件到容器指定目录 (d:/oracleinstall/database 对应容器 /install/database) docker run --privileged --name oracle11g -p 1521:1521 -v d:/oracleinstall:/install jaspeen/oracle-11g 0x02 入坑记下面罗列出新手安装Oracle数据库时候最需要注意的几个文件可以帮助您排查错误: #dbstart日志 /opt/oracle/product/11.2.0.1/db1/startup.log #监听器日志 /opt/oracle/diag/tnslsnr/oracle11/listener/alert/log.xml 1.问题解决 #netca配置静默监听出错 java.lang.UnsatisfiedLinkError: /db/app/oracle/product/11.2.0/lib/libnjni11.so: libclntsh.so.11.1 #解决方法: cp $ORACLE_HOME/inventory/Scripts/ext/lib/libclntsh.so.11.1 $ORACLE_HOME/lib/ _问题2:安装oracle11g时候错误信息INFO: Oracle Net Services configuration failed. The exit code is 1 _ INFO: Oracle Net Configuration Assistant failed. INFO: Oracle Net Configuration Assistant failed. #解决方法: 查看/etc/hosts中是否添加该主机的机器名和回环地址 [oracle@oracle bin]$ ./sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Sat May 25 00:20:45 2019 Copyright (c) 1982, 2009, Oracle. All rights reserved. ERROR: ORA-12162: TNS:net service name is incorrectly specified # 解决方式: 1、系统当前的ORACLE_HOME和ORACLE_SID环境变量 2、给出ORACLE_SID,重新尝试登录: 报错信息:oracle 11g ORA-12514:TNS:监听程序当前无法识别连接描述符中请求的服务 解决方法1: vim /opt/oracle/product/11.2.0.1/db1/network/admin/listener.ora #添加SID名称 SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = orcl.db1) (ORACLE_HOME = /opt/oracle/product/11.2.0.1/db1/) (SID_NAME = orcl) ) ) #HOST指定后需要查看对应的/etc/hosts中IP是否正确 LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = oracle11)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /opt/oracle 解决方法二: 登录数据库: $sqlplus / as sysdba 显示服务名: SQL>show parameter service_names 强制注册服务: SQL>alter system register; 查看监听状态: $lsnrctl status 解决方法三:排查客户端连接的服务名称是否正确 TestOracle = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST=WeiyiGeek-Oracle)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl.db1) #关键点 ) ) 解决方法四:查看oracle11是否与主机IP绑定正确查看/etc/hosts [oracle@WeiyiGeek-oracle ~]$ cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.172.240 WeiyiGeek-Oracle 实例化status UNKNOWN 没有正常的启动成功,需要dbstart后才分配内存 /opt/oracle/product/11.2.0.1/db1/bin/dbstart $ORACLE_HOME 加载全部内容