12

Centos7 安装 Oracle 数据库

 3 years ago
source link: https://blog.cugxuan.cn/2020/12/16/Database/centos-install-oracle/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

因为之前做的项目使用的是 oracle 数据库,版本为 11G R212C
但是有需要自己这边也部署一下,找了一些资料,在 centos 上安装比较方便,最后安装了 Oracle Database Express Edition (XE) Release 11.2.0.2.0 (11gR2) 这个版本,记录一下

Centos7 安装 Oracle 数据库

  • 服务器一台,这里使用的是 Centos7(网上看的 Ubuntu 的资料都很麻烦,为此我们搞了一台服务器,重置成了 Centos)
  • oracle 数据库的安装包,点击跳转资料下载
// 在服务器下载好安装包
$ wget https://gonelist.cugxuan.cn/d/app/linux/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
// 解压安装
$ unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
$ cd Disk1/
$ ls
oracle-xe-11.2.0-1.0.x86_64.rpm response upgrade
// 此时已经看到 oracle-xe-11.2.0-1.0.x86_64.rpm 在 Disk1 文件夹中
// 安装 oracle 数据库
$ rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm

执行完操作之后一般会看到报错,说至少需要 2G 的 swap 空间

This system does not meet the minimum requirements for swap space. Based on
the amount of physical memory available on the system, Oracle Database 11g
Express Edition requires 2048 MB of swap space. This system has 0 MB
of swap space. Configure more swap space on the system and retry the
installation.

设置交换空间

// 创建 swap 文件夹
$ mkdir /usr/swap
$ ls /usr
bin etc games include lib lib64 libexec local sbin share src swap tmp
// 可以看到已经有 swap 文件夹了
$ cd /usr/swap/
$ ll
总用量 0
// 此时总用量为 0
// 执行下面的操作,设置 swap 为 3G
$ dd if=/dev/zero of=swapfile bs=1G count=3
记录了3+0 的读入
记录了3+0 的写出
3221225472字节(3.2 GB)已复制,23.7552 秒,136 MB/秒
// 执行 ls 看到有 swapfile 了
$ ls
swapfile
$ mkswap /usr/swap/swapfile
正在设置交换空间版本 1,大小 = 3145724 KiB
无标签,UUID=93eeb4ad-a26e-47c2-9aa9-6e68e3dd27f6
$ swapon /usr/swap/swapfile
swapon: /usr/swap/swapfile:不安全的权限 0644,建议使用 0600。
// 因为有安全提示,所以设置一下 swapfile 的权限
$ chmod 600 swapfile
// 设置 fstab 让其永久生效
$ vi /etc/fstab
// 在最后面加一行
/usr/swap/swapfile swap swap defaults 0 0
// 重启 centos
$ reboot
// 重启之后,可以看到 swap 已经生效
$ free
total used free shared buff/cache available
Mem: 1882000 637968 166216 454060 1077816 618592
Swap: 3145724 26880 3118844

解决了 swap 空间的要求,继续安装即可

// 因为已经重启,所以重新进入 Disk1
$ cd Disk1/
$ rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm
正在升级/安装...
1:oracle-xe-11.2.0-1.0 ################################# [100%]
Executing post-install steps...
You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.
$ /etc/init.d/oracle-xe configure
// 按照默认提示安装即可
// 中间会配置 HTTP,oracle 端口
// SYS 和 SYSTEM 的密码
// 是否开机启动

会自动建立一个名为 oracle 的用户,目录在 /u01/app/oracle。
会建立 dba 组,oracle 用户属于这个组。
会自动生成一个数据库实例,名为 XE,在 /u01/app/oracle/product/11.2.0/xe/dbs/spfileXE.ora

此时需要配置环境变量

$ vi /etc/profile
// 在最后面加入以下内容
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=XE
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`

然后退出重新登陆之后就可以使用 sqlplus 命令连接数据库了

记录一下创建用户的命令,用户名为 USERNAME,密码为 PASSWORD,按照需要修改

创建表空间

CREATE TABLESPACE "USERNAME" --空间名
LOGGING
DATAFILE '/u01/app/oracle/oradata/XE/username.dbf' SIZE 32M
AUTOEXTEND
ON MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

创建用户

CREATE USER USERNAME IDENTIFIED BY PASSWORD --账号/密码
ACCOUNT UNLOCK
DEFAULT TABLESPACE USERNAME

为用户授权

GRANT CONNECT,RESOURCE TO USERNAME; --表示把 connect,resource权限授予USERNAME 用户
GRANT DBA TO USERNAME; --表示把 dba权限授予给 USERNAME 用户

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK