Docker installation configuration starts Oracle11g container to solve ORA-12541: TNS: no listener to connect to third-party client

For installation under Windows, please refer to my article: The whole process of installing oracle11g database under win11&win7

1. Download and start

Premise : You need to install and configure docker ( set mirror source , configure Aliyun acceleration ), etc., you can refer to my installation and configuration of docker and docker-compose based on CentOS7 .

Docker container related operations can refer to my basic Docker container operation start-stop-restart

//查看docker启动状态,若为active(running)则已经启动。
systemctl status docker

//执行start命令启动docker
systemctl start docker

1.1 Download Oracle11g image

Since https://hub.docker.com/ where the official mirror is located cannot be opened, use the Ali mirror to download the Oracle11g mirror.
oracle11g is the Names of the oracle11g image.

docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

insert image description here
Note: The mirror image is relatively large, nearly 7 G.

//查看下载好的镜像
docker images

insert image description here

1.2. Start the container

//默认启动容器的方式(第一次推荐这种)
docker run -d -it -p 1521:1521 --name oracle11g --restart=always registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g


//持久化启动的方式
docker run -d -it -p 1521:1521 --name oracle --restart=always --mount source=oracle_vol,target=/home/oracle/app/oracle/oradata registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

Here we use the default way to start the container, next time you can directly use the docker start command to start the container .
insert image description here

//docker start 容器名(Names)或完整的容器ID(CONTAINER ID)或容器ID(CONTAINER ID)的前4位
//620b是djc-RabbitMQ容器ID(CONTAINER ID)的前4位
//执行完命令,再执行docker ps(查看当前启动的容器)查看是否启动成功。
docker start djc-RabbitMQ
docker start 620bd670d79b
docker start 620b
或
docker start -i 以交互模式启动
docker start -t 以附加进程模式启动

insert image description here

//查看所有容器(包含已经启动和未启动的容器)
//此处第一个就是我们刚刚启动的oracle11g,oracle11g是该oracle11g镜像的Names。
docke ps -a

insert image description here

//查看启动的线程
netstat -tulnp

insert image description here

1.3 Configure container environment

//1-进入容器
docker exec -it oracle11g bash

//2-切换到 root 用户 su root,该Oracle11g的容器密码默认为helowin。
su root

//3-配置环境变量
将环境变量配置在 /home/oracle/.bashrc 中,这样无需再去执行创建软链接的命令 ln -s $ORACLE_HOME/bin/sqlplus /usr/bin


insert image description here

//4-执行 vi /home/oracle/.bashrc ,按i或insert键编辑.bashrc文件,在文件最后加入下列内容
//编辑好
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH

编辑好,按ECS退出i(insert)模式,:wq保存并退出。  

//5-刷新环境变量,使之生效。
source /home/oracle/.bashrc 

insert image description here
insert image description here

//6-查看编辑完成的.bashrc文件
cat .basjrc

insert image description here

2. Login

2.1 Configure the firewall

防火墙要允许 1521 端口,外部的数据库管理工具才能连的上
# 打开防火墙
systemctl start firewalld

# 查询端口状态
firewall-cmd --query-port=1521/tcp

# 永久性开放端口
firewall-cmd --permanent --zone=public --add-port=1521/tcp

# 重启防火墙
firewall-cmd --reload
firewall-cmd --query-port=1521/tcp

insert image description here

or

//直接关闭防火墙 
systecmctl stop firewalld

//开机禁用防火墙
systecmctl disable firewalld

insert image description here

2.2 Commands

//1-解决sqlplus /nolog 的 Permission denied 问题 【进入oracle容器之前执行】
setenforce 0

//2-进入容器
docker exec -it oracle11g bash


//3-将当前用户切换到Oracle
//如果直接以root用户执行下一步sqlplus /nolog,会报错Permission denied
su - oracle


//4-进入Oracle命令行
//如果直接以root用户执行sqlplus /nolog,会报错Permission denied
sqlplus /nolog




//5-使用 “操作系统认证” 的方式
//如果这里直接以默认的root用户登录,会报登录失败ORA-12456:TNS:permission denied
//这里会报Connected to an idle instance,表示需要使用startup命令启动数据库
conn / as sysdba



//6-启动数据库  后续补充
startup;

//7-select instance_name
select instance_name from v$instance;

//8-show user
show user;

2.3 Why switch to the oracle user

4-Enter the Oracle command line-if you directly execute sqlplus /nolog as the root user, an error will be reported Permission denied

insert image description here

5- Use the "operating system authentication" method - if you log in directly as the default root user here, you will report a login failure ORA-12456: TNS: permission denied
insert image description here
su - oracle
insert image description here
insert image description here

2.4 Screenshots of the whole login process

insert image description here

3. Connect to the third-party client Navicat Premium 16

3.1 ORA-12541: TNS: no listener

 ORA-12541:TNS: 无监听程序

insert image description here

原因:lsnrctl 没有启动,导致监听器没有启动。
//查看lsnrctl 状态
lsnrctl status

//reload
lsnrctl reload

//启动lsnrctl,启动监听器。
lsnrctl start


//关闭lsnrctl,关闭监听器
lsnrctl stop

insert image description here
insert image description here
Start lsnrctl, start the listener
insert image description here
After starting the listener, check the lsnrctl status again :
insert image description here

3.2 Connect Navicat Premium 16 again

insert image description here

insert image description here

3.3 Test SELECT * FROM EMP

insert image description here

3.5 Screenshots of the whole process of connecting to the third-party client Navicat Premium 16

insert image description here
insert image description here

3.6 Shut down the Oracle11g container

Basic operation of Docker container start-stop-restart

//1-exit退出Oracle11g容器内
eixt

//2-停止Oracle11g容器并在60s内保存其状态
docker stop -t=60 oracle11g

//3-查看正在运行的容器-若无,则表示Oracle11g容器已经成功关闭
docker ps

insert image description here
insert image description here

4. References

Start-stop-restart the basic operation of the Docker container
Install oracle
cannot restore segment prot after reloc: Permission denied
The most complete steps in the history of docker installation oracle11g (with pictures and texts)
The most complete steps in the history of docker installation oracle11g (with pictures and texts)

Guess you like

Origin blog.csdn.net/qyfx123456/article/details/132009672