1.准备
oracle Oracle Database 11g Release 2在官网上下载Oracle,并上传到自己的服务器 https://www.oracle.com/database/technologies/index.html
- 下载Oracle源
根据oracle版本选择 wget http://yum.oracle.com/public-yum-ol6.repo 还是wget http://yum.oracle.com/public-yum-ol7.repo
[root@localhost yum.repos.d]# yum -y install wget
[root@localhost yum.repos.d]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# wget http://yum.oracle.com/public-yum-ol7.repo
根据系统编辑文件,根据对应系统版本将 enabled的值置为1,使用对应的源,默认是最新的
[root@localhost yum.repos.d]# vi public-yum-ol7.repo
[ol7_latest]
name=Oracle Linux $releasever Latest ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/latest/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
[ol7_u0_base]
name=Oracle Linux $releasever GA installation media copy ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/0/base/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=0
[ol7_u1_base]
name=Oracle Linux $releasever Update 1 installation media copy ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/1/base/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=0
[ol7_u2_base]
name=Oracle Linux $releasever Update 2 installation media copy ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/2/base/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=0
[ol7_u3_base]
name=Oracle Linux $releasever Update 3 installation media copy ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/3/base/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=0
[ol7_u4_base]
name=Oracle Linux $releasever Update 4 installation media copy ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/4/base/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=0
[ol7_u5_base]
name=Oracle Linux $releasever Update 5 installation media copy ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/5/base/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=0
2.基础环境配置
查看机器配置参数
- cpu配置
[root@mldb002 ~]# more /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
stepping : 1
microcode : 1
cpu MHz : 2494.222
cache size : 40960 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
- 内存配置
[root@mldb002 ~]# more /proc/meminfo
MemTotal: 33014448 kB
MemFree: 32425904 kB
Buffers: 65416 kB
Cached: 185636 kB
SwapCached: 0 kB
Active: 142592 kB
Inactive: 185972 kB
Active(anon): 77532 kB
Inactive(anon): 160 kB
Active(file): 65060 kB
Inactive(file): 185812 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 40 kB
Writeback: 0 kB
AnonPages: 77524 kB
Mapped: 27924 kB
Shmem: 176 kB
Slab: 48796 kB
配置交换分区
Swap交换分区建议6G以上,最好在安装ORACLE-LINUX-R6U5时就分配好6G以上的空间,硬盘不少于10G。
如果安装linux的时候没有配置也可以用如下命令配置:
参考
1、用dd命令创建一个16G的文件(of :文件路径 bs:大小单位 count:数量)
[root@mldb002 /]#dd if=/dev/zero of=/u02/sys/swap bs=1G count=16
2、将它创建为Linux Swap虚拟交换文件
[root@mldb002 sys]# mkswap /u02/sys/swap
mkswap: /u02/sys/swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 16777212 KiB
no label, UUID=ae803301-f1ce-4581-921f-b0911c094dbb
3、激活并使用/var/swapfile交换文件
[root@mldb002 /]#swapon /u02/sys/swap
4、设置系统启动后自动激活虚拟交换文件。
[root@mldb002 /]#vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Aug 25 11:52:44 2017
#
# 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=a3b07a51-3009-4ddf-9240-81333f13880e / ext4 defaults 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/u02/sys/swap swap swap defaults 0 0
5、查看是否配置成功
top - 14:58:19 up 6 min, 1 user, load average: 0.00, 0.02, 0.00
Tasks: 192 total, 2 running, 190 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.1%us, 0.1%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 33014448k total, 450980k used, 32563468k free, 8596k buffers
Swap: 16777212k total, 0k used, 16777212k free, 107780k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1303 root 20 0 2447m 66m 10m S 0.7 0.2 0:07.13 java
1301 root 20 0 113m 1516 916 S 0.3 0.0 0:00.15 wrapper
1 root 20 0 19228 1584 1308 S 0.0 0.0 0:00.52 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
7 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
8 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/1
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1
10 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
11 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/2
12 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/2
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/2
14 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/2
15 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/3
16 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/3
17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/3
18 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/3
19 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/4
20 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/4
21 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/4
22 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/4
23 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/5
配置网络
必须固定安装Oracle所在机器的IP地址,不能用DHCP动态分配IP地址。如果不是固定ip则需要更改/etc/sysconfig/network-scripts/ifcfg-eth0文件:
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:0C:29:74:5B:62
ONBOOT=yes
HWADDR=00:0C:29:74:5B:62 #你的mac地址
IPADDR=192.168.89.130 #你的IP地址
NETMASK=255.255.255.0 #你的IP地址
GATEWAY=192.168.89.1 #你的网关
修改主机名
[root@localhost etc]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 mldb002
或者
[root@mldb002 etc]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=mldb002
NETWORKING_IPV6=no
PEERNTP=no
- 重启并确认主机名
[root@localhost etc]# reboot
[root@localhost etc]# hostname
[root@mldb002 yum.repos.d]# hostname
mldb002
Oracle环境配置
- 在安装过程中涉及的几个文件位置及用途
/etc/sysctl.conf (修改内核参数)
/etc/security/limits.conf (shell对oracle用户的限制)
/etc/pam.d/login
/etc/profile (系统相关的环境变量)
/home/oracle/.bash_profile (oracle用户相关的环境变量)
/home/oracle(确保本目录空间足够大)
/etc/hosts (建立ip和机器名的关系,通过uname把地址和机器名关联,否则在安装数据库时报监听器错误)
/etc/sysconfig/network 修改机器名
创建Oracle用户和用户组
在后面预安装包安装的话如果没有oracle用户则会自动创建,这里由于我们想指定UID和GID所以手动创建oinstall,dba组和oracle用户,安装目录可以选择安装在/home/oralce目录下。
linux用户和组介绍
查看组命令
[root@mldb002 ~] cat /etc/group
[root@mldb002 ~] groupadd -g 54321 oinstall
[root@mldb002 ~] groupadd -g 54322 dba
[root@mldb002 ~] useradd -u 54321 -m -d /home/oracle -g oinstall -G dba oracle
[root@mldb002 ~] id oracle
uid=54321(oracle) gid=54321(oinstall) 组=54321(oinstall),54322(dba)
groupadd oinstall 是创建用户组,用来做oracle的安装和维护工作
useradd 是创建用户
-m –d /home/oracle 是把/home/oracle目录作为oracle用户的主目录或登录默认目录
–g oinstall 是表示oracle用户的初始组为oinstall
–G dba 是表示oracle用户同时属于dba组,做数据维护,和数据库管理工作.
创建oracle用户的密码:根据提示,输入2次密码就可以了。还要让oinstall用户组对oracle安装目录有写权限
[root@linuxoa pafirc] passwd oracle
[root@linuxoa pafirc] chmod -R 700 /home/oracle
修改内核参数
如果内核参数配置的不对,在”产品特定先决条件检查”中也会被检测出来,也需要修改内核参数.在/etc/sysctl.conf中可以自定义修改,由于我们使用预安装包安装他会自动修改内核参数所以这里不用修改了。
设置Shell对于oracle用户的限制:
[root@txmlwebserver01 mlerpdb01]# vi /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@txmlwebserver01 ~]# source /etc/profile
配置ORACLE_HOME
- 创建安装目录
[root@mldb002 /]# mkdir -p /u01/app/oracle
[root@mldb002 /]# mkdir -p /u01/app/oracle/oradata
[root@mldb002 /]# mkdir -p /u01/app/oraInventory
[root@mldb002 /]# mkdir -p /u01/app/oracle/fast_recovery_area
[root@mldb002 /]# mkdir -p /u01/app/oracle/product/11.2.0/db_1
[root@mldb002 /]# chown -R oracle:oinstall /u01/app/oracle
[root@mldb002 /]# chown -R oracle:oinstall /u01/app
[root@mldb002 /]# chmod -R 755 /u01/app
以oracle用户身份登录,修改当前用户下的.bash_profile(这是用户主目录下的一个隐藏文件)
[oracle@mldb002 ~]cd /home/oracle
[oracle@mldb002 ~]vi .bash_profile
export ORACLE_BASE=/u01/app/oracle;
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1;
export ORACLE_SID=mlerpdb01;
export ORACLE_UNQNAME=mlerpdb01;
export ORACLE_TERM=xterm;
export PATH=$ORACLE_HOME/bin:$PATH;
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
export PATH
[oracle@mldb002 ~]# . /home/oracle/.bash_profile
4.安装oracle-rdbms-server-11gR2-preinstall
- 使用yum安装oracle-rdbms-server-11gR2-preinstall包(oracle-rdbms-server-11gR2-preinstall)
[root@mldb002 yum.repos.d]# yum install oracle-rdbms-server-11gR2-preinstall
如果出现"Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle" 类似报错,可以采取以下两种解决方法
1.不需要验证包的完整性[root@localhost yum.repos.d]# yum install --nogpgcheck oracle-rdbms-server-11gR2-preinstall
2.wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol7 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
- 查看安装结果日志
[root@mldb002 yum.repos.d]# cat /var/log/oracle-rdbms-server-11gR2-preinstall/results/orakernel.log
Adding group oinstall with gid 54321
Adding group dba
Adding user oracle with user id 54321, initial login group oinstall, supplementary group dba and home directory /home/oracle
Changing ownership of /home/oracle to oracle:oinstall
Please set password for oracle user
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba)
Creating oracle user passed
Saving a copy of the initial sysctl.conf
Verifying kernel parameters as per Oracle recommendations...
Adding fs.file-max = 6815744
Adding kernel.sem = 250 32000 100 128
Adding kernel.shmmni = 4096
Adding kernel.shmall = 1073741824
Adding kernel.shmmax = 4398046511104
Adding kernel.panic_on_oops = 1
Adding net.core.rmem_default = 262144
Adding net.core.rmem_max = 4194304
...
5.安装Oracle
- 上传Oracle安装文件到服务器的/u02/tools目录
[root@mldb002 results]# yum -y install zip unzip
[root@mldb002 tmp]# mkdir -p /u02/tools
[root@mldb002 tmp]# cd /u02/tools
[root@mldb002 tools]# unzip /u02/tools/linux.x64_11gR2_database_1of2.zip
[root@mldb002 tools]# unzip /u02/tools/linux.x64_11gR2_database_2of2.zip
- 查看响应文件
[root@localhost tools]# cd database/response/
[root@localhost response]# ls
dbca.rsp db_install.rsp netca.rsp
[root@localhost response]# grep -Ev "^$|^#" db_install.rsp
#对照响应文件修改自己为自己的配置,示例是安装在/u01/app目录下的
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_AND_CONFIG
ORACLE_HOSTNAME=txmlwebserver01
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN,zh_TW
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=mlerpdb01
oracle.install.db.config.starterdb.SID=mlerpdb01
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=1600
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=MLusr001
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/u01/app/oracle/oradata
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/u01/app/oracle/fast_recovery_area
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT_USERNAME=
MYORACLESUPPORT_PASSWORD=
SECURITY_UPDATES_VIA_MYORACLESUPPORT=
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=SKIP_UPDATES
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=
- 开始安装
[root@localhost database] su - oracle
[oracle@localhost database] cd /u02/tools/database/
[oracle@localhost database]# ./runInstaller -silent -showProgress -ignoreSysPrereqs -responseFile /u02/tools/database/response/db_install.rsp
错误1:检查临时空间: 可用的临时空间为 7 MB, 所需的临时空间为 120 MB。 未通过 <<<<
可以删除临时目录的文件
[oracle@localhost database] cd /tmp
[oracle@localhost tmp]$ rm -rf OraInstall2018-03-09_0*
错误2:
WARNING: A log of this session is currently saved as: /tmp/OraInstall2012-11-20_05-33-57PM/installActions2012-11-20_05-33-57PM.log. Oracle recommends that if you want to keep this log, you should move it from the temporary location to a more permanent location.
INFO: Finding the most appropriate exit status for the current application
INFO: Exit Status is -2
INFO: Shutdown Oracle Database 11g Release 2 Installer
解决办法:
在响应文件db_install.rsp中,设置DECLINE_SECURITY_UPDATES=true即可。
以下配置脚本需要以 "root" 用户的身份执行。
#!/bin/sh
#要运行的 Root 脚本
/u02/tools/oracle/oraInventory/orainstRoot.sh
/u02/tools/oracle/product/11.2.0/db_1/root.sh
要执行配置脚本, 请执行以下操作:
1. 打开一个终端窗口
2. 以 "root" 身份登录
3. 运行脚本
4. 返回此窗口并按 "Enter" 键继续
- 查看开机启动配置文件
[root@oracle admin]# vi /etc/oratab
#
# This file is used by ORACLE utilities. It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.
# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
mlerpdb01:/usr/local/soft/oracle/product/11.2.0/db_1:Y
[root@oracle admin]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
su - oracle -c "/home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"
- 启动数据库
[oracle@txmlwebserver01 ~]$ su – oracle
[oracle@txmlwebserver01 ~]$ sqlplus / nolog
sql> conn / as sysdba
sql> startup (一般不需要加参数,只要设置好环境变量)
sql> quit (退出sql模式)
$ lsnrctl start (启动监听器)
- 开放远程连接端口
[root@txmlwebserver01 ~]$ firewall-cmd --zone=public --permanent --add-port=1521/tcp
[root@txmlwebserver01 ~]$ service firewalld restart
create tablespace NOTIFYDB datafile '${ORACLE_HOME}\oradata\notifydb.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
4.PL/SQL远程连接
-
安装oracle 客户端
oracle客户端 -
连接配置
网络配置
- 使用PL/SQL
- 查询测试数据
select * from emp
image.png
5.参考资料
Orcale安装
https://www.cnblogs.com/ajiangg/p/7991338.html
https://www.cnblogs.com/ivictor/p/4384583.html
https://blog.csdn.net/sinat_27902055/article/details/60331329
Oracle官网
https://docs.oracle.com/cd/E11882_01/install.112/e47689/rev_precon_db.htm#LADBI1331
修改hostname
https://blog.csdn.net/yangshangwei/article/details/52878530
网友评论