Centos安装Oracle相对比Mysql这些麻烦,不然一个LNMP或者宝塔就搞定的事情。
手动安装,所以把整个过程记录下,顺带做成笔记方便日后和其他人使用。
升级centos的相关软件到最新。
yum update -y
安装一个swap分区,如果是宝塔的话可以在宝塔的后台设置增加。
dd if=/dev/zero of=/swap bs=1024 count=2048000
mkswap /swap
chmod 600 /swap
swapon /swap
echo "/swap swap swap default 1 1">>/etc/fstab #设置成自动挂载
如果你用的是腾讯云或者阿里云等VPS,那么一般会用到数据盘,这里先挂载好自己数据盘,根据下面的教程来操作,并把数据盘挂载到/data目录下。
hostnamectl set-hostname oracledb
echo "127.0.0.1 oracledb" >>/etc/hosts
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
官方网站:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/
根据自己的服务器,下载相应的软件,我的系统是64位的,所以下载的是 Linux x86-64的,下载完的两个文件如下
- linux.x64_11gR2_database_1of2.zip 1.15G
- linux.x64_11gR2_database_2of2.zip 1.04G
因为oracle官方下载安装包需要登录oracle官网才能下载,无图形化只能是先在下到自己的电脑上再上传到VPS中安装。
yum -y install 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
安装完成后,检查依赖是否安装成功
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 | grep "not installed"
如果要安装Oracle数据库,则需要以下本地操作系统组和用户:
- Oracle inventory组(通常为 oinstall)
- OSDBA组 (通常为 dba)
- OSOPER组 (通常为 oper)
- Oracle软件所有者(通常为 oracle)
添加命令:
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba oracle
修改oracle用户密码
passwd oracle
这里不要忘记了oracle的密码!
在/etc/sysctl.conf添加如下参数,如果系统中某个参数高于下面的参数的值 ,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能,具体的参数介绍百度看看就可以。
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
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
将上面的内容跟着原有内容增加到下面保存即可。
使内核参数生效
sysctl -p
在/etc/security/limits.conf中添加如下参数
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
还是一样拉到最低,增加并保存以上内容。
在/etc/pam.d/login文件中,添加下面内容
session required /lib64/security/pam_limits.so
session required pam_limits.so/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使用/etc/profile文件生效
source /etc/profile
- 禁用使用Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages)
7-1、查看是否启用 如果显示 [always]说明启用了
cat /sys/kernel/mm/transparent_hugepage/enabled
7-2、禁用Transparent HugePages,在/etc/grub.conf添加如下内容
echo never > /sys/kernel/mm/transparent_hugepage/enabled
重新启动系统以使更改成为永久更改
reboot
mkdir -p /data/app/
chown -R oracle:oinstall /data/app/
chmod -R 775 /data/app/
这里我们建立oracle相关的文件就在刚才我们挂载的/data目录下面。
在文件/home/oracle/.bash_profile里添加下面内容(具体值根据实际情况修改),相关参数具体百度。
umask 022
export ORACLE_HOSTNAME=oracledb
export ORACLE_BASE=/data/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export ORACLE_SID=ORCL
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
如果自行修改,请注意上面的文件路径。完成后重启系统。
reboot
unzip -q linux.x64_11gR2_database_1of2.zip -d /data
unzip -q linux.x64_11gR2_database_2of2.zip -d /data
mkdir -p /data/etc
cp /data/database/response/* /data/etc/
解压文件并将相关文件移动到相关文件夹中。
在/data/etc/db_install.rsp修改以下变量的值
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=oracledb
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
这里如果不好修改,可以把文件下载到本地,搜索查找相关配置进行修改,完成后再上传覆盖源文件。
su - oracle
cd /data/database
./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq
安装期间可以使用tail命令监看oracle的安装日志,安装过程中会提示你。
You can find the log of this install session at:
/data/app/oracle/inventory/logs/installActions2020-03-19_03-53-45PM.log
tail -f /data/app/oracle/inventory/logs/installActions2020-03-19_03-53-45PM.log
安装完成后有如下提示,如果有类似如下提示,说明安装完成。
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run
/data/app/oracle/inventory/orainstRoot.sh
/data/app/oracle/product/11.2.0/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts
4. Return to this window and hit "Enter" key to continue
Successfully Setup Software.
su - root
sh /data/app/oracle/inventory/orainstRoot.sh
sh /data/app/oracle/product/11.2.0/root.sh
su - oracle
netca /silent /responsefile /data/etc/netca.rsp
输出结果
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /data/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/data/app/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
查看监听端口
netstat -tnpl | grep 1521
tcp6 0 0 :::1521 :::* LISTEN 4821/tnslsnr
编辑应答文件/data/etc/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/data/app/oracle/oradata
RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "1638"
配置文件里面有#注释的需要清除掉。
注意相关用户密码。如果不好编辑也可以下载到本地编辑后上传覆盖。
执行静默建库
su - oracle
dbca -silent -responseFile /data/etc/dbca.rsp
ps.执行完后会先清屏,清屏之后没有提示,直接输入oracle用户的密码,回车,再输入一次,再回车。
执行过程如下
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
57% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
74% complete
85% complete
96% complete
100% complete
Look at the log file "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
查看进程
ps -ef | grep ora_ | grep -v grep
执行结果
oracle 3974 1 0 17:11 ? 00:00:00 ora_pmon_dborcl
oracle 3976 1 0 17:11 ? 00:00:00 ora_vktm_dborcl
oracle 3980 1 0 17:11 ? 00:00:00 ora_gen0_dborcl
oracle 3982 1 0 17:11 ? 00:00:00 ora_diag_dborcl
oracle 3984 1 0 17:11 ? 00:00:00 ora_dbrm_dborcl
oracle 3986 1 0 17:11 ? 00:00:00 ora_psp0_dborcl
oracle 3988 1 0 17:11 ? 00:00:00 ora_dia0_dborcl
oracle 3990 1 0 17:11 ? 00:00:00 ora_mman_dborcl
oracle 3992 1 0 17:11 ? 00:00:00 ora_dbw0_dborcl
oracle 3994 1 0 17:11 ? 00:00:00 ora_lgwr_dborcl
oracle 3996 1 0 17:11 ? 00:00:00 ora_ckpt_dborcl
oracle 3998 1 0 17:11 ? 00:00:00 ora_smon_dborcl
oracle 4000 1 0 17:11 ? 00:00:00 ora_reco_dborcl
oracle 4002 1 3 17:11 ? 00:00:01 ora_mmon_dborcl
oracle 4004 1 0 17:11 ? 00:00:00 ora_mmnl_dborcl
oracle 4006 1 0 17:11 ? 00:00:00 ora_d000_dborcl
oracle 4008 1 0 17:11 ? 00:00:00 ora_s000_dborcl
oracle 4023 1 0 17:11 ? 00:00:00 ora_qmnc_dborcl
oracle 4043 1 0 17:11 ? 00:00:00 ora_cjq0_dborcl
oracle 4068 1 0 17:11 ? 00:00:00 ora_q000_dborcl
oracle 4070 1 0 17:11 ? 00:00:00 ora_q001_dborcl
查看监听状态
lsnrctl status
执行结果
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-MAR-2020 17:13:14
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 19-MAR-2020 08:42:07
Uptime 0 days 8 hr. 31 min. 7 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File /data/app/oracle/diag/tnslsnr/oracledb/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb)(PORT=1521)))
Services Summary...
Service "dborclXDB" has 1 instance(s).
Instance "dborcl", status READY, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "dborcl", status READY, has 1 handler(s) for this service...
The command completed successfully
su - oracle
sqlplus / as sysdba
select status from v$instance;
执行select时,全出现以下情况
SQL> select status from v$instance;
select status from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0
解决方式:
输入startup,
startup的输出提示:
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/data/app/oracle/product/11.2.0/dbs/initORCL.ora'根据提示,将ORACLEBASE/admin/数据库名称/pfile目录下的init.ora.xxx形式的文件copy到ORACLE_BASE/admin/数据库名称/pfile目录下的init.ora.xxx形式的文件copy到ORACLE_HOME/dbs目录下initOracle.ora(根据startup提示)即可
cp /data/app/oracle/admin/orcl/pfile/init.ora.2192020171059 initORCL.ora
查看数据库编码
select userenv('language') from dual;
输出结果
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
AMERICAN_AMERICA.AL32UTF8
SQL>
查看数据库版本
select * from v$version;
输出结果
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
激活scott用户
alter user scott account unlock;
alter user scott identified by tiger;
select username,account_status from dba_users;
修改/data/app/oracle/product/11.2.0/bin/dbstart
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改/data/app/oracle/product/11.2.0/bin/dbshut
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改vi /etc/oratab
orcl:/data/app/oracle/product/11.2.0:Y
新建文件/etc/rc.d/init.d/oracle
! /bin/bash
oracle: Start/Stop Oracle Database 11g R2
chkconfig: 345 90 10
description: The Oracle Database is an Object-Relational Database Management System.
processname: oracle
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_USER=oracle
case "$1" in
'start')
if [ -f $LOCKFILE ]; then
echo $0 already running.
exit 1
fi
echo -n $"Starting Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch $LOCKFILE
;;
'stop')
if [ ! -f $LOCKFILE ]; then
echo $0 already stopping.
exit 1
fi
echo -n $"Stopping Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f $LOCKFILE
;;
'restart')
$0 stop
$0 start
;;
'status')
if [ -f $LOCKFILE ]; then
echo $0 started.
else
echo $0 stopped.
fi
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
esac
exit 0
给/etc/init.d/oracle添加执行权限
chmod +x /etc/init.d/oracle
开机启动oracle
systemctl enable oracle
或
chkconfig oracle on
给启动文件加权限
cd /data/app/oracle/product/11.2.0/bin/
chmod 6751 oracle
cd /var/tmp
chown -R oracle:oinstall .oracle
firewall-cmd --zone=public --add-port=1521/tcp --permanent
firewall-cmd --reload
同时选择你可以用Navicat等工具连接oracle了,如果是云服务器记得打开安全组里的1521端口,否则无法连接。
CREATE TABLESPACE DBNAME DATAFILE '/data/app/dbhome/db.ora' SIZE 10240m;
//“DBNAME" 空间名 “/data/app/dbhome/db.ora” 存储地址
Centos的话可能会因为目录权限导致存储地址创建失败,如果失败的话换为ROOT权限,并赋予权限到目录。
//设置表空间目录权限
chown -R oracle:oinstall /data/app/dbhome/
//新建用户和密码,dbname 用户名, dbpsswd 是密码
create user dbname identified by "dbpsswd";
//赋予数据库操作的基本权限
grant connect,resource,dba to dbname;
到此,Centos7 无图形化界面静默安装Oracle11G R2全部结束,相关表空间及用户名密码也创建完成。