实验名称:搭建Oracle数据库
实验要求:完成搭建Oracle数据库
实验环境:Centos7虚拟机一台,IP地址192.168.22.100,4G运行,交换分区需要是物理内存的1.5–2倍,磁盘空间不少于10G,Oracle安装就需要5G
实验步骤:
(一),配置实验环境
1,先查看条件是否满足
在这里插入图片描述2,配置实验所需域名

[root@localhost ~]# vim /etc/hostname                      设置主机名(需要遵循FQDN且不可随意更改)
odb.sevenwin.org
[root@localhost ~]# vim /etc/hosts                           设置本地host缓存文件

测试看是否能ping通
在这里插入图片描述3,上传并更改java1.8的java环境

[root@localhost ~]# java -version                        查看Java环境
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
[root@localhost ~]# rz                            上传java1.8的安装包

[root@localhost ~]# tar -zxf jdk-8u161-linux-x64.tar.gz     解包
[root@localhost ~]# mv jdk1.8.0_161/ /usr/local/jdk1.8    移动并更名
[root@localhost ~]# vim /etc/profile                    配置全局环境变量
export JAVA_HOME=/usr/local/jdk1.8
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
[root@localhost ~]# source /etc/profile                 立即生效
[root@localhost ~]# java -version                     查看Java环境是否配置成功
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

,4,配置网络源yum,下载所需依赖程序

[root@localhost ~]# cd /etc/yum.repos.d/               切换工作目录
[root@localhost yum.repos.d]# ls
CentOS-Base.repo       CentOS-Media.repo
CentOS-CR.repo         CentOS-Sources.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo
CentOS-fasttrack.repo
[root@localhost yum.repos.d]# mkdir yum.repos.d.bak    创建yum备份目录
[root@localhost yum.repos.d]# mv C* yum.repos.d.bak/    移动进行备份
[root@localhost yum.repos.d]# ls
yum.repos.d.bak
[root@localhost yum.repos.d]# vim yum.repo           配置网络源yum
#CentOS-Base.repo
#
#unless you are manually picking other mirrors.
#remarked out baseurl= line instead.
#
#

[base]
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@localhost yum.repos.d]# yum clean all         清除yum缓存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up everything
[root@localhost yum.repos.d]# yum makecache        加载数据
[root@localhost yum.repos.d]# yum -y install yum-utils     安装yum扩展包
[root@localhost ~]# yum -y install  gcc gcc-c++ glibc glibc-common glibc-devel glibcheaders ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXext libXtst libX11 libXau libXi make sysstat unixODBC unixODBC-devel zlib-devel compat-libcap1 compat-libstdc++-33    安装依赖包

5,用户环境配置

[root@localhost ~]# groupadd oinstall     创建组
[root@localhost ~]# groupadd dba        创建组
[root@localhost ~]# groupadd oper        创建组
[root@localhost ~]# useradd -g oinstall -G dba,oper oracle   创建Oracle用户并指定基本组和附加组
[root@localhost ~]# passwd oracle           设置Oracle用户密码
Changing password for user oracle.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully
[root@localhost ~]# vim /etc/sysctl.conf 
6,设置内核参数
[root@localhost ~]# vim /etc/sysctl.conf 
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500

7,设置Oracle的shell限制

[root@localhost ~]# vim /etc/security/limits.conf 
oracle soft nofile 1024                     打开文件数量的软限制
oracle hard nofile 65536                    打开文件数量的硬限制
oracle soft nproc 2047                      工作可以用到的进程数量(软限制)
oracle hard nproc 16384                    工作可以用到的进程数量(硬限制)
oracle soft stack 10240                      堆栈占用的缓冲空间大小(软限制)
oracle hard stack 32768                      堆栈占用的缓冲空间大小(硬限制)
8,设置Oracle的shell启动脚本
[root@localhost ~]# vim /home/oracle/.bashrc 
export TMP=/tmp                         定义一个tmp的变量根下的tmp临时目录
export ORACLE_HOSTNAME=odb.sevenwin.org   定义了Oracle的主机名
export ORACLE_UNQNAME=orcl                定义Oracle的实例名
export ORACLE_BASE=/opt/app/oracle            Oracle的基目录
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1   Oracle的家目录(根据自己实际情况进行调整)
export ORACLE_SID=orcl                      SID和实例名一致
export PATH=/usr/sbin:$PATH:$ORACLE_HOME/bin   追加路径
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;    定义库的路径
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;    定义类库的路径
alias cdob='cd $ORACLE_BASE'                  定义命令的别名,cd到Oracle的基目录
alias cdoh='cd $ORACLE_HOME'                 定义命令的别名cd到Oracle的家目录
alias tns='cd $ORACLE_HOME/network/admin'      定义命令的别名,cd到网络配置admin的主目录
alias envo='env | grep ORACLE'                    定义命令的别名,显示跟Oracle有关的环境变量
umask 022                                    umask值设置为022
envo

(二),安装Oracle
1,安装环境配置

[root@localhost ~]# mkdir /opt/app/oracle/product/12.2.0/db_1 -p   创建Oracle安装路径
[root@localhost ~]# chown -R  oracle:oinstall /opt/app/            授权
[root@localhost ~]# vim /etc/selinux/config                       设置沙河安全等级
SELINUX=permissive

重启虚拟机,并以root身份登录
在这里插入图片描述

[oracle@odb ~]$ rz                上传安装包

[oracle@odb ~]$ ls
Desktop    Downloads                    Music     Public     Videos
Documents  linuxx64_12201_database.zip  Pictures  Templates
[oracle@odb ~]$ unzip linuxx64_12201_database.zip     解包
[oracle@odb ~]$ ls
database  Documents  linuxx64_12201_database.zip  Pictures  Templates
Desktop   Downloads  Music                        Public    Videos
[oracle@odb ~]$ cd database/
[oracle@odb database]$ ls
install  response  rpm  runInstaller  sshsetup  stage  welcome.html
[oracle@odb database]$ ./runInstaller                进行安装

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述需要打开一个新的终端,以root身份运行这两个脚本


[oracle@odb database]$ su - root     切换到root用户来运行脚本
Password: 
Last login: Sun Jan 17 09:19:40 CST 2021 from 192.168.22.1 on pts/2
ABRT has detected 1 problem(s). For more info run: abrt-cli list --since 1610847561
[root@odb ~]# /opt/app/oraInventory/orainstRoot.sh       运行第一个脚本
Changing permissions of /opt/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /opt/app/oraInventory to oinstall.
The execution of the script is complete.
[root@odb ~]# /opt/app/oracle/product/12.2.0/db_1/root.sh    运行第二个脚本
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /opt/app/oracle/product/12.2.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]:   回车
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Do you want to setup Oracle Trace File Analyzer (TFA) now ? yes|[no] :   回车

Oracle Trace File Analyzer (TFA - User Mode) is available at :
    /opt/app/oracle/product/12.2.0/db_1/suptools/tfa/release/tfa_home/bin/tfactl

OR

Oracle Trace File Analyzer (TFA - Daemon Mode) can be installed by running this script :  回车
    /opt/app/oracle/product/12.2.0/db_1/suptools/tfa/release/tfa_home/install/roottfa.sh

在这里插入图片描述

[root@odb ~]# whoami                 查看当前用户
root
[root@odb ~]# vim /etc/oratab            进行更改
orcl:/opt/app/oracle/product/12.2.0/db_1:Y    把N改成y,(Oracle运行数据库引擎的时候要运行orcl) 
2,启动、停止、以及查看数据库状态命令

[oracle@odb ~]$ lsnrctl stauus 查看监控以及数据库状态
在这里插入图片描述

[oracle@odb ~]$ lsnrctl start             启动监控

在这里插入图片描述

[oracle@odb ~]$ lsnrctl stop            停止监控

在这里插入图片描述

[oracle@odb ~]$ sqlplus sys AS sysdba    以DBA的身份登录Oracle

在这里插入图片描述
【至此,Oracle数据库搭建完成】

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐