Written in the book before
Because the local MAC space is not enough (ha ha, promote my learning), so I want to build a cloud Oracle environment.
I have written the Windows building before, but the 11G (project requirements) has not been installed before, so I simply changed the server to Linux, and prepare to use the Docker way to build.
The overall steps
- Ali Cloud application Linux server, here my CentOS 7.4.
- Install the docker.
- Download the Oracle image and install it.
- Import data (using DMP, creating tablespaces, users, etc.).
Docker profile
Docker in simple terms, is a virtual machine, you want what application, directly input commands to install, do not need to directly delete, sandbox idiot. The official logo is the whale carrying the goods, here I mainly used to install Oracle, mysql, Tomcat and so on. The logo is as follows:
Without further ado, let’s get started.
Install Docker
For Linux servers, installing Docker is very simple, but requires a CentOS kernel version older than 3.10. Use uname -r to view this. The diagram below:
For detailed installation steps, please refer to this blog post blog.csdn.net/qq_36892341… , write very clearly, no longer tautology, if you do not understand, you can leave a message.
2. Download the Oracle image and install it
Using the docker search to search for an oracle oracle version, I choose is registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g here, This is an Oracle 11G version of Ali Cloud, the need for other versions of small partners can choose.
Run the following command to pull the mirror
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
Copy the code
After the pull, you can use Docker Images to view the existing image
As you can see, REPOSITORY is the IMAGE name, TAG is the version number, and IMAGE ID is the IMAGE number.
To start the Oracle service, run the following command: -p Map port 8080 of the container to port 8080 of the host (-p host port: container port)
docker run --name registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g -p 1521:1521
Copy the code
Then use Docker PS to see the container at launch.
As you can see here, the Oracle service has been started (ff94A17F84A7)
Import data, users, and tablespace creation
3.1. Import DMP data files
First, you need to copy DMP (data files exported from other libraries, including data + table structures, etc.) data from the native Oracle container
Docker cp/local file address container ID:/ container file storage address
docker cp /home/oracle/data_20181104.dmp ff94a17f84a7:/home/cloudera
Copy the code
[Note: Container ID (here mine is FF94A17F84A7) please change to your own]
Create tablespaces and users
Use the following command to enter the Docker container
docker exec -it ff94a17f84a7 bash
Copy the code
Log in as a database administrator
Sqlplus: command not found, don’t worry, use su – oracle to switch to oracle user, then sqlplus, then sys/sys as sysdba to log in, as shown in the figure below, login succeeded!
Create table space
There are four small steps:
Create temporary tablespace temp;
create temporary tablespace TEST_DBF_TEMP tempfile '/home/oracle/data/TEST_DBF_TEMP.dbf' size 50m autoextend on next 50m maxsize 2048m;Copy the code
2, create formal tablespace:
create tablespace TEST_DBF datafile '/home/oracle/data/TEST_DBF.dbf' size 50M autoextend on next 50m maxsize 2048m;
Copy the code
Create user and specify tablespace:
create user TEST identified by "123" default tablespace TEST_DBF temporary tablespace TEST_DBF_TEMP;
Copy the code
4. User authorization:
grant create session,connect,resource,dba to TEST;
Copy the code
3.3. Import DMP files:
imp TEST/123 file = /data_20181210.dmp full=y;
Copy the code
Wait for the import to complete.
PS: Ali Cloud remember to cloud server console open database corresponding port can be connected to the Internet.
Configuration rules
Select clone one, and enter the host port corresponding to Oracle in Docker PS:
With a picture of success:
Bingo!
FAQ (updated from time to time) :
The Oracle service is disconnected & suspended and restarted
Oracle failed to connect today. Possible causes:
- SELECT name FROM V $database; SELECT name FROM V $database; View the SID.
- The Oracle database in the Dokcer container is suspended.
- Other unknown reasons (e.g., the computer is not connected to the Internet, the disk space is full, the user name or password is wrong, etc.).
I immediately went to the server and docker PS to query the online container, but found that Oracle was still there.
So docker exec-it FF94a17F84a7 bash goes into the container.
LSNRCTL start Starts the listener, as shown in the figure below, indicating that the listener has been started.
Sqlplus /nolog enter, conn/as sysdba administrator connect, and then startup, as shown in the following figure.
Bingo!
After restarting the container, the port changes, set the fixed port
- View the container to be modified and remember the container ID
docker ps -a
2. Stop the container
docker stop xxx
- Example Modify the port mapping configuration file of a container
vim /var/lib/docker/containers/{container_id}/hostconfig.json
"PortBindings" : {" 80 / TCP ": [{" HostIp" : ""," HostPort ":" 8080 "/ / hosting IP}]}.Copy the code
4. Restart the Docker service
service docker restart
5. Start the container
docker start xxx
Error response from daemon: Cannot XX container
This error is really weird, I put a New Year’s day back, what can not operate?
The solution
Restart the Docker service
systemctl restart docker
Copy the code
Restarting the container succeeded