Centos7.9安装Oracle11GR2

一、安装环境

以下安装环境在虚拟机测试环境

操作系统:Centos7.9

内存:8G

CPU:双核

硬盘:60G

二、下载安装包

https://pan.baidu.com/s/1oarQ1BWHCrNiDAu2-dbXNA?pwd=vt25 提取码: vt25

提取码: vt25

三、环境配置准备

3.1 防火墙配置

systemctl disable firewalld && systemctl stop firewalld

3.2 selinux配置

#临时关闭
[root@localhost ~]# setenforce 0 
#永久关闭
[root@localhost ~]# vim /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=enforcing   # 更改为SELINUX=disable
# 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.3 安装依赖包

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个

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

若出现包安装失败,则进行一下操作,若无失败情况则跳至3.4

更换yum源,以下任选一个执行

#阿里云 CentOS 7 源
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 华为云 CentOS 7 源
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.myhuaweicloud.com/repo/CentOS-7.repo

# 清华大学 CentOS 7 源:
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/

更换完yum源之后,清理yum缓存,并生成新的缓存

yum clean all && yum makecache

更新yum源检查是否生效

yum update -y

3.4 创建用户和用户组

创建oinstalldba用户组

groupadd oinstall && groupadd dba

创建oracle用户

useradd -g oinstall -G dba oracle

设置oracle密码

passwd oracle

查看创建结果

[root@localhost ~]# id oracle
uid=1000(oracle) gid=1000(oinstall) groups=1000(oinstall),1001(dba)

注意:这里查出来的uid必须是oraclegid必须是oinstall必须是dba

3.5 修改内核参数

[root@localhost ~]# vim /etc/sysctl.conf
# 在文件中添加以下内容:
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 3145728
kernel.shmmax = 12884901887
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.panic_on_oops = 1
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500

#生效配置
[root@localhost ~]# sysctl -p
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 524288
kernel.shmmax = 12884901887
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.panic_on_oops = 1
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500

各个参数说明:

**fs.aio-max-nr:**此参数限制并发未完成的请求,应该设置避免I/O子系统故障。
**fs.file-max:**该参数决定了系统中所允许的文件句柄最大数目,文件句柄设置代表linux系统中可以打开的文件的数量。
**kernel.shmall:**该参数控制可以使用的共享内存的总页数。Linux共享内存页大小为4KB,共享内存段的大小都是共享内存页大小的整数倍。一个共享内存段的最大大小是16G,那么需要共享内存页数是16GB/4KB=16777216KB /4KB=4194304(页),也就是64Bit系统下16GB物理内存,设置kernel.shmall = 41943 04才符合要求.
**kernel.shmmax:**是核心参数中最重要的参数之一,用于定义单个共享内存段的最大值。设置应该足够大,设置的过低可能会导致需要创建多个共享内存段,这样可能导致系统性能的下降。至于导致系统下降的主要原因为在实例启动以及ServerProcess创建的时候,多个小的共享内存段可能会导致当时轻微的系统性能的降低(在启动的时候需要去创建多个虚拟地址段,在进程创建的时候要让进程对多个段进行“识别”,会有一些影响),但是其他时候都不会有影响。
*官方建议值:*32位linux系统:可取最大值为4GB(4294967296bytes)-1byte,即4294967295。建议值为多于内存的一半,所以如果是32为系统,一般可取值为4294967295。
64位linux系统:可取的最大值为物理内存值-1byte,建议值为多于物理内存的一半,例如,如果为12GB物理内存,可取121024*10241024-1=12884901887。
**kernel.shmmni:**该参数是共享内存段的最大数量。shmmni缺省值4096,一般肯定是够用了。
kernel.sem:

以kernel.sem = 250 32000 100 128为例:

  • 250是参数semmsl的值,表示一个信号量集合中能够包含的信号量最大数目。
  • 32000是参数semmns的值,表示系统内可允许的信号量最大数目。
  • 100是参数semopm的值,表示单个semopm()调用在一个信号量集合上可以执行的操作数量。
  • 128是参数semmni的值,表示系统信号量集合总数。

**net.ipv4.ip_local_port_range:**表示应用程序可使用的IPv4端口范围。
**net.core.rmem_default:**表示套接字接收缓冲区大小的缺省值。
**net.core.rmem_max:**表示套接字接收缓冲区大小的最大值。
**net.core.wmem_default:**表示套接字发送缓冲区大小的缺省值。
**net.core.wmem_max:**表示套接字发送缓冲区大小的最大值。

3.6 修改配置

3.6.1 编辑limits.conf
#在文件末尾添加
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 10240

[root@buhuo database]# cat /etc/security/limits.conf 
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4

# End of file
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 10240

3.6.2 编辑login
[root@localhost ~]# cat /etc/pam.d/login 
#在文件末尾添加以下两行
session    required     /lib64/security/pam_limits.so
session    required     pam_limits.so


#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth       substack     system-auth
auth       include      postlogin
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
session    optional     pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    include      postlogin
-session   optional     pam_ck_connector.so
#在文件末尾添加以下两行
session    required     /lib64/security/pam_limits.so
session    required     pam_limits.so
3.6.3 编辑profile
[root@localhost ~]# 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@localhost ~]# source /etc/profile
3.6.4 创建数据库目录
[root@localhost /]# mkdir -p /data/server/oracle
[root@localhost /]# mkdir -p /data/server/file
[root@localhost /]# chown -R oracle:oinstall /data/
[root@localhost /]# chmod -R 775 /data/
3.6.5 配置Oracle用户
#切换到Oracle用户下
[root@localhost /]# su oracle

#编辑环境变量文件
[oracle@localhost /]$ vim ~/.bash_profile

#在末尾添加
export ORACLE_BASE=/data/server/oracle
export ORACLE_SID=orcl

#生效文件
[oracle@localhost ~]$ source .bash_profile

四、安装部署及配置

4.1上传Oracle安装包

4.2安装解压工具

已经安装则跳过该步骤

#切换回root用户
[oracle@localhost file]$ su root
#安装解压工具
[root@localhost file]# yum install -y unzip zip

4.3解压文件

[root@localhost file]# su oracle
[oracle@localhost file]$ unzip linux.x64_11gR2_database_1of2.zip 
[oracle@localhost file]$ unzip linux.x64_11gR2_database_2of2.zip 

4.4 编辑文件内容

#打开编辑db_install.rsp
[oracle@localhost response]$ vim /data/file/database/response/db_install.rsp 

oracle.install.option=INSTALL_DB_SWONLY // 安装类型  
UNIX_GROUP_NAME=oinstall // 安装组  
INVENTORY_LOCATION=/data/server/oracle/oraInventory //INVENTORY目录(不填就是默认值)  
ORACLE_HOME=/data/server/oracle/product/11/db_1
ORACLE_BASE=/data/server/oracle
oracle.install.db.InstallEdition=EE     // 企业版本  
oracle.install.db.DBA_GROUP=dba  
oracle.install.db.OPER_GROUP=oinstall
# oracle.install.db.OSBACKUPDBA_GROUP=oinstall  
# oracle.install.db.OSDGDBA_GROUP=oinstall  
# oracle.install.db.OSKMDBA_GROUP=oinstall
# oracle.install.db.OSRACDBA_GROUP=oinstall

oracle.install.db.config.starterdb.type=GENERAL_PURPOSE //数据库类型  
oracle.install.db.config.starterdb.globalDBName=orcl  
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.memoryLimit=81920 //自动管理内存的内存(M)  
oracle.install.db.config.starterdb.password.ALL=oracle//设定所有数据库用户使用同一个密码

SECURITY_UPDATES_VIA_MYORACLESUPPORT=false  
DECLINE_SECURITY_UPDATES=true

4.6 开始安装

注:执行./runlnstaller时,一定要是在Oracle用户下执行,root用户下执行会报错

[oracle@localhost /home/database]$./runlnstaller

报错问题汇总解决

#以下为报错信息
[oracle@localhost database]$ ./runInstaller 

>>> Ignoring required pre-requisite failures. Continuing...
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2024-11-27_01-05-11PM. 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':
    % <full path to xclock.. see below>
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用户下执行以下命令,查询可安装的xorg
[root@localhost database]# yum whatprovides "*/xhost"
# 使用yum安装最新版本
[root@localhost database]# yum install -y xorg-x11-server-utils-7.7-2.el6.x86_64 
# 安装完成后,使用startx命令启动	

# 输入命令startx进入桌面时,报错bash :startx command not found
#原因:系统并没有安装桌面

#解决方案:yum groupinstall "X Window System " -y

                      yum groupinstall "Gnome" -y
                  
                  输入 startx 启动桌面,可以启动

# 使用下面的xhost命令
[root@localhost database]# xhost 192.168.100.40  #这里的ip是Xmanger所安装的机器的ip,需要更换成自己安装Xmanager的机器的IP
#返回下面的结果
192.168.100.40 being added to access control list
# 执行xhost +进行检验
[root@localhost ~]# xhost +
#返回如下表示正常
access control disabled, clients can connect from any host
#再切换至oracle用户下,执行以下命令
[root@localhost database]$ su oracle
[oracle@localhost database]$ export DISPLAY=192.168.100.40:00

#在执行xclock时报错
[root@buhuo ~]# xclock
bash: xclock: command not found...
#解决方法如下
[root@buhuo ~]# yum install -y xorgwhich xclockx11-apps
                yum install xorg-x11-apps xorg-x11-utils -y

[root@buhuo ~]# which xclock
#出现下面的证明xclock可以使用
/usr/bin/xclock



由于Linux 安装的是中文环境,在运行 ./runInstaller 安装Oracle后,打开的安装界面乱码了,解决方案:临时指定语言环境

LANG=en_US ./runInstaller

     执行以上命令即可显示出正常的英文界面,如下图:

缺包问题

https://pan.baidu.com/s/15x01XuEu48_9epK2PVFk2g?pwd=u5v8 提取码: u5v8
 

提取码: u5v8

#从上面链接下载所需要的三个包,分别是
elfutils-libelf-0.97.1-5.i386.rpm
elfutils-libelf-devel-0.97.1-5.i386.rpm
pdksh-5.2.14-37.el5_8.1.i386.rpm

#需要使用rpm命令安装这三个包
[root@buhuo ~]# rpm -Uvh --force elfutils-libelf-0.97.1-5.i386.rpm
warning: elfutils-libelf-0.97.1-5.i386.rpm: Header V3 DSA/SHA1 Signature, key ID b38a8516: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:elfutils-libelf-0.97.1-5         ################################# [100%]
[root@buhuo ~]# rpm -Uvh --force elfutils-libelf-devel-0.97.1-5.i386.rpm
warning: elfutils-libelf-devel-0.97.1-5.i386.rpm: Header V3 DSA/SHA1 Signature, key ID b38a8516: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:elfutils-libelf-devel-0.97.1-5   ################################# [100%]

#在安装第三个包时会报错,显示两个包冲突,需要删除冲突的包
[root@buhuo ~]# rpm -Uvh pdksh-5.2.14-37.el5_8.1.i386.rpm 
warning: pdksh-5.2.14-37.el5_8.1.i386.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
error: Failed dependencies:
    pdksh conflicts with (installed) ksh-20120801-144.el7_9.x86_64

#使用下面的命令删除冲突包
[root@buhuo ~]# rpm -e ksh-20120801-144.el7_9.x86_64
   
[root@buhuo ~]# rpm -ivh pdksh-5.2.14-37.el5_8.1.i386.rpm 
warning: pdksh-5.2.14-37.el5_8.1.i386.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:pdksh-5.2.14-37.el5_8.1          ################################# [100%]


swap分区问题

#使用命令查看swap分区空间,如果没有任何输出,说明系统没有启用交换空间。
[root@buhuo ~]# swapon --show
#如果系统没有足够的交换空间,您可以增加交换空间。可以选择创建交换文件,以下是步骤:

#创建一个交换文件: 使用 fallocate 创建一个 20GB 的交换文件:
[root@buhuo ~]# fallocate -l 20GB /swapfile
#如果 fallocate 命令不可用,可以使用 dd 命令:
[root@buhuo ~]# dd if=/dev/zero of=/swapfile bs=1M count=20480
20480+0 records in
20480+0 records out
21474836480 bytes (21 GB) copied, 104.497 s, 206 MB/s

#置文件权限: 设置交换文件的权限:
[root@buhuo ~]# chmod 600 /swapfile

#格式化交换文件
[root@buhuo ~]# mkswap /swapfile
Setting up swapspace version 1, size = 20971516 KiB
no label, UUID=d7e3deec-aae3-4ca7-94ef-b3ef62181798


#启用交换文件
[root@buhuo ~]# swapon /swapfile


#将交换文件添加到 /etc/fstab 使其永久生效: 打开 /etc/fstab 文件,并添加以下内容
[root@buhuo ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Jun 28 04:16:23 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=c8b5b2da-5565-4dc1-b002-2a8b07573e22 /                       ext4    defaults        1 1
#在文件最后一行添加以下内容
/swapfile swap swap defaults 0 0

在安装数据库时出现agent nmhs时需要修改以下文件

root@buhuo ~]# vim /data/server/oracle/product/11.2.0/dbhome_1/sysman/lib/ins_emagent.mk
将文件中
$(MK_EMAGENT_NMECTL) 改为
$(MK_EMAGENT_NMECTL) -lnnz11(#提示:第一个是字母l,后面两个是数字1)

sqlplus命令问题

#执行sqlplus时提示如下
[oracle@buhuo database]$ sqlplus 
bash: sqlplus: command not found...

#需要在.bash_profile中添加或增加以下内容
[oracle@buhuo ~]$ cat .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=/data/server/oracle
export ORACLE_SID=ncdb
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin

#保存退出后执行source命令生效该文件,之后sqlplus命令可以使用
[oracle@buhuo ~]$ source .bash_profile 

修改Oracle字符集为ZHS16GBK

1、登录DBA用户

# 登录dba用户
sqlplus /nolog
SQL>connect sys/oracle as sysdba

2、查看当前字符集

# 查看当前字符集
SELECT * FROM V$NLS_PARAMETERS WHERE PARAMETER = 'NLS_CHARACTERSET';
SELECT USERENV('language') FROM DUAL;

3、关闭数据库,以mount方式打开

# 关闭数据库
shutdown immediate;

# 以mount打开
startup mount;

4、设置session

# 设置session
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
ALTER SYSTEM SET AQ_TM_PROCESSES=0;

5、启动数据库,修改字符集

# 启动数据库
SQL>alter database open;

# 修改字符集
ALTER DATABASE CHARACTER SET ZHS16GBK;

# 可能会遇到的错误:ORA-12712: new character set must be a superset of old character set

# 解决办法
ALTER DATABASE character set INTERNAL_USE ZHS16GBK;

6、重启,查看是否修改成功

# 关闭
shutdown immediate;

# 重启
startup;

# 查看当前字符集
SELECT * FROM V$NLS_PARAMETERS WHERE PARAMETER = 'NLS_CHARACTERSET';
SELECT USERENV('language') FROM DUAL;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星星乘坐的船

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值