这篇文章上次修改于 765 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

写在前面

我是腾讯云2h2g小机器,装了一大堆东西想跑个oracle数据库玩玩,搜了下还是docker安方便。

第一步pull镜像

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

大小大概6个g,我服务器总共才40g着不住啊。

第二步创建容器

我看其他教程都是挂载的容器数据卷,我在home下新建了oracle目录
所以我的docker启动命令是

docker run -d --restart=always -p 1521:1521 --name oracle_11g  -v  /home/oracle/app:/opt/oracle/app -v  /home/oracle/data:/opt/oracle/dpdump  registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

-p映射端口 --restart=always 让它能够自动启动

进入容器

创建完成后就要进入容器里面操作了。

docker exec -it oracle_11g bash

进入后获取root权限,输入

su root

输入密码helowin
[root@a2d20fe3b8d6 /]#
这样就成功获取root了

接下来设置环境变量

vi /etc/profile
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2

export ORACLE_SID=helowin

export PATH=$ORACLE_HOME/bin:$PATH

使变量生效,接着切换为 oracle用户就可以正常使用了

source /etc/profile

创建软链接

ln -s $ORACLE_HOME/bin/sqlplus /usr/bin

切换到Oracle用户

su - oracle

登录sqlplus并修改sys、system用户密码

sqlplus /nolog
conn /as sysdba
alter user system identified by oracle;
#修改system用户账号密码;
alter user sys identified by oracle;
#修改sy用户账号密码;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;

create user 用户名 identified by 密码;
#创建新用户
grant connect,resource,dba to my_account;
#给予权限
#修改密码规则策略为密码永不过期;
exit
#退出

查看一下oracle实例状态

lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 15-MAR-2022
17:11:33

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
15-MAR-2022 16:17:12 Uptime 0 days 0 hr. 54 min. 21
sec Trace Level off Security ON: Local
OS Authentication SNMP OFF Listener Parameter
File
/home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/listener.ora
Listener Log File
/home/oracle/app/oracle/diag/tnslsnr/a2d20fe3b8d6/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=a2d20fe3b8d6)(PORT=1521)))
Services Summary... Service "helowin" has 1 instance(s). Instance
"helowin", status READY, has 1 handler(s) for this service... Service
"helowinXDB" has 1 instance(s). Instance "helowin", status READY,
has 1 handler(s) for this service... The command completed
successfully

接下来就可以链接了

oraclenavicat.png