Installing Oracle database (alicloud source) with docker under virtual machine

Time:2020-4-7

Environmental preparation

Docker environment

Install Docker

Create a new virtual machine without installing the docker environment. Execute the following command to install it:
yum install docker -y
yum updateUpgrade everything that can be upgraded on the machine to the latest version~
After installationdocker --versionTo view the installed version of docker
Docker version 1.13.1, build cccb291/1.13.1

Start Docker

rootUser execute command:
systemctl start docker.service
systemctl enable docker.service
There may be an error that the installation succeeds but the docker cannot be started. For the solution, please refer to the following link:

https://blog.csdn.net/qq_1365…

Oracle image installation

Here are two different ways of mirroring. To put it simply:
The first is:The image pulled down is a script. In this case, you need to upload the Oracle installation file on your own machine. The actual principle is to install Oracle silently in the script mode, but you need to instruct others to write it for you. After the installation, you can pack it into a container and use it.
Second species:What you pull down is a complete database, including the operating system and so on, which is equivalent to someone else setting up an environment for you to use, such as the image provided by Alibaba cloud.

This article chooses the second method, which is to use the image provided by Alibaba cloud

Mirror pull

Execute command:
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
Wait for download. The image size is 2.9g. It will take some time after decompressing 6.7g.

Start Oracle and automatically start the image

In particular, the image actually provides an environment in which Oracle can run, that is, the software has been installed, but for the data files in our database, this cannot be generated in the image, because if the image is generated in the image, once there is a problem with the image, our data files will be lost, which will be irreversible Influence.

First, we use this command to enter the image and do some basic configuration:
1. Start the image
docker run -p 1521:1521 --name oracle_11g -d --restart=always registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

2. Start service
docker start oracle_11g

3. Enter the console to set user information
docker exec -it oracle_11g bash

4. Switch to root, because it is the image provided by alicloud, root needs to log in with the password of “hello”

5. Modify the configuration file
vi /etc/profile
Append at the end
export ORACLE\_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome\_2
export ORACLE\_SID=helowin
export PATH=$ORACLE\_HOME/bin:$PATH

6. Make the configuration effective and establish sqlplus soft connection
source /etc/profile
ln -s $ORACLE\_HOME/bin/sqlplus /usr/bin

7. Switch Oracle users and execute sqlplus / as SYSDBA
You can see the database that can enter the image.
Installing Oracle database (alicloud source) with docker under virtual machine

Observe the image system with DF – H command

Installing Oracle database (alicloud source) with docker under virtual machine

As you can see, the directory structure of the virtual machine is completely different from that of our virtual machine, which means that the image is packaged with the operating system

One problem

From the above observation, we can find a problem:
In the image, you can see the data file of this database in the/home/oracle/app/oracle/oradataNext, but it’s only 20g, and it’s 14g, and it’s almost gone. If I add data files based on this image, the disk is not enough, and it seems that we haven’t established a relationship with our own virtual machine yet, how can I keep my data files locally?

Effect to be achieved

We want to achieve an effect, that is, the software uses the image, and the data file uses our existing local, that is, the data is persisted in the local, not affected by the image.

Adjust the start command above to:
docker run -p 1521:1521 --name oracle_11g -d -v /opt/ora_data:/home/oracle/app/oracle/oradata/mydata --restart=always registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

Here’s a major addition-vParameters, as follows:
-v /opt/ora_data:/home/oracle/app/oracle/oradata/mydata
In front of the colon is the real path of our local virtual machine, which is the 10g I drew for the data file
Behind the colon is the path of the saved data file after Oracle is set up in the image. I added amydataFolder, used to store the new data files we created.
The command means to map the local path to the path in the image, and save the data file to the path of the virtual machine when it is actually generated.

Stop mirroring

Changing the startup mode involves stopping the running image first
Execute command:
docker stop oracle_11g
docker rm oracle_11g

Execute the adjusted start command

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

View the path of the data file in the image

As you can see, the image is generatedmydataFolder
Installing Oracle database (alicloud source) with docker under virtual machine

Practical testing

Connect with PLSQL

Modify the tnsname.ora file of the native Oracle client, and add a new connection:
Note here that the service_name should be filled in from Alibaba cloud
Installing Oracle database (alicloud source) with docker under virtual machine

Establish test account

Log in to the image Oracle user and execute the command:

create user lijian identified by lijian;
grant dba to lijian;  ---DBA
Grant create session to Lijian; -- login permission, which enables the user to be called by other programs, such as PLSQL
Grant unlimited tablespace to Lijian; -- permission to use tablespace
Grant create table, create view, create trigger, create sequence, create procedure, create type to Lijian; -- permission to create table, view, trigger, sequence, stored procedure, type.

Create a new tablespace

1. Input the path of the virtual machine directly to see if it can:
create tablespace JLLT_DM logging datafile '/opt/ora_data/jllt_dm01.dbf' size 100M;
Error found:
Installing Oracle database (alicloud source) with docker under virtual machine

2. Enter the mydata path we set in the image:
create tablespace JLLT_DM logging datafile '/home/oracle/app/oracle/oradata/mydata/jllt_dm01.dbf' size 100M;
You can see the normal setup.
Installing Oracle database (alicloud source) with docker under virtual machine

3. Take a look at the disk space again and execute DF:
As you can see,mydataAfter a data file is added with the command to create a table space under the file, a file system will be automatically divided without occupying the previous directory in the image.
Installing Oracle database (alicloud source) with docker under virtual machine

4. Take a look at the corresponding virtual machine/ora_dataCatalog:
Installing Oracle database (alicloud source) with docker under virtual machine

As you can see,/opt/ora_dataNow we have the data files we have created, so that we can achieve the goal we want to achieve.
Installing Oracle database (alicloud source) with docker under virtual machine

Compare with traditional installation

Although it’s a long time, you will find that it’s very simple to install Oracle with docker in a few steps.

  1. Pull mirror image
  2. Waiting for download
  3. Modify configuration, set save data file to mount local disk
  4. Start, start.

There are many things written before, including Yum installation dependency, Linux system parameter setting, configuration monitoring, database building and so on, which are not seen in this article, because these things are provided in docker image and can be used directly.
Still want to embrace new technology as far as possible, of course, the actual production environment if there is no Internet, it is more sad..

Recommended Today

PHP Basics – String Array Operations

In our daily work, we often need to deal with some strings or arrays. Today, we have time to sort them out String operation <?php //String truncation $str = ‘Hello World!’ Substr ($STR, 0,5); // return ‘hello’ //Chinese string truncation $STR = ‘Hello, Shenzhen’; $result = mb_ Substr ($STR, 0,2); // Hello //First occurrence of […]