Centos7 安装Oracle 11g
2020-11-30 本文已影响0人
我问你瓜保熟吗
- 修改主机名
hostnamectl set-hostname oracledb
cat /etc/hosts
192.168.*.* oracledb
- 关闭selinux和防火墙
sed 's/SELINUX=.*/SELINUX=disabled/g' -i /etc/selinux/config
setenforce 0 # 立即生效
systemctl stop firewalld.service
systemctl disable firewalld.service
- 创建oracle用户及用户组
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle
oracle
- 为oracle账户添加免密码sudo权限
echo "oracle ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
- 安装依赖
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
- 创建安装目录
mkdir -p /opt/oracle
chown oracle:oinstall /opt/oracle
chmod 755 /opt/oracle
mkdir -p /opt/oraInventory
chown oracle:oinstall /opt/oraInventory
chmod 755 /opt/oraInventory
- oracle 用户环境变量
echo >> /home/oracle/.bashrc << EOM
export ORACLE_BASE=/opt/oracle # oracle安装目录
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 # oracle home目录
export ORACLE_SID=orcl # oracle实例名
export ORACLE_PID=oracle11g.pid
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export LANG="zh_CN.UTF-8"
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
export PATH=$PATH:$ORACLE_HOME/bin
EOM
source ~/.bash_profile
- 设置内核参数
echo >> /etc/sysctl.conf << EOM
fs.aio-max-nr = 1048576
fs.file-ax = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100128
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 = 1048586
EOM
sysctl -p # 立即生效内核参数
- 设置PAM资源限制
echo >> /etc/security/limits.conf << EOM
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
EOM
- 准备安装包
tar xf linux.x64_11gR2_database_1of2.zip -C /home/oracle
tar xf linux.x64_11gR2_database_2of2.zip -C /home/oracle
chown -R oracle:oinstall /home/oracle/database
- 修改信息
vim /home/oracle/database/response/db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY # 安装类型
ORACLE_HOSTNAME=oracledb # 主机名称(hostname查询)
UNIX_GROUP_NAME=oinstall # 安装组
INVENTORY_LOCATION=/opt/oraInventory # INVENTORY目录(不填就是默认值)
SELECTED_LANGUAGES=en,zh_CN # 选择语言
ORACLE_HOME=/opt/oracle/product/11.2.0/db_1 # oracle_home
ORACLE_BASE=/opt/oracle # oracle_base
oracle.install.db.InstallEdition=EE # oracle版本
oracle.install.db.isCustomInstall=false # 自定义安装,否,使用默认组件
oracle.install.db.DBA_GROUP=dba # dba用户组
oracle.install.db.OPER_GROUP=oinstall # oper用户组
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.memoryLimit=81920 # 自动管理内存的内存(M)
oracle.install.db.config.starterdb.password.ALL=oracle # 设定所有数据库用户使用同一个密码
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
- 安装
/home/oracle/database/runInstaller -silent -responseFile /home/oracle/database/response/db_install.rsp
- 上一步执行成功后,执行如下脚本
su
/opt/oraInventory/orainstRoot.sh
/opt/oracle/product/11.2/db_1/root.sh
- 启用监听
su - oracle
export DISPLAY=localhost:0.0
netca -silent -responseFile /home/database/response/netca.rsp
lsnrctl start
lsnrctl status
netstat -tnulp | grep 1521
- 建立数据库实例
su
vim /home/oracle/database/response/dbca.rsp
修改一下参数
GDBNAME = "orcl"
SID = "orcl"
# 密码,根据情况自己设置,也可以不设置,
SYSPASSWORD = "sys"
SYSTEMPASSWORD = "system"
SYSMANPASSWORD = "sysman"
DBSNMPPASSWORD = "dbsnmp"
DATAFILEDESTINATION =/opt/oracle/oradata
RECOVERYAREADESTINATION=/opt/oracle/fast_recovery_area
# 最好设置
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "4096"
- 创建实例
su - oracle
dbca -silent -responseFile /home/database/response/dbca.rsp
- 删除实例
dbca -silent -deleteDatabase -sourcedb orcl
- 监听程序命令
lsnrctl status # 查看监听程序状态
lsnrctl start # 启动监听程序
lsnrctl stop # 停止监听程序
- 实例相关命令
sqlplus / as sysdba # 无口令登录,Oracle采用的是操作系统认证方式,当属于操作系统DBA组用户登陆到数据库服务器,那么Oracle认为这样的用户就可以授权以SYSDBA身份登录数据库
startup # 启动实例
shutdown immediate # 卸载实例
- 表和表空间相关
# 创建 test 表空间,大小为 1G(1024m)
CREATE TABLESPACE test DATAFILE '/home/oracle/data/test.ora' SIZE 1024m;
# 创建 test 用户,密码为 test,关联 test 表空间
CREATE USER test IDENTIFIED BY "test" DEFAULT TABLESPACE test QUOTA 1024m ON USERS;
# 给 test 用户授予权限
GRANT CONNECT,DBA,RESOURCE TO test;