docker下部署oracle11g
1. 创建安装目录
mkdir -p /install/database
2. 下载
将oracle11g下载地址(https://www.oracle.com/database/technologies/112010-linx8664soft.html)安装上传并解压到/install/database
unzip linux.x64_11gR2_database_1of2.zip -d /install/database
unzip linux.x64_11gR2_database_2of2.zip -d /install/database
#拉取oracle镜像
docker pull jaspeen/oracle-11g
3. 创建oracle容器
docker run --privileged --name oracle11g -p 1521:1521 -v /install/database:/install jaspeen/oracle-11g
注:创建容器过程:报错Checking swap space: 0 MB available, 150 MB required. Failed
解决方法:
1、检查 Swap 空间在设置 Swap 文件之前,有必要先检查一下系统里有没有既存的 Swap 文件。运行以下命令:swapon -s
如果返回的信息概要是空的,则表示 Swap 文件不存在。
2、检查文件系统在设置 Swap 文件之前,同样有必要检查一下文件系统,看看是否有足够的硬盘空间来设置 Swap 。运行以下命令:df -hal
3、创建并允许 Swap 文件下面使用 dd 命令来创建 Swap 文件。检查返回的信息,还剩余足够的硬盘空间即可。
dd if=/dev/zero of=/swapfile bs=1024 count=512k,参数解读:if=文件名:输入文件名,缺省为标准输入。即指定源文件。< if=input file >of=文件名:输出文件名,缺省为标准输出。即指定目的文件。< of=output file >bs=bytes:同时设置读入/输出的块大小为bytes个字节count=blocks:仅拷贝blocks个块,块大小等于bs指定的字节数。
4. 格式化并激活
Swap 文件上面已经创建好 Swap 文件,还需要格式化后才能使用。运行命令:
mkswap /swapfile
激活 Swap ,运行命令:
swapon /swapfile
以上步骤做完,再次运行命令:
swapon -s
你会发现返回的信息概要:
Filename Type Size Used Priority
/swapfile file 524284 0 -1
如果要机器重启的时候自动挂载 Swap ,那么还需要修改 fstab 配置。用 vim 打开 /etc/fstab 文件,在其最后添加如下一行:
/swapfile swap swap defaults 0 0
最后,赋予 Swap 文件适当的权限:
chown root:root /swapfile
chmod 0600 /swapfile
以上步骤做完,再次运行命令:
swapon -s
[root@mail database]# free -m
total used free shared buff/cache available
Mem: 7824 2326 4654 16 843 5178
Swap: 511 0 511
5. 继续执行oracle容器创建
docker run --privileged --name oracle11g -p 1521:1521 -v /install/database:/install jaspeen/oracle-11g
Database is not installed. Installing...
Installing Oracle Database 11g
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB. Actual 47303 MB Passed
Checking swap space: must be greater than 150 MB. Actual 1023 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-04-17_08-14-23AM. Please wait ...
You can find the log of this install session at:
/opt/oracle/oraInventory/logs/installActions2019-04-17_08-14-23AM.log
注:这个安装过程会很漫长,日志也很多,这里只提供部分。注意到日志里有 100% complete 打印,代表oracle安装成功
6. 切换用户
切换到oracle用户,然后连接到sql控制台
[root@7f53f07c93e5 /]# su - oracle
Last login: Wed Apr 17 08:29:31 UTC 2019
[oracle@7f53f07c93e5 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Apr 17 09:29:49 2019
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
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.
SQL>
忘记SYS用户,或者是SYSTEM用户的密码
CONN SYS/PASS_WORD AS SYSDBA; --如果是忘记SYSTEM用户的密码,可以用SYS用户登录。
ALTER USER SYSTEM IDENTIFIED BY "newpassword";
CONN SYSTEM/PASS_WORD AS SYSDBA; --如果是忘记SYS用户的密码,可以用SYSTEM用户登录。
ALTER USER SYS IDENTIFIED BY "newpassword";