oracle12c linux安装
# 首先安装或者克隆centos7
这里我用的是minimal-1708版本
# 配置网络nat
cd /etc/sysconfig/network-scripts
vi ifcfg-ens33
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.40.122
NETMASK=255.255.255.0
GATEWAY=192.168.40.1
DNS1=192.168.40.1
service network restart
Vmware的设置
查看Vmnet8的ip段和网关,关闭dhcp
# 升级软件包
yum -y update
# 安装net-tools
yum -y install net-tools.x86_64
# 关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
重启后
getenforce
Disabled
# 关闭防火墙
systemctl stop firewalld
# 修改主机名和hosts
hostnamectl set-hostname oracle
vi /etc/hosts 添加oracle到匹配ip
# 安装oracle安装过程依赖项
yum -y install binutils compat-libstdc++ compat-libstdc++-33 elfutils-libelf-devel gcc gcc-c++ glibc-devel glibc-headers ksh libaio-devel libstdc++-devel make sysstat unixODBC-devel binutils-* compat-libstdc++* elfutils-libelf* glibc* gcc-* libaio* libgcc* libstdc++* make* sysstat* unixODBC* wget unzip
# 安装oracle java jdk
上传jdk1.8
安装jdk
rpm -i jdk-8u181-linux-x64.rpm
# 创建所需操作系统用户组和用户
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba,oper oracle
passwd oracle
密码设置要8位以上,而且不能过于简单
# 将oracle使用者加入到sudo群组中
vi /etc/sudoers
oracle ALL=(ALL) ALL
# 创建安装目录
*** $ORACLE_BASE
mkdir -p /opt/oracle
*** ORACLE_HOME
mkdir -p /opt/oracle/product/12.2.0/dbhome_1
数据存放目录
mkdir /opt/oracle/oradata
清单目录
mkdir /opt/oracle/inventory
数据恢复目录
mkdir /opt/oracle/flash_recovery_area
修改权限
chown -R oracle:oinstall /opt/oracle
chmod -R 775 /opt/oracle
# 修改系统参数
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
# 修改用户限制文件
vi /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
# 关联设置
[root@oracle ~]# vi /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
# 设置环境变量
[root@oracle ~]# 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
### source /etc/profile
# 配置oracle用户环境变量(切换oracle用户)
切换到oracle用户的home目录
[oracle@oracle ~]$ vim .bash_profile
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/12.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
[oracle@oracle ~]$ source .bash_profile
# 上传下载的数据库文件
到$ORACLE_BASE
# 解压oracle安装包
使用oracle用户解压
# 查看应答文件
解压完成可以看到目录/opt/oracle/database/response有3个应答文件,
分别数据库安装文件、建立数据库实例和监听配置安装文件
[oracle@oracle oracle]$ ll /opt/oracle/database/response/
total 112
-rwxrwxr-x 1 oracle oinstall 74822 Apr 4 2014 dbca.rsp
-rw-rw-r-- 1 oracle oinstall 25036 Jul 7 2014 db_install.rsp
-rwxrwxr-x 1 oracle oinstall 6038 Jan 24 2014 netca.rsp
# 修改数据库安装文件db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY #安装类型
ORACLE_HOSTNAME=oracle #主机名称
UNIX_GROUP_NAME=oinstall #安装组
INVENTORY_LOCATION=/opt/oracle/inventory #清单目录
SELECTED_LANGUAGES=en,zh_CN #选择语言
ORACLE_HOME=/opt/oracle/product/12.2.0/dbhome_1 #
oracle.install.db.InstallEdition=SE2 #oracle版本
oracle.install.db.DBA_GROUP=dba oracle_home
ORACLE_BASE=/opt/oracle #oracle_base#dba用户组
oracle.install.db.OPER_GROUP=oper #oper用户组
oracle.install.db.BACKUPDBA_GROUP=dba
oracle.install.db.DGDBA_GROUP=dba
oracle.install.db.KMDBA_GROUP=dba
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE #数据库类型
oracle.install.db.config.starterdb.globalDBName=orcl #globalDBName
oracle.install.db.config.starterdb.SID=orcl #SID
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.password.ALL=oracle
oracle.install.db.config.starterdb.installExampleSchemas=true
#设定所有数据库用户使用同一个密码
DECLINE_SECURITY_UPDATES=true #设置安全更新
# 安装
./runInstaller -silent -responseFile /opt/oracle/database/response/db_install.rsp -ignorePrereq
# 修改权限
以 root 用户的身份执行以下脚本:
1. /opt/oracle/inventory/orainstRoot.sh
2. /opt/oracle/product/12.2.0/dbhome_1/root.sh
# netca
[oracle@oracle ~]$ netca /silent /responseFile /opt/oracle/database/response/netca.rsp
正在对命令行参数进行语法分析:
参数"silent" = true
参数"responsefile" = /opt/oracle/database/response/netca.rsp
完成对命令行参数进行语法分析。
Oracle Net Services 配置:
完成概要文件配置。
Oracle Net 监听程序启动:
正在运行监听程序控制:
/opt/oracle/product/12.2.0/dbhome_1/bin/lsnrctl start LISTENER
监听程序控制完成。
监听程序已成功启动。
监听程序配置完成。
成功完成 Oracle Net Services 配置。退出代码是0
安装好后会生成listener.ora shrept.lst 和 sqlnet.ora文件
[oracle@oracle ~]$ ls /opt/oracle/product/12.2.0/dbhome_1/network/admin/
listener.ora samples shrept.lst sqlnet.ora
检查1521端口
[oracle@oracle ~]$ netstat -tulnp|grep 1521
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::1521 :::* LISTEN 61120/tnslsnr
查看listener.ora文件
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.20)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
tnsnames.ora文件内容
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.20)(PORT = 1521))
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.40.20)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
# 执行dbca
[oracle@oracle ~]$ vim /opt/oracle/database/response/dbca.rsp
gdbName=orcl
sid=orcl
templateName=General_Purpose.dbc
sysPassword=oracle
systemPassword=oracle
datafileDestination=/opt/oracle/oradata
recoveryAreaDestination=/opt/oracle/flash_recovery_area
characterSet=AL32UTF8
nationalCharacterSet=UTF8
[oracle@oracle ~]$ dbca -silent -createDatabase -responseFile /opt/oracle/database/response/dbca.rsp
建库后进行实例进程检查:
ps -ef | grep ora_ | grep -v grep
[oracle@oracle ~]$ sqlplus / as sysdba
SQL> select status from v$instance;
STATUS
------------
OPEN
如果出现的是Oracle not availible
startup
# 修改客户端乱码
export NLS_LANG=AMERICAN_AMERICA.UTF8
export LANG=en_US.UTF-8
## 如果执行lsnrctl status是如下情况
The listener supports no services
查看数据库service_name
sys@ORCL> show parameter service
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string orcl
手工注册有时能够解决问题:
sys@ORCL> alter system register;
System altered.
# 安装demo schema
下载demo schema
https://github.com/oracle/db-sample-schemas/releases/latest
将db-sample-schemas-12.2.0.1.zip 上传到/opt/oracle 目录下
解压
$ unzip db-sample-schemas-12.2.0.1.zip
进入目录
$ cd /opt/oracle/db-sample-schemas-12.2.0.1
修改工作路径
$ perl -p -i.bak -e 's#__SUB__CWD__#'$(pwd)'#g' *.sql */*.sql */*.dat
重新设置环境变量
[oracle@oracle db-sample-schemas-12.2.0.1]$ source /usr/local/bin/oraenv
ORACLE_SID = [orcl] ? y
ORACLE_HOME = [/home/oracle] ? /opt/oracle/product/12.2.0/dbhome_1/
The Oracle base remains unchanged with value /opt/oracle
确认关闭防火墙
$ systemctl stop firewalld
查看监听器是否启动
$ lsnrctl status
如果没有启动
$ lsnrctl start
$ sqlplus / as sysdba
@mksample oracle oracle hrpw oepw pmpw ixpw shpw bipw users temp /tmp/log/ orcl
登录安装好的示例数据库
conn hr/hrpw