Mac基于docker-compose 安装 oracle
编写 docker-compose.yaml
oracle:
image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
restart: always #如果docker容器由于一些问题挂掉的化,docker-composer会自动把容器给启动起来
container_name: oracle #启动之后容器的名称
volumes:
- ./oracle/data/oracle-11g/data:/u01/app/oracle
ports:
- 1521:1521
执行compose
因为上面是 oracle 所以下面是 oracle 如果上面是 oracle_11,下面也要改为 oracle_11
docker-compose up -d oracle
启动成功后如图所示
到容器中修改东西
luwei@luweideMacBook-Pro-2 pkg-config % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
29f0b85f1284 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g "/bin/sh -c '/home/o…" 2 hours ago Up 2 hours 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp oracle
89c169b8bd14 nginx:alpine "/docker-entrypoint.…" 7 days ago Up 7 days (healthy) 0.0.0.0:81->80/tcp, :::81->80/tcp, 0.0.0.0:444->443/tcp, :::444->443/tcp nginx
e0e4fa4bf177 lnmp_php72 "entrypoint php-fpm" 7 days ago Up 7 days (healthy) 9000-9001/tcp php72
a1ddf67627cd lnmp_php56 "entrypoint php-fpm" 7 days ago Up 7 days (healthy) 9000/tcp php56
324aa6c8b071 lnmp_php71 "entrypoint php-fpm" 7 days ago Up 7 days (healthy) 9000/tcp php71
4fd5d2ce7612 mongo:4.4.0 "docker-entrypoint.s…" 7 days ago Up 7 days 0.0.0.0:27018->27017/tcp, :::27018->27017/tcp mongo4.4
f212f81e0546 redis:4-alpine "docker-entrypoint.s…" 7 days ago Up 7 days (healthy) 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis
e42962aa16c8 mysql:5.6 "docker-entrypoint.s…" 7 days ago Up 44 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp mysql
luwei@luweideMacBook-Pro-2 pkg-config %
进入oracle容器
luwei@luweideMacBook-Pro-2 pkg-config % docker exec -it 29f0b85f1284 /bin/bash
[oracle@29f0b85f1284 /]$
查看配置 tnsnames.ora
[oracle@29f0b85f1284 /]$ find / -name tnsnames.ora /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/samples/tnsnames.ora /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/tnsnames.ora
查看配置信息
[oracle@29f0b85f1284 /]$ cat /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_HELOWIN =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
HELOWIN =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = helowin)
)
)
[oracle@29f0b85f1284 /]$
- 可以看到如下配置,后面要用的
(SERVICE_NAME = helowin) HOST = localhost) (PORT = 1521
切换oracle数据库的root用户下,密码 helowin
[oracle@29f0b85f1284 /]$ su root
Password:
[root@29f0b85f1284 /]#
修改profile的配置文件,打开profile文件,在末尾添加配置。
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
刷新文件
source /etc/profile
创建软链
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
切换回 orcle
su - oracle
登录sqlplus,修改sys、system用户密码,创建用户
//1.登录
sqlplus /nolog
//2.连接
conn /as sysdba
//3.修改密码
alter user system identified by system;
alter user sys identified by sys;
//4.创建用户
create user dev identified by dev;
//5.并给用户赋予权限
grant connect,resource,dba to dev;
执行效果如下
[oracle@29f0b85f1284 ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Oct 27 14:17:17 2021
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> alter user system identified by system;
User altered.
SQL> alter user sys identified by sys;
User altered.
SQL> create user dev identified by dev;
User created.
SQL> grant connect,resource,dba to dev;
Grant succeeded.
SQL>
SQL>