一、安装的硬件要求
1.内存:
要求:内存最小1G,推荐2G或者更高。呃呃呃
查看命令:# grep MemTotal /proc/meminfo
2.Swap:
要求:
RAW Swap
1G至2G 1.5倍
2G至16G 同RAW相等
16G以上 16G
二、环境准备
安装包:
- linuxx64_12201_database.zip
Oracle下载地址:[http://www.oracle.com/technetwork/indexes/downloads/index.html#database]
三、安装Oracle前的准备
3.1.创建运行oracle数据库的系统用户和用户组
1 [root@oracle-test ~]# groupadd oinstall #创建用户组oinstall
2 [root@oracle-test ~]# groupadd dba #创建用户组dba
3 [root@oracle-test ~]# useradd -g oinstall -g dba -m oracle #创建oracle用户,并加入到oinstall和dba用户组
4 [root@oracle-test ~]# passwd oracle #设置用户oracle的登陆密码,不设置密码,在CentOS的图形登陆界面没法登陆
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.
5 [root@oracle-test ~]# id oracle # 查看新建的oracle用户
uid=1001(oracle) gid=1002(dba) groups=1002(dba)
3.2.创建oracle数据库安装目录
[root@oracle-test ~]# mkdir -p /oracle/product/12.2.0/db_1 #创建oracle安装目录
[root@oracle-test ~]# chown -R oracle:oinstall /oracle
[root@oracle-test ~]# mkdir -p /ora_data/ #创建数据文件目录
[root@oracle-test ~]# chown -R oracle:oinstall /ora_data
[root@oracle-test ~]# mkdir -p /ora_idx/ #创建索引文件目录
[root@oracle-test ~]# chown -R oracle:oinstall /ora_idx
[root@oracle-test ~]# mkdir -p /ora_flash/ #创建归档日志文件目录
[root@oracle-test ~]# chown -R oracle:oinstall /ora_flash
3.3.安装oracle数据库所需要的软件包
[root@oracle-test ~]# yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.devel compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686
检查是否安装成功(31个安装包)
[root@oracle-test ~]# rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel|wc
centos7需要的安装包,可以在Oracle上查看:https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#LADBI1085
3.4.关闭防火墙
[root@oracle-test ~]# systemctl status firewalld.service #查看防火墙状态(运行中)
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-09-13 09:23:08 CST; 25min ago
Docs: man:firewalld(1)
Main PID: 641 (firewalld)
CGroup: /system.slice/firewalld.service
└─641 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Sep 13 09:22:58 localhost.localdomain systemd[1]: Starting firewalld - dynami...
Sep 13 09:23:08 localhost.localdomain systemd[1]: Started firewalld - dynamic...
Hint: Some lines were ellipsized, use -l to show in full.
[root@oracle-test ~]# systemctl stop firewalld.service #关闭防火墙
[root@oracle-test ~]# systemctl status firewalld.service #查看防火墙状态(已关闭)
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Wed 2017-09-13 09:48:55 CST; 10s ago
Docs: man:firewalld(1)
Process: 641 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 641 (code=exited, status=0/SUCCESS)
Sep 13 09:22:58 localhost.localdomain systemd[1]: Starting firewalld - dynami...
Sep 13 09:23:08 localhost.localdomain systemd[1]: Started firewalld - dynamic...
Sep 13 09:48:54 localhost.localdomain systemd[1]: Stopping firewalld - dynami...
Sep 13 09:48:55 localhost.localdomain systemd[1]: Stopped firewalld - dynamic...
Hint: Some lines were ellipsized, use -l to show in full.
[root@oracle-test ~]#
systemctl disable firewalld.service #禁止使用防火墙(重启也是禁止的)
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
3.5.关闭selinux(需重启生效)
[root@oracle-test ~]# vi /etc/selinux/config
[root@oracle-test ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
3.6、修改内核参数
[root@oracle-test ~]# vim /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
#oracle setting
fs.aio-max-nr = 1048576
fs.file-max = 6815744
# 该参数表示系统任意时刻可以分配的所有共享内存段的总和的最大值(以页为单位).其值应不小于
# shmmax/page_size(getconf PAGESIZE可以查询到).缺省值就是2097152
kernel.shmall = 2097152
#64 位 linux 系统:可取的最大值为物理内存值 -1byte ,建议值为多于物理内存的一半,一般取值大于 SGA_MAX_SIZE 即可,
# 可以取物理内存 -1byte.例:内存为 16G 时,该值为 16*1024*1024*1024-1 = 17179869183
kernel.shmmax = 17179869183
# 缺省为32M,对于oracle来说,该缺省值太低了,通常将其设置为2G
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
[root@oracle-test ~]# sysctl -p #立即生效
3.7、对oracle用户设置限制,提高软件运行性能(斜体为添加部分)
[root@oracle-test ~]# vim /etc/security/limits.conf
@student - maxlogins 4
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 10240
End of file
3.8 修改用户登录库文件引用
[root@oracle-test ~]#vim /etc/pam.d/login
# 在文件末尾添加下面2行内容
session required /lib64/security/pam_limits.so
session required pam_limits.so
3.9 修改用户登录环境变量
[root@oracle-test ~]# vim /etc/profile
# 在文件末尾添加下面内容
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
# 使修改的文件生效
[root@oracle-test ~]# source /etc/profile
3.10、配置用户的环境变量
[root@oracle-test ~]# cat /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_BASE=/oracle #oracle数据库安装目录
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1 #oracle数据库路径
export ORACLE_SID=orcl #oracle启动数据库实例名
export ORACLE_UNQNAME=orcl
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH #添加系统环境变量
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:$ORACLE_HOME/oracm/lib:/usr/local/lib:/usr/lib #添加系统环境变量
export LANG='AMERICAN_AMERICA.ZHS16GBK' #防止安装过程出现乱码
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK #设置Oracle客户端字符集,必须与Oracle安装时设置的字符集保持一致
[root@oracle-test ~]# source /home/oracle/.bash_profile #使环境变量生效
3.11、将安装包放到/root/home/路径下
[root@oracle-test ~]# ls
linuxx64_12201_database.zip
3.12、解压安装包并设置权限
[root@oracle-test ~]# unzip linuxx64_12201_database.zip
移动到home目录
[root@oracle-test ~]#mv /root/database/ /home/oracle/
[root@oracle-test ~]# chown -R oracle:oinstall /home/oracle/database/
四、开始安装Oracle
4.1、进入到虚拟机控制台中,以oracle用户登录,运行安装程序:
切换目录:
切换到中文模式
[oracle@oracle-test ~]$ export LANG=en_US.UTF-8
[oracle@oracle-test ~]$ export LC_CTYPE=en_US.iso88591
4.2、执行安装命令
[oracle@oracle-test ~]$./database/runInstaller
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 500 MB. Actual 267705 MB Passed
Checking swap space: must be greater than 150 MB. Actual 15999 MB Passed
Checking monitor: must be configured to display at least 256 colors
>>> Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set. Failed <<<<
Some requirement checks failed. You must fulfill these requirements before
continuing with the installation,
Continue? (y/n) [n] y
>>> Ignoring required pre-requisite failures. Continuing...
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2021-01-14_09-48-30AM. Please wait ...
DISPLAY not set. Please set the DISPLAY and try again.
Depending on the Unix Shell, you can use one of the following commands as examples to set the DISPLAY environment variable:
- For csh: % setenv DISPLAY 192.168.1.128:0.0
- For sh, ksh and bash: $ DISPLAY=192.168.1.128:0.0; export DISPLAY
Use the following command to see what shell is being used:
echo $SHELL
Use the following command to view the current DISPLAY environment variable setting:
echo $DISPLAY
- Make sure that client users are authorized to connect to the X Server.
To enable client users to access the X Server, open an xterm, dtterm or xconsole as the user that started the session and type the following command:
% xhost +
To test that the DISPLAY environment variable is set correctly, run a X11 based program that comes with the native operating system such as 'xclock':
%
If you are not able to run xclock successfully, please refer to your PC-X Server or OS vendor for further assistance.
Typical path for xclock: /usr/X11R6/bin/xclock
备注:发现有报错,然后执行:
[root@oracle-test ~]#export DISPLAY=192.168.155.14:0.0 #192.168.155.14为本机ip,并非是oracle服务器。
4.3、安装xhost和运行DISPLAY
1.[oracle@oracle-test ~]$ export DISPLAY=192.168.155.14:0.0
在虚拟机中安装ORACLE, 设置完DISPLAY变量后,运行xhost +命令无法找到,明显为xhost相对应的rpm包未安装.
用yum命令加参数whatprovides 加xhost查到相对应的包为xorg-x11-server-utils-7.7-14.el6.x86_64,如下图.
2. [root@oracle-test ~]# yum whatprovides */xhost
Loaded plugins: refresh-packagekit, security, ulninfo
xorg-x11-server-utils-7.7-14.el6.x86_64 : X.Org X11 X server utilities
Repo : public_ol6_latest
Matched from:
Filename : /usr/bin/xhost
3. yum安装xorg-x11-server-utils-7.*.el7.x86_64包
[root@oracle-test ~]# yum install -y xorg-x11-server-utils-7.*.el7.x86_64
Loaded plugins: refresh-packagekit, security, ulninfo
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package xorg-x11-server-utils.x86_64 0:7.7-14.el6 will be installed
--> Processing Dependency: mcpp for package: xorg-x11-server-utils-7.7-14.el6.x86_64
--> Running transaction check
---> Package mcpp.x86_64 0:2.7.2-4.1.el6 will be installed
--> Processing Dependency: libmcpp.so.0()(64bit) for package: mcpp-2.7.2-4.1.el6.x86_64
--> Running transaction check
---> Package libmcpp.x86_64 0:2.7.2-4.1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================
Package Arch Version Repository Size
==================================================================
Installing:
xorg-x11-server-utils x86_64 7.7-14.el6 public_ol6_latest 156 k
Installing for dependencies:
libmcpp x86_64 2.7.2-4.1.el6 public_ol6_latest 68 k
mcpp x86_64 2.7.2-4.1.el6 public_ol6_latest 23 k
Transaction Summary
====================================================================
Install 3 Package(s)
Total download size: 246 k
Installed size: 548 k
Downloading Packages:
------------------------------------------------------------------------------------------------------------------------------------
Total 11 MB/s | 246 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libmcpp-2.7.2-4.1.el6.x86_64 1/3
Installing : mcpp-2.7.2-4.1.el6.x86_64 2/3
Installing : xorg-x11-server-utils-7.7-14.el6.x86_64 3/3
Verifying : xorg-x11-server-utils-7.7-14.el6.x86_64 1/3
Verifying : libmcpp-2.7.2-4.1.el6.x86_64 2/3
Verifying : mcpp-2.7.2-4.1.el6.x86_64 3/3
Installed:
xorg-x11-server-utils.x86_64 0:7.7-14.el6
Dependency Installed:
libmcpp.x86_64 0:2.7.2-4.1.el6 mcpp.x86_64 0:2.7.2-4.1.el6
Complete!
4. 安装完xorg-x11-server-utils-7.7-14.el6.x86_64包后,产生了xhost +
[root@oracle-test ~]# xhost +
access control disabled, clients can connect from any host
4.4、再次执行安装命令:
[oracle@oracle-test ~]$./database/runInstaller
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB. Actual 268850 MB Passed
Checking swap space: must be greater than 150 MB. Actual 15999 MB Passed
Checking monitor: must be configured to display at least 256 colors
>>> Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set. Failed <<<<
Some requirement checks failed. You must fulfill these requirements before
continuing with the installation,
Continue? (y/n) [n] y
>>> Ignoring required pre-requisite failures. Continuing...
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2021-01-04_03-08-36PM. Please wait ...
4.5、进入图形化安装,操作步骤如下:
步骤一:如下图,去掉对勾:
步骤二:
选择:Install database software only
(只安装数据库软件,稍后使用dbca创建数据库示例)
步骤三:
选择:Single instance database installation
(单实例数据库安装)
步骤四:
选择:Enterprise Edition(企业版)
步骤五:
配置好环境变量后路径自动识别,无需修改:
步骤六:设置路径为: /oracle/oraInventory
点击:Yes
步骤七:把第二个组选为dba组:
步骤八:安装前检测,有部分rpm包缺失,需要找到相应包安装:
安装对应包:
[root@oracle2 ~]#yum install -y smartmontools-*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package smartmontools.x86_64 1:7.0-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================
Installing:
smartmontools x86_64 1:7.0-2.el7 base 546 k
Transaction Summary
=========================================================================================================================================
Install 1 Package
Total download size: 546 k
Installed size: 2.0 M
Downloading packages:
smartmontools-7.0-2.el7.x86_64.rpm | 546 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:smartmontools-7.0-2.el7.x86_64 1/1
Verifying : 1:smartmontools-7.0-2.el7.x86_64 1/1
Installed:
smartmontools.x86_64 1:7.0-2.el7
Complete!
步骤九:再次检查后无异常,点击下一步安装:
步骤十:安装进行中:
步骤十一:
根据以下路径,执行下列的两个脚本:
[root@oracle-test ~]#/oracle/oraInventory/orainstRoot.sh
Changing permissions of /oracle/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /oracle/oraInventory to dba.
The execution of the script is complete.
[root@oracle-test ~]#/oracle/product/11.2.0/db_1/root.sh
Performing root user operation.
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /oracle/product/11.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] :
yes
Installing Oracle Trace File Analyzer (TFA).
Log File: /oracle/product/11.2.0/db_1/install/root_oracle1_2021-01-14_10-16-04-154949797.log
Finished installing Oracle Trace File Analyzer (TFA)
步骤十二:安装数据库完后,关闭。
步骤十三:sqlplus验证
通过sqlplus 连接验证:
(因为还没有创建数据库,所以是连接到空闲实例)
4.6、建立数据库:启动dbca创建数据库
步骤1:进入到虚拟机控制台中,以oracle用户登录,输入:dbca,然后进入Oracle12c安装界面。
步骤2:在选择数据库操作页,选择Create a database,点击Next;
步骤3:在选择数据库创建模式页,选择Advanced configuration,点击Next;
步骤4:在选择数据库部署类型页,默认,并点击Next;
步骤5:在指定数据库标识页,分为两种情形(这里按照第一种方式进行建库):
1)如果安装Non-Container数据,去掉勾选Create as Container database,点击Next;
2)如果安装容器数据库,勾选Create as Container database,点击Next;
注:勾选Create as Container database表示创建的数据库是容器数据库,然后可以选择Undo的模式,在这里选择默认,并创建一个PDB数据库,名称为orclpdb。
步骤6:在选择数据库存储选项页,选择自定义的数据路径,并点击Next;
步骤7:在选择闪回恢复区选项页,勾选Specify Fast Recovery Area,并点击Next;
步骤8:在指定网络配置详细页,默认,点击Next;
步骤9:在指定Oracle Data Vault配置选项页,默认,点击Next;
步骤10:在指定配置选项页,分别配置以下内容:
1)内存配置,选择4072M;
2)进程大小配置,默认;
3)字符集配置,默认;
4)连接模式配置,默认;
5)示例数据库配置,勾选Add sample schemas to the database,点击Next;
步骤11:在指定EM管理选项页,默认,点击Next(这里指的是安装EM管理服务);
下一步后出现报错,这里点击YES:
步骤12:在指定数据库密码页,选择Use the same administrator password for all accounts,点击Next;
提示密码简单,不满足安全标准,这里点击YES:
步骤13:在创建数据库选项页,默认,点击Next;
步骤14:在概要页,点击Finish;
步骤15: 在安装进度页,默认;
步骤16:安装完成页,点击Close;
4.7、启动netca建立监听程序
步骤1:进入到虚拟机控制台中,以oracle用户登录,输入:netca
选择:Listener Configuration
步骤2:选择:Add
步骤3:默认继续:
步骤4:默认继续:
步骤5:使用默认端口1521:
步骤6:是否创建其他监听程序,选择:No
步骤7:监听程序创建完成
4.8、创建本地网络服务名
步骤1:选择:Local Net Service Name Configuration
步骤2:选择:Add
步骤3:输入数据库实例名称:orcl
步骤4:默认继续:
步骤5:输入数据库服务器主机名称或者IP地址,这里选择输入IP地址:
步骤6:选择:Yes,perform a test (测试连接)
步骤7:输入system用户名及密码,连接测试成功::
步骤8:给本地网络服务名起名称,可以自定义,这里依然为:orcl
步骤9:是否创建其他网络服务名,点击:No
步骤10:点击:Next 直到退出