1.下载oracle11g
linux.x64_11gR2_database_1of2.zip 下载地址
链接:https://pan.baidu.com/s/1A8VEBtADuKWWhv4IhO2GYw
提取码:fng1
linux.x64_11gR2_database_2of2.zip下载地址
链接:https://pan.baidu.com/s/1Q9RzENA_WtiqRdHsnI0W4g
提取码:jnnl
2.解压文件到指定目录:
[root@zsy home]# unzip linux.x64_11gR2_database_1of2.zip -d /home/oracle/
[root@zsy home]# unzip linux.x64_11gR2_database_2of2.zip -d /home/oracle/
[root@zsy oracle]# mv database/ /home/
[root@zsy oracle]# cd /home/
3.关闭selinux
[root@zsy ~]# vim /etc/selinux/config
设置SELINUX=disabled
4.关闭防火墙
查看系统版本
[root@zsy etc]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@zsy etc]# getconf LONG_BIT
[root@zsy etc]# service iptables stop
[root@zsy etc]# service iptables status
[root@zsy etc]# chkconfig iptables off
5.安装oracle 11g依赖包
[root@zsy etc]# yum install gcc make binutils gcc-c++ compat-libstdc++-33elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-develnumactl-devel sysstat unixODBC unixODBC-devel pcre-devel –y
6.添加安装用户和用户组
[root@zsy etc]# groupadd oinstall
[root@zsy etc]# groupadd dba
[root@zsy etc]# useradd -g oinstall -G dba oracle
[root@zsy etc]# passwd oracle
Changing password for user oracle.
New password:
Retype new password:
[root@zsy etc]# id oracle
uid=501(oracle) gid=502(oinstall) groups=502(oinstall),501(dba)
7.修改内核参数配置文件
[root@zsy etc]# vim /etc/sysctl.conf
在末尾添加以下内容:
fs.aio-max-nr = 1048576
fs.file-max = 6815744
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
查看是否成功写进/etc/sysctl.conf文件中:
[root@myYUn software]# sysctl -p
其中kernel.shmmax = 1073741824为本机物理内存(2G)的一半,单位为byte。
8.修改用户的限制文件
修改/etc/security/limits.conf文件:
[root@zsy etc]# vim /etc/security/limits.conf
在末尾添加以下内容:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
修改/etc/pam.d/login文件:
[root@zsy etc]# vim /etc/pam.d/login
在末尾添加以下内容:
session required /lib64/security/pam_limits.so
session required pam_limits.so
修改/etc/profile文件:
[root@zsy etc]# vim /etc/profile
在末尾添加以下内容:
#oracle配置
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
9.创建安装目录和设置文件权限
[root@zsy ~]# mkdir -p /home/data/oracle11/oracle/product/11.2.0
[root@zsy ~]# mkdir -p /home/data/oracle11/oracle/oradata
[root@zsy ~]# mkdir -p /home/data/oracle11/oracle/inventory
[root@zsy ~]# mkdir -p /home/data/oracle11/oracle/fast_recovery_area
[root@zsy ~]# chown -R oracle:oinstall /home/data/oracle11/oracle
[root@zsy ~]# chmod -R 775 /home/data/oracle11/oracle
10.设置oracle用户环境变量
首先切换到oracle用户下:
[root@myYUn software]# su -l oracle
[oracle@myYUn ~]$ vim .bash_profile
在末尾添加如下内容:
ORACLE_BASE=/home/data/oracle11/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
注意,标红处必须与创建的数据库实例名称一致,否则数据库启动后无法访问。第一次配置完记得source一下。
[oracle@zsy ~]$ source .bash_profile
11.编辑静默安装响应文件
复制安装文件夹response到当前oracle用户的家目录下:
[root@zsy home]# su - oracle
[oracle@zsy ~]$ cp -R /home/database/response/ .
[oracle@zsy ~]$ cd response/
[oracle@zsy response]$ vim db_install.rsp
需要设置的选项如下:
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=CentOS
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/data/oracle11/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/home/data/oracle11/oracle/product/11.2.0
ORACLE_BASE=/home/data/oracle11/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
12.根据响应文件静默安装Oracle11g
[oracle@zsy response]$ cd /home/database/
[oracle@zsy database]$ ./runInstaller -silent -responseFile /home/database/response/db_install.rsp –ignorePrereq
开始Oracle在后台静默安装。安装过程中,如果提示[WARNING]不必理会,此时安装程序仍在后台进行,如果出现Successfully Setup Software,则安装程序已经停止了。
可以在以下位置找到本次安装会话的日志:/home/data/oracle11/oracle/inventory/logs/installActions2020-01-19_04-55-30AM.log
可以切换终端执行top命令查看后台进程一直是在安装的,/data目录也在不断增大,
当出现以下提示时,代表安装成功:
按照要求执行脚本。
打开终端,退出到root身份登录,执行脚本
[oracle@zsy database]$ exit
Logout
[root@zsy ~]# sh /home/data/oracle11/oracle/inventory/orainstRoot.sh
Changing permissions of /home/data/oracle11/oracle/inventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /home/data/oracle11/oracle/inventory to oinstall.
The execution of the script is complete.
[root@zsy ~]# sh /home/data/oracle11/oracle/product/11.2.0/root.sh
13.以静默方式配置监听
重新使用oracle用户登录
[root@zsy ~]# su -l oracle
注意此处,必须使用/silent /responseFile格式,而不是-silent -responseFile,因为是静默安装
[oracle@zsy ~]$ netca /silent /responseFile /home/database/response/netca.rsp/
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /home/database/response/netca.rsp/
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/home/data/oracle11/oracle/product/11.2.0/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
成功运行后,在/home/data/oracle11/oracle /product/11.2.0/network/admin中生成listener.ora和sqlnet.ora
Yum安装netstat软件,软件包是在net-tools中。
[oracle@zsy ~]$ su - root
Password:
[root@zsy ~]# yum install net-tools
通过netstat命令可以查看1521端口正在监听
[root@zsy ~]# netstat -tnulp | grep 1521
14.以静默方式建立新库,同时也建立一个对应的实例
[oracle@zsy ~]$ vim /home/oracle/response/dbca.rsp
修改文件中以下参数:
[GENERAL]
# oracle版本,不能更改
RESPONSEFILE_VERSION = "11.2.0"
# Description : Type of operation
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
# Description : Global database name of the database
# 全局数据库的名字=SID+主机域名
# 第三方工具链接数据库的时候使用的service名称
GDBNAME = "orcl"
# Description : System identifier (SID) of the database
# 对应的实例名字
SID = "orcl"
# Description : Name of the template
# 建库用的模板文件
TEMPLATENAME = "General_Purpose.dbc"
# Description : Password for SYS user
# SYS管理员密码
SYSPASSWORD = "123456"
# Description : Password for SYSTEM user
# SYSTEM管理员密码
SYSTEMPASSWORD = "123456"
# Description : Password for SYSMAN user
# SYSMAN管理员密码
SYSMANPASSWORD = "123456"
# Description : Password for DBSNMP user
# DBSNMP管理员密码
DBSNMPPASSWORD = "123456"
# Description : Location of the data file's
# 数据文件存放目录
DATAFILEDESTINATION =/home/data/oracle11/oracle/oradata
# Description : Location of the data file's
# 恢复数据存放目录
RECOVERYAREADESTINATION=/home/data/oracle11/oracle/fast_recovery_area
# Description : Character set of the database
# 字符集,重要!!! 建库后一般不能更改,所以建库前要确定清楚。
# (CHARACTERSET = "AL32UTF8" NATIONALCHARACTERSET= "UTF8")
CHARACTERSET = "UTF8"
# Description : total memory in MB to allocate to Oracle
# oracle内存1638MB,物理内存2G*80%
TOTALMEMORY = "1638"
进行静默配置:
[oracle@zsy ~]$ dbca -silent -responseFile /home/oracle/response/dbca.rsp
建库后进行实例进程检查:
[oracle@zsy ~]$ ps -ef | grep ora_ | grep -v grep
查看监听状态:
[oracle@zsy ~]$ lsnrctl status
数据库创建完成。
有关详细信息, 请查看以下位置的日志文件: /home/data/oracle11/oracle/cfgtoollogs/dbca/orcl/orcl.log
数据库信息:
全局数据库名:orcl
系统标识符 (SID):orcl
登录查看实例状态
[oracle@zsy orcl]$ sqlplus / as sysdba
SQL> select status from v$instance;
15.Oracle安装成功后,创建一个登录账户
1、切换到oracle用户下su -l oracle
2、使用sysdba账户登录:
[oracle@zsy orcl]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sun Jan 19 06:22:23 2020
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
3、创建用户
语法:CREATE USER 用户名 IDENTIFIED BY 密码
SQL> create user admin identified by 123456;
4、将刚创建的用户解锁/锁住
语法:ALTER USER 用户名 ACCOUNT UNLOCK/LOCK
//用户解锁
SQL> alter user admin account unlock;
//用户锁住 (知道该命令就行,不要随便锁定用户)
SQL> alter user admin account lock;
4、授予新登陆的用户创建权限:
语法:CRANT CREATE SESSION TO 用户名
SQL> grant create session to admin;
5、授予新创建的用户数据库管理员权限
语法:CRANT DBA TO 用户名;
SQL> grant dba to admin;
.
6、切换到新创建的用户登陆
语法:CONNECT 用户名/密码
SQL> connect admin/123456;
7、删除用户
语法:DROP USER 用户名
Drop user admin;