Rumah  >  Artikel  >  Tutorial sistem  >  Master menerangkan cara memasang oracle dan mysql dengan Docker di bawah unbuntu

Master menerangkan cara memasang oracle dan mysql dengan Docker di bawah unbuntu

WBOY
WBOYasal
2024-07-17 12:03:18711semak imbas

Master menerangkan cara memasang oracle dan mysql dengan Docker di bawah unbuntu

1. Pasang docker

Kemas kini sumber apt dan pasang sijil CA, arahannya adalah seperti berikut:

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates

Tambah kunci GPG:

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Buka fail /etc/apt/sources.list.d/docker.list (buat satu jika ia tidak wujud)

Tambah deb sumber https://apt.dockerproject.org/repo ubuntu-xenial main dan simpan

Pilih sumber yang berbeza mengikut versi sistem:

On Ubuntu Precise 12.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-precise main

On Ubuntu Trusty 14.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-trusty main

Ubuntu Wily 15.10
deb https://apt.dockerproject.org/repo ubuntu-wily main

Ubuntu Xenial 16.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-xenial main

Pilih Ubuntu Xenial 16.04 (LTS) di sini

Kemas kini sesuai dan pastikan sumber Docker adalah betul

sudo apt-get update
apt-cache policy docker-engine

Pemasangan:

sudo apt-get install docker-engine

Sokong pengguna biasa untuk menggunakan docker

Kumpulan docker pemasangan ppa telah dibuat, jika tidak sudo groupadd docker akan membinanya

sudo gpasswd -a ${USER} docker
sudo service docker restart
sudo chmod a+rw /var/run/docker.sock

carian docker : Cari cermin oracle dari Docker Hub

$ docker search oracle
NAME                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
oraclelinux                         Oracle Linux is an open-source operating s...   398       [OK]       
frolvlad/alpine-oraclejdk8          The smallest Docker image with OracleJDK 8...   269                  [OK]
alexeiled/docker-oracle-xe-11g      This is a working (hopefully) Oracle XE 11...   221                  [OK]
sath89/oracle-12c                   Oracle Standard Edition 12c Release 1 with...   214                  [OK]
sath89/oracle-xe-11g                Oracle xe 11g with database files mount su...   133                  [OK]
isuper/java-oracle                  This repository contains all java releases...   55                   [OK]
jaspeen/oracle-11g                  Docker image for Oracle 11g database            54                   [OK]
oracle/glassfish                    GlassFish Java EE Application Server on Or...   30                   [OK]
oracle/openjdk                      Docker images containing OpenJDK Oracle Linux   25                   [OK]
airdock/oracle-jdk                  Docker Image for Oracle Java SDK (8 and 7)...   23                   [OK]
ingensi/oracle-jdk                  Official Oracle JDK installed on centos.        21                   [OK]
cogniteev/oracle-java               Oracle JDK 6, 7, 8, and 9 based on Ubuntu ...   20                   [OK]
wnameless/oracle-xe-11g             Dockerfile of Oracle Database Express Edit...   16                   [OK]
n3ziniuka5/ubuntu-oracle-jdk        Ubuntu with Oracle JDK. Check tags for ver...   14                   [OK]
oracle/nosql                        Oracle NoSQL on a Docker Image with Oracle...   13                   [OK]
collinestes/docker-node-oracle      A container with Node.js/Oracle instant cl...   9                    [OK]
andreptb/oracle-java                Debian Jessie based image with Oracle JDK ...   7                    [OK]
sgrio/java-oracle                   Docker images of Java 7/8 provided by Orac...   7                    [OK]
openweb/oracle-tomcat               A fork off of Official tomcat image with O...   7                    [OK]
flurdy/oracle-java7                 Base image containing Oracle's Java 7 JDK       5                    [OK]
davidcaste/debian-oracle-java       Oracle Java 8 (and 7) over Debian Jessie        3                    [OK]
teradatalabs/centos6-java8-oracle   Docker image of CentOS 6 with Oracle JDK 8...   3                    
spansari/nodejs-oracledb            nodejs with oracledb installed globally on...   1                    
publicisworldwide/oracle-core       This is the core image based on Oracle Lin...   1                    [OK]
sigma/nimbus-lock-oracle                                                            0                    [OK]
2. Tarik oracle-oracle-xe-11g ke tempatan
docker pull sath89/oracle-xe-11g
Paparan selepas

tarik:

$ docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
hello-world            latest              f2a91732366c        8 days ago          1.85kB
sath89/oracle-xe-11g   latest              04851454491b        3 months ago        792MB

Buat dan mulakan contoh oracle:

docker run -d  -p 9090:8080 -p 1521:1521 -v /home/${USER}/oracle/data:/u01/app/oracle sath89/oracle-xe-11g

Di mana -p 9090:8080 ialah port pengurusan web Oracle Application Express 8080 dalam imej docker yang dipetakan ke port 9090 tempatan:

http://localhost:9090/apex
workspace: INTERNAL
user: ADMIN
password: oracle

-p 1521: 1521 ialah port perkhidmatan oracle Jika anda tidak mahu menggunakan 1521 untuk port tempatan, anda boleh mengubah suai 1521 yang pertama.

3. Pasang pelanggan segera oracle instantclient:

Rujuk secara khusus pada catatan blog sebelum ini untuk mencipta versi diperkemas klien Oracle dan persekitaran kompilasi pro*c di bawah Ubuntu

Saya tidak menemui perisian pelanggan segera 11g di tapak web rasmi Oracle yang saya letakkan di Tianyi Cloud (kod akses: 6540)

SID oracle konfigurasi tempatan:

Tambahkan /opt/oracle/product/network/admin/tnsnames.ora (berkaitan dengan laluan pelanggan segera):

XE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = xe)
    )
  )

Anda juga boleh pergi terus tanpa mengkonfigurasi:

sqlplus sys/oracle@127.0.0.1:1521/xe as sysdba
sqlplus system/oracle@//localhost:1521/xe

Setelah dikonfigurasikan, anda boleh mengaksesnya seperti ini

sqlplus sys/oracle@xe as sysdba
sqlplus system/oracle@xe

sys dan sistem ialah dua pengguna lalai, satu dengan autoriti sysdba dan satu lagi dengan autoriti sistem. Kata laluan awal ialah oracle

Adalah disyorkan untuk menukar kata laluan sys sejurus selepas pemasangan berjaya

sqlplus sys/oracle@xe as sysdba
SQL>alter user sys identified by your-passwd

Buat ruang meja

SQL> create tablespace myts  datafile  '/u01/app/oracle/oradata/XE/myts.dbf'  size 100M autoextend on next 5M maxsize 400M;

Ubah suai ruang jadual lalai sistem

SQL>  alter database default tablespace MYTS;
SQL>  select a.property_name, a.property_value from database_properties a where a.property_name like '%DEFAULT%';

PROPERTY_NAME
--------------------------------------------------------------------------------
PROPERTY_VALUE
--------------------------------------------------------------------------------
DEFAULT_TEMP_TABLESPACE
TEMP

DEFAULT_PERMANENT_TABLESPACE
MYTS

DEFAULT_EDITION
ORA$BASE

.......

Buat pengguna, benarkan dan nyatakan ruang jadual

SQL> create user scott identified by tiger;
SQL> grant connect, resource to scott;
SQL> alter user scott default tablespace myts;

Skrip penciptaan jadual myscott.sql:

--------------------------------------------------------
--  File created - 星期六-六月-14-2014   
--------------------------------------------------------
--------------------------------------------------------
--  DDL for Table BONUS
--------------------------------------------------------

  CREATE TABLE "BONUS" 
   (	"ENAME" VARCHAR2(10), 
	"JOB" VARCHAR2(9), 
	"SAL" NUMBER, 
	"COMM" NUMBER
   ) ;
--------------------------------------------------------
--  DDL for Table DEPT
--------------------------------------------------------

  CREATE TABLE "DEPT" 
   (	"DEPTNO" NUMBER(2,0), 
	"DNAME" VARCHAR2(14), 
	"LOC" VARCHAR2(13)
   ) ;
--------------------------------------------------------
--  DDL for Table EMP
--------------------------------------------------------

  CREATE TABLE "EMP" 
   (	"EMPNO" NUMBER(4,0), 
	"ENAME" VARCHAR2(10), 
	"JOB" VARCHAR2(9), 
	"MGR" NUMBER(4,0), 
	"HIREDATE" DATE, 
	"SAL" NUMBER(7,2), 
	"COMM" NUMBER(7,2), 
	"DEPTNO" NUMBER(2,0)
   ) ;
--------------------------------------------------------
--  DDL for Table SALGRADE
--------------------------------------------------------

  CREATE TABLE "SALGRADE" 
   (	"GRADE" NUMBER, 
	"LOSAL" NUMBER, 
	"HISAL" NUMBER
   ) ;

---------------------------------------------------
--   DATA FOR TABLE BONUS
--   FILTER = none used
---------------------------------------------------
REM INSERTING into BONUS

---------------------------------------------------
--   END DATA FOR TABLE BONUS
---------------------------------------------------


---------------------------------------------------
--   DATA FOR TABLE DEPT
--   FILTER = none used
---------------------------------------------------
REM INSERTING into DEPT
Insert into DEPT (DEPTNO,DNAME,LOC) values (10,'ACCOUNTING','NEW YORK');
Insert into DEPT (DEPTNO,DNAME,LOC) values (20,'RESEARCH','DALLAS');
Insert into DEPT (DEPTNO,DNAME,LOC) values (30,'SALES','CHICAGO');
Insert into DEPT (DEPTNO,DNAME,LOC) values (40,'OPERATIONS','BOSTON');

---------------------------------------------------
--   END DATA FOR TABLE DEPT
---------------------------------------------------


---------------------------------------------------
--   DATA FOR TABLE EMP
--   FILTER = none used
---------------------------------------------------
REM INSERTING into EMP
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7369,'SMITH','CLERK',7902,to_timestamp('17-12月-80 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),800,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7499,'ALLEN','SALESMAN',7698,to_timestamp('20-2月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1600,300,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7521,'WARD','SALESMAN',7698,to_timestamp('22-2月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1250,500,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7566,'JONES','MANAGER',7839,to_timestamp('02-4月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2975,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7654,'MARTIN','SALESMAN',7698,to_timestamp('28-9月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1250,1400,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7698,'BLAKE','MANAGER',7839,to_timestamp('01-5月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2850,null,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7782,'CLARK','MANAGER',7839,to_timestamp('09-6月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2450,null,10);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7788,'SCOTT','ANALYST',7566,to_timestamp('19-4月 -87 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),3000,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7839,'KING','PRESIDENT',null,to_timestamp('17-11月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),5000,null,10);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7844,'TURNER','SALESMAN',7698,to_timestamp('08-9月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1500,0,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7876,'ADAMS','CLERK',7788,to_timestamp('23-5月 -87 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1100,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7900,'JAMES','CLERK',7698,to_timestamp('03-12月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),950,null,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7902,'FORD','ANALYST',7566,to_timestamp('03-12月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),3000,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7934,'MILLER','CLERK',7782,to_timestamp('23-1月 -82 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1300,null,10);

---------------------------------------------------
--   END DATA FOR TABLE EMP
---------------------------------------------------


---------------------------------------------------
--   DATA FOR TABLE SALGRADE
--   FILTER = none used
---------------------------------------------------
REM INSERTING into SALGRADE
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (1,700,1200);
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (2,1201,1400);
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (3,1401,2000);
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (4,2001,3000);
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (5,3001,9999);

---------------------------------------------------
--   END DATA FOR TABLE SALGRADE
---------------------------------------------------


--------------------------------------------------------
--  DDL for Index PK_EMP
--------------------------------------------------------

  CREATE UNIQUE INDEX "PK_EMP" ON "EMP" ("EMPNO") 
  ;
--------------------------------------------------------
--  DDL for Index PK_DEPT
--------------------------------------------------------

  CREATE UNIQUE INDEX "PK_DEPT" ON "DEPT" ("DEPTNO") 
  ;



--------------------------------------------------------
--  Constraints for Table EMP
--------------------------------------------------------

  ALTER TABLE "EMP" ADD CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") ENABLE;

--------------------------------------------------------
--  Constraints for Table DEPT
--------------------------------------------------------

  ALTER TABLE "DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") ENABLE;

--------------------------------------------------------
--  Ref Constraints for Table EMP
--------------------------------------------------------

  ALTER TABLE "EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
	  REFERENCES "DEPT" ("DEPTNO") ENABLE;

Laksanakan skrip dan pertanyaan:

SQL> @myscott.sql
SQL> select * from EMP;
4. Jalankan sqlplus terus dalam docker tanpa memasang klien:
$ docker ps -a
CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS                                            NAMES
3c6a2c2761fb        sath89/oracle-xe-11g   "/entrypoint.sh "   2 minutes ago       Up About a minute   0.0.0.0:1521->1521/tcp, 0.0.0.0:9090->8080/tcp   dreamy_pasteur
$ docker exec -it 3c6a2c2761fb /bin/bash
root@3c6a2c2761fb:/# su oracle
oracle@3c6a2c2761fb:/$ $ORACLE_HOME/bin/sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Wed Nov 29 13:40:15 2017

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> quit
Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
oracle@8e1a86793036:/$ $ORACLE_HOME/bin/sqlplus scott/tiger

SQL*Plus: Release 11.2.0.2.0 Production on Wed Nov 29 13:40:24 2017

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> select * from emp;

     EMPNO ENAME      JOB	       MGR HIREDATE	    SAL       COMM
---------- ---------- --------- ---------- --------- ---------- ----------
    DEPTNO
----------
      7369 SMITH      CLERK	      7902 17-DEC-80	    800
	20

......
5. Berhenti dan mulakan instance oracle dalam bekas
$ docker stop 3c6a2c2761fb
$ docker start 3c6a2c2761fb

Untuk memudahkan pengurusan seterusnya, anda boleh menambah alias dalam .bashrc

alias orastartdock='docker start 3c6a2c2761fb'
alias orastopdock='docker stop 3c6a2c2761fb'

Juga boleh didapati di

docker run -d --name=oracle1 -p 9090:8080 -p 1521:1521 -v /home/${USER}/oracle/data:/u01/app/oracle sath89/oracle-xe-11g

Nyatakan nama kontena oracle1, yang boleh digunakan untuk menghentikan dan memulakan contoh dengan cara berikut:

$ docker stop oracle1
$ docker start oracle1

Daripada menggunakan ID CONTAINER yang dijana secara rawak oleh docker

Anda boleh menggunakan ~$ docker rename oracle1 ora1 untuk menamakan semula nama container docker, gunakan ~$docker rm container name atau container ID untuk memadam, atau anda boleh menggunakan arahan berikut untuk memadam kesemuanya

docker rm $(docker ps -aq)

Sudah tentu, ia tidak boleh dipadam apabila ia dimulakan.

Selagi laluan storan port dan data ditukar, satu imej boleh mencipta berbilang kejadian oracle, seperti:

docker run -d --name=oracle2 -p 9092:8080 -p 1522:1521 -v /home/${USER}/oracle/data2:/u01/app/oracle sath89/oracle-xe-11g


docker run -d --name=ora3 -p 9093:8080 -p 1523:1521 -v /home/${USER}/oracle/data3:/u01/app/oracle sath89/oracle-12c

Dengan cara ini anda boleh menyediakan berbilang persekitaran oracle dengan mudah.

6. Jalankan mysql
$docker pull mysql:5.7.20

$docker run -p 3307:3306 --name mysql5.7.20 -v /home/${USER}/mysqldata/mysql5.7.20/conf:/etc/mysql/conf.d -v /home/${USER}/mysqldata/mysql5.7.20/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.20

$ docker exec -it mysql5.7.20 bash

# mysql -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH  GRANT OPTION; 
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> FLUSH   PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
root@657aaa1203f4:/# exit
exit
~$ mysql -h 127.0.0.1   -P3307 -u root -123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement
mysql> quit
 

Anda mesti menambah -h 127.0.0.1 di sini, jika tidak, walaupun port -P3307 ditentukan, ia masih akan disambungkan ke mysql mesin hos dan bukannya satu bekas docker Ini kerana port 3306 ditentukan dalam .my.cf pada mesin hos.

Atas ialah kandungan terperinci Master menerangkan cara memasang oracle dan mysql dengan Docker di bawah unbuntu. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn