欢迎阅读!

潇湘夜雨

当前位置: 主页 > 数据库 >

oracle在centos7静默安装和开机启动配置

时间:2018-07-25 14:39来源:潇湘夜雨 作者:华嵩阳 点击:
一、安装前准备 系统:centos7.2 oracle版 本:linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip [root@localhost ~]# hostname oracle11 vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost
一、安装前准备
 
系统:centos7.2
oracle版本:linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip
 
[root@localhost ~]# hostname oracle11
vim /etc/hosts
 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.80.130  oracle11
 
1、安装依赖包
yum install  gcc gcc-c++ binutils ksh compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-common glibc-devel glibc-devel libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel
 
以下是官方要求的依赖包(包含32和64,根据实际选择:
binutils-2.20.51.0.2-5.11.el6 (x86_64) \
compat-libcap1-1.10-1 (x86_64) \
compat-libstdc++-33-3.2.3-69.el6 (x86_64) \
compat-libstdc++-33-3.2.3-69.el6.i686 \
gcc-4.4.4-13.el6 (x86_64)
gcc-c++-4.4.4-13.el6 (x86_64)
glibc-2.12-1.7.el6 (i686)
glibc-2.12-1.7.el6 (x86_64)
glibc-devel-2.12-1.7.el6 (x86_64)
glibc-devel-2.12-1.7.el6.i686
ksh
libgcc-4.4.4-13.el6 (i686)
libgcc-4.4.4-13.el6 (x86_64)
libstdc++-4.4.4-13.el6 (x86_64)
libstdc++-4.4.4-13.el6.i686
libstdc++-devel-4.4.4-13.el6 (x86_64)
libstdc++-devel-4.4.4-13.el6.i686
libaio-0.3.107-10.el6 (x86_64)
libaio-0.3.107-10.el6.i686
libaio-devel-0.3.107-10.el6 (x86_64)
libaio-devel-0.3.107-10.el6.i686
make-3.81-19.el6
sysstat-9.0.4-11.el6 (x86_64)
unixODBC 
unixODBC-devel
 
 
 
2.创建所需的操作系统组和用户
 
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
 
设置oracle用户密码
[root@oracle11 ~]# passwd oracle
更改用户 oracle 的密码 。
新的 密码:oracle11
无效的密码: 密码包含用户名在某些地方
重新输入新的 密码:oracle11
passwd:所有的身份验证令牌已经成功更新。
 
3、关闭selinux
 
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config 
[root@localhost ~]# cat /etc/selinux/config 
 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
 
 
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
 
4.修改内核参数
 
在/sbin/sysctl.conf 文件中,使用文本编辑器或vi命令增加或修改以下参数 (vi /sbin/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
 
修改后,使设置生效
 
/sbin/sysctl -p
 
5.修改用户限制
 
在/etc/security/limits.conf 文件中,使用文本编辑器或vi命令
 
vi /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 文件中,使用文本编辑器或vi命令增加或修改以下内容
 
session required pam_limits.so
 
在/etc/profile 文件中,使用文本编辑器或vi命令增加或修改以下内容
 
 
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
使设置生效
 
source /etc/profile
 
6.创建安装目录(可根据情况,选择比较多空间的目录创建)
 
 
#新点
[root@oracle11 ~]# mkdir -p /u01/app/oracle/product/11.2.0
[root@oracle11 ~]# mkdir /u01/app/oracle/oradata
[root@oracle11 ~]# mkdir /u01/app/oracle/inventory
[root@oracle11 ~]# mkdir /u01/app/oracle/fast_recovery_area
[root@oracle11 ~]# chown -R oracle:oinstall /u01/app/oracle
[root@oracle11 ~]# chmod -R 775 /u01/app/oracle
 
chown -R oracle.oinstall /u01/ #给安装目录授权
 
7.创建/etc/oraInst.loc文件,内容如下
 
[root@localhost ~]# vim /etc/oraInst.loc
 
nventory_loc=/usr/oracle/oraInventory
inst_group=oinstall
 
更改文件的权限
 
chown oracle:oinstall /etc/oraInst.loc
chmod 664 /etc/oraInst.loc
 
8.设置oracle环境变量
 
su - oracle    //切换用户到oracle
  
vi ~/.bash_profile  //访问或者创建 home/oracle目录下面的.bash_profile文件
 
在最后加上以下内容
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
ORACLE_UNQNAME=orcl
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID ORACLE_UNQNAME PATH
 
source /home/oracle/.bash_profile
 
检查环境变量:
 
env
 
同时,在使用静默安装的时候会检查DISPLAY的设置,如果经常说检查DISPLAY不行的话,到root用户下执行“xhost + 你的ip:0.0“
/usr/bin/xdpyinfo命令不存在安装如下包
[root@localhost ~]# yum install xorg-x11-utils
 
9.解压oracle安装文件
 
unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip
 
解压后的文件都在database目录下
cd database
 
 
10.编辑静默安装响应文件
 
[oracle@oracle11 database]$ cd response/
[oracle@oracle11 response]$ ls -lh
总用量 76K
-rw-rw-r-- 1 oracle oinstall  44K 2月  14 2009 dbca.rsp
-rw-rw-r-- 1 oracle oinstall  23K 8月  15 2009 db_install.rsp
-rwxrwxr-x 1 oracle oinstall 5.7K 2月  26 2009 netca.rsp
[oracle@oracle11 response]$ cp db_install.rsp db_install.rsp.bak
[oracle@oracle11 database]$ [oracle@oracle11 ~]$ cp -r packge/database/response/ ./
 
vim /home/oracle/response/db_install.rsp
需要设置的选项如下:
 
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle11
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/u01/app/oracle/product/11.2.0
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
 
二、根据响应文件静默安装Oracle 11g
[oracle@oracle11 database]$  ./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq
正在启动 Oracle Universal Installer...
 
检查临时空间: 必须大于 120 MB。   实际为 26065 MB    通过
检查交换空间: 必须大于 150 MB。   实际为 2047 MB    通过
准备从以下地址启动 Oracle Universal Installer /tmp/OraInstall2018-07-11_08-42-58PM. 请稍候...[oracle@oracle11 database]$ [WARNING] [INS-32055] 主产品清单位于 Oracle 基目录中。
   原因: 主产品清单位于 Oracle 基目录中。
   操作: Oracle 建议将此主产品清单放置在 Oracle 基目录之外的位置中。
[WARNING] [INS-32055] 主产品清单位于 Oracle 基目录中。
   原因: 主产品清单位于 Oracle 基目录中。
   操作: Oracle 建议将此主产品清单放置在 Oracle 基目录之外的位置中。
可以在以下位置找到本次安装会话的日志:
 /u01/app/oracle/inventory/logs/installActions2018-07-11_08-42-58PM.log
 
 
常见错误:
准备从以下地址启动 Oracle Universal Installer /tmp/OraInstall2018-07-11_08-41-22PM. 请稍候...[oracle@oracle11 database]$ [FATAL] [INS-32012] 无法创建目录。
   原因: 没有授予创建目录的正确权限, 或卷中没有剩余空间。
   操作: 请检查您对所选目录的权限或选择另一个目录。
[FATAL] [INS-32012] 无法创建目录。
   原因: 没有授予创建目录的正确权限, 或卷中没有剩余空间。
   操作: 请检查您对所选目录的权限或选择另一个目录。
此会话的日志当前已保存为: /tmp/OraInstall2018-07-11_08-41-22PM/installActions2018-07-11_08-41-22PM.log。如果要保留此日志, Oracle 建议将它从临时位置移动到更持久的位置。
 
解决方法:
chown -R oracle.oinstall /u01/ #给安装目录授权
 
 
 
当出现以下提示时,代表安装成功:
以下配置脚本需要以 "root" 用户的身份执行。
 #!/bin/sh 
 #要运行的 Root 脚本
 
/u01/app/oracle/inventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0/root.sh
要执行配置脚本, 请执行以下操作:
1. 打开一个终端窗口
2. 以 "root" 身份登录
3. 运行脚本
4. 返回此窗口并按 "Enter" 键继续
 
Successfully Setup Software.
 
 
按照要求执行脚本。
打开终端,以root身份登录,执行脚本:
 
[root@oracle11 ~]# /u01/app/oracle/inventory/orainstRoot.sh
更改权限/u01/app/oracle/inventory.
添加组的读取和写入权限。
删除全局的读取, 写入和执行权限。
 
更改组名/u01/app/oracle/inventory 到 oinstall.
脚本的执行已完成。
[root@oracle11 ~]# /u01/app/oracle/product/11.2.0/root.sh
Check /u01/app/oracle/product/11.2.0/install/root_oracle11_2018-07-11_20-49-54.log for the output of root script
 
 
 
三、以静默方式配置监听
重新使用oracle用户登录
[oracle@oracle11 ~]$ netca -silent -responsefile /home/oracle/response/netca.rsp
 
正在对命令行参数进行语法分析:
参数"silent" = true
参数"responsefile" = /home/oracle/response/netca.rsp
完成对命令行参数进行语法分析。
Oracle Net Services 配置:
完成概要文件配置。
Oracle Net 监听程序启动:
正在运行监听程序控制: 
 /u01/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER
监听程序控制完成。
监听程序已成功启动。
监听程序配置完成。
成功完成 Oracle Net Services 配置。退出代码是0
通过netstat命令可以查看1521端口正在监听。
 
[oracle@oracle11 ~]$ netstat -tnlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::1521                 :::*                    LISTEN      2624/tnslsnr        
tcp6       0      0 :::22                   :::*                    LISTEN      -                   
tcp6       0      0 ::1:25                  :::*                    LISTEN      -                   
tcp6       0      0 ::1:6010                :::*                    LISTEN      -                   
tcp6       0      0 ::1:6011                :::*                    LISTEN      -       
成功运行后,在/u01/app/oracle/product/11.2.0/network/admin/中生成listener.ora和sqlnet.ora
 
常见错误:
****DISPLAY environment variable not set!
    Oracle Net Configuration Assistant is a GUI tool
    which requires that DISPLAY specify a location
    where GUI tools can display.
    Set and export DISPLAY, then re-run.
 
错误原因:xshell等工具没开启转发,或者是服务的转发工具和sshd的配置有问题。
 
解决方法:
首先将xshell的转发打开
编辑 /etc/ssh/sshd_config,
 
yum install xorg-x11-xauth
 
同时sshd  的config文件开启X11Forwarding yes
 
如果还是不行,可以手动开启监听,网上有教程。
 
四、以静默方式建立新库,同时也建立一个对应的实例。
[oracle@oracle11 ~]$ vim /home/oracle/response/dbca.rsp
设置以下参数:
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/u01/app/oracle/oradata
RECOVERYAREADESTINATION=/u01/app/oracle/fast_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "1638"
 
其中TOTALMEMORY = "1638" 为1638MB,物理内存2G*80%。
 
进行静默配置:
[oracle@oracle11 ~]$ dbca -silent -responseFile /home/oracle/response/dbca.rsp
 
复制数据库文件
1% 已完成
3% 已完成
11% 已完成
18% 已完成
26% 已完成
37% 已完成
正在创建并启动 Oracle 实例
40% 已完成
45% 已完成
50% 已完成
55% 已完成
56% 已完成
60% 已完成
62% 已完成
正在进行数据库创建
66% 已完成
70% 已完成
73% 已完成
85% 已完成
96% 已完成
100% 已完成
有关详细信息, 请参阅日志文件 "/u01/app/oracle/cfgtoollogs/dbca/orcl/orcl.log"。
 
 
建库后进行实例进程检查:
[oracle@oracle11 ~]$ ps -ef | grep ora_ | grep -v grep
 
[oracle@oracle11 ~]$  ps -ef | grep ora_ | grep -v grep
oracle     4890      1  0 11:27 ?        00:00:00 ora_pmon_orcl
oracle     4892      1  0 11:27 ?        00:00:00 ora_vktm_orcl
oracle     4896      1  0 11:27 ?        00:00:00 ora_gen0_orcl
oracle     4898      1  0 11:27 ?        00:00:00 ora_diag_orcl
oracle     4900      1  0 11:27 ?        00:00:00 ora_dbrm_orcl
oracle     4902      1  0 11:27 ?        00:00:00 ora_psp0_orcl
oracle     4904      1  0 11:27 ?        00:00:00 ora_dia0_orcl
oracle     4906      1  0 11:27 ?        00:00:00 ora_mman_orcl
oracle     4908      1  0 11:27 ?        00:00:00 ora_dbw0_orcl
oracle     4910      1  0 11:27 ?        00:00:00 ora_lgwr_orcl
oracle     4912      1  0 11:27 ?        00:00:00 ora_ckpt_orcl
oracle     4914      1  0 11:27 ?        00:00:00 ora_smon_orcl
oracle     4916      1  0 11:27 ?        00:00:00 ora_reco_orcl
oracle     4918      1  0 11:27 ?        00:00:00 ora_mmon_orcl
oracle     4920      1  0 11:27 ?        00:00:00 ora_mmnl_orcl
oracle     4922      1  0 11:27 ?        00:00:00 ora_d000_orcl
oracle     4924      1  0 11:27 ?        00:00:00 ora_s000_orcl
oracle     5000      1  0 11:27 ?        00:00:00 ora_qmnc_orcl
oracle     5015      1  0 11:27 ?        00:00:00 ora_cjq0_orcl
oracle     5017      1  0 11:27 ?        00:00:00 ora_q000_orcl
oracle     5019      1  0 11:27 ?        00:00:00 ora_q001_orcl
 
查看监听状态:
[oracle@oracle11 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 12-JUL-2018 11:28:59
 
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                12-JUL-2018 07:59:28
Uptime                    0 days 3 hr. 29 min. 31 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/oracle11/listener/alert/log.xml
Listening Endpoints Summary...
 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
 Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
 Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
 
 
登录查看实例状态:
[oracle@oracle11 ~]$ sqlplus / as sysdba
SQL> select status from v$instance;
 
STATUS
------------
OPEN
 
 
 
 
五、Oracle开机自启动设置
 
(一)service服务类型
service服务这样是centos6之前的版本的,在centos7中也可以用,只不过centos7采用systemctl这种方式管理
服务,性能更高效,如果两种方式都有,systemctl的优先级更高。
 
1.修改/u01/app/oracle/product/11.2.0/bin/dbstart
[oracle@oracle11 ~]$ vim /u01/app/oracle/product/11.2.0/bin/dbstart
将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=$ORACLE_HOME
 
2.修改/u01/app/oracle/product/11.2.0/bin/dbshut
[oracle@oracle11 ~]$ vim /u01/app/oracle/product/11.2.0/bin/dbshut
将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=$ORACLE_HOME
 
3.修改/etc/oratab文件
[oracle@oracle11 ~]$ vim /etc/oratab
将orcl:/u01/app/oracle/product/11.2.0:N中最后的N改为Y,成为orcl:/u01/app/oracle/product/11.2.0:Y
4.输入命令dbshut和dbstart测试
[oracle@oracle11 ~]$ dbshut
 
Oracle监听停止,进程消失。
 
[oracle@oracle11 ~]$ dbstart
 
Oracle监听启动,进程启动。
 
5.切换到root账户建立自启动脚本
[oracle@oracle11 ~]$ su -
[root@oracle11 ~]# vim /etc/rc.d/init.d/oracle
添加以下内容(有些值如ORACLE_HOME和ORACLE_USER等根据实际情况可以修改):
 
#!/bin/sh
#chkconfig: 2345 20 80
#description: Oracle dbstart / dbshut
#以上两行为chkconfig所需
ORA_HOME=/u01/app/oracle/product/11.2.0
ORA_OWNER=oracle
LOGFILE=/var/log/oracle.log
echo "#################################" >> ${LOGFILE}
date +"### %T %a %D: Run Oracle" >> ${LOGFILE}
if [ ! -f ${ORA_HOME}/bin/dbstart ] || [ ! -f ${ORA_HOME}/bin/dbshut ]; then
    echo "Error: Missing the script file ${ORA_HOME}/bin/dbstart or ${ORA_HOME}/bin/dbshut!" >> ${LOGFILE}
    echo "#################################" >> ${LOGFILE}
    exit
fi
start(){
    echo "###Startup Database..."
    su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}"
    echo "###Done."
    echo "###Run database control..."
    su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl start dbconsole"
    echo "###Done."
}
stop(){
    echo "###Stop database control..."
    su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl stop dbconsole"
    echo "###Done."
    echo "###Shutdown Database..."
    su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}"
    echo "###Done."
}
case "$1" in
    'start')
        start >> ${LOGFILE}
    ;;
    'stop')
        stop >> ${LOGFILE}
    ;;
    'restart')
        stop >> ${LOGFILE}
        start >> ${LOGFILE}
    ;;
esac
date +"### %T %a %D: Finished." >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
echo ""
 
 
6.修改/etc/init.d/oracle服务文件权限
 
[root@oracle11 ~]# vim /etc/rc.d/init.d/oracle
[root@oracle11 ~]# chmod +x /etc/rc.d/init.d/oracle 
[root@oracle11 ~]# service oracle stop
Reloading systemd:                                         [  确定  ]
Stopping oracle (via systemctl):                           [  确定  ]
 
7.设置为开机启动
[root@oracle11 ~]# chkconfig oracle on
 
8.进行service oracle start/stop测试
 
9.Reboot重启查看Oracle监听和实例进程均能自动启动。
 
(二)systemctl 服务类型
 
注意:采用systemctl服务启动oracle,启动监听的参数要配置成绝对路径,不然1521端口可能无法启动。
vim /u01/app/oracle/product/11.2.0/bin/dbstart
#ORACLE_HOME_LISTNER=$ORACLE_HOME
ORACLE_HOME_LISTNER=/u01/app/oracle/product/11.2.0
 
1、添加脚本
[root@oracle11 ~]# vim /usr/lib/systemd/system/oracle.service
 
[Unit]
Description=The oracle11g database
After=network.target remote-fs.target 
 
[Service]
User=oracle
Type=forking
# oracle will fail to start if /run/oralce.pid already exists but has the wrong
# SELinux context. This might happen when running `oralce -t` from the cmdline.
#ExecStart=/bin/bash /home/oracle/start.sh
#ExecStartPre=/home/oracle/.bash_profile
ExecStart=/u01/app/oracle/product/11.2.0/bin/dbstart
ExecStop=/u01/app/oracle/product/11.2.0/bin/dbshut
RestartSec=2s
 
[Install]
WantedBy=multi-user.target
 
 
[root@oracle11 ~]# systemctl daemon-reload #重新加载启动脚本,否则可能无效。
[root@oracle11 ~]# systemctl start oracle
[root@oracle11 ~]# systemctl status oracle #查看启动状态
● oracle.service - The oracle11g database
   Loaded: loaded (/usr/lib/systemd/system/oracle.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2018-07-14 16:29:12 CST; 4s ago
  Process: 2154 ExecStop=/u01/app/oracle/product/11.2.0/bin/dbshut (code=exited, status=0/SUCCESS)
  Process: 2314 ExecStart=/u01/app/oracle/product/11.2.0/bin/dbstart (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/oracle.service
           ├─2322 /u01/app/oracle/product/11.2.0/bin/tnslsnr LISTENER -inherit
           ├─2480 ora_pmon_orcl
           ├─2482 ora_vktm_orcl
           ├─2486 ora_gen0_orcl
           ├─2488 ora_diag_orcl
           ├─2490 ora_dbrm_orcl
           ├─2492 ora_psp0_orcl
           ├─2494 ora_dia0_orcl
           ├─2496 ora_mman_orcl
           ├─2498 ora_dbw0_orcl
           ├─2500 ora_lgwr_orcl
           ├─2502 ora_ckpt_orcl
           ├─2504 ora_smon_orcl
           ├─2506 ora_reco_orcl
           ├─2508 ora_mmon_orcl
           ├─2510 ora_mmnl_orcl
           ├─2512 ora_d000_orcl
           ├─2514 ora_s000_orcl
           ├─2573 ora_qmnc_orcl
           └─2651 ora_cjq0_orcl
 
7月 14 16:29:05 oracle11 systemd[1]: Starting The oracle11g database...
7月 14 16:29:07 oracle11 dbstart[2314]: Processing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/startup.log
7月 14 16:29:12 oracle11 systemd[1]: Started The oracle11g database.
[root@oracle11 ~]# netstat -tnlp|grep 1521
tcp6       0      0 :::1521                 :::*                    LISTEN      2322/tnslsnr        
 
[root@oracle11 ~]# systemctl enable oracle #使oracle服务开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/oracle.service to /usr/lib/systemd/system/oracle.service.
 
[root@oracle11 system]# systemctl is-enabled oracle #查看oracle是否开机启动
enabled
 
六、扩展
 
1、EMCA管理
[oracle@oracle11 ~]$ emctl start dbconsole
OC4J Configuration issue. /u01/app/oracle/product/11.2.0/oc4j/j2ee/OC4J_DBConsole_oracle11_orcl not found. 
安装的Oracle默认没有配置EM,下面记录下配置和启动过程!
首先创建EM,执行下面的命令
[oracle@oracle11 ~]$ emca -config dbcontrol db -repos recreate
 
EMCA 开始于 2018-7-12 18:42:57
EM Configuration Assistant, 11.2.0.0.2 正式版
版权所有 (c) 2003, 2005, Oracle。保留所有权利。
 
输入以下信息:
数据库 SID: orcl
Exception in thread "main" oracle.sysman.emcp.exception.DatabaseUnavailableException: 数据库实例不可用。
at oracle.sysman.emcp.DatabaseChecks.throwDBUnavailableException(DatabaseChecks.java:151)
at oracle.sysman.emcp.DatabaseChecks.checkDbAvailabilityImpl(DatabaseChecks.java:139)
at oracle.sysman.emcp.DatabaseChecks.checkDbAvailability(DatabaseChecks.java:163)
at oracle.sysman.emcp.DatabaseChecks.getDbServiceName(DatabaseChecks.java:582)
at oracle.sysman.emcp.EMConfigAssistant.performConfiguration(EMConfigAssistant.java:1267)
at oracle.sysman.emcp.EMConfigAssistant.statusMain(EMConfigAssistant.java:573)
at oracle.sysman.emcp.EMConfigAssistant.main(EMConfigAssistant.java:521)
 
错误解决方法:
 
[oracle@oracle11 ~]$ emca -repos drop
 
EMCA 开始于 2018-7-12 18:51:44
EM Configuration Assistant, 11.2.0.0.2 正式版
版权所有 (c) 2003, 2005, Oracle。保留所有权利。
 
输入以下信息:
数据库 SID: orcl
监听程序端口号: 1521
SYS 用户的口令:  oracle
SYSMAN 用户的口令:  oracle
 
是否继续? [是(Y)/否(N)]: y
2018-7-12 18:52:13 oracle.sysman.emcp.EMConfig perform
信息: 正在将此操作记录到 /u01/app/oracle/cfgtoollogs/emca/orcl/emca_2018_07_12_18_51_44.log。
2018-7-12 18:52:14 oracle.sysman.emcp.ParamsManager checkListenerStatusForDBControl
警告: 初始化 SQL 连接时出错。无法执行 SQL 操作
2018-7-12 18:52:14 oracle.sysman.emcp.EMReposConfig invoke
信息: 正在删除 EM 资料档案库 (此操作可能需要一段时间)...
2018-7-12 18:52:14 oracle.sysman.emcp.util.PlatformInterface executeCommand
警告: 执行 /u01/app/oracle/product/11.2.0/sysman/admin/emdrep/bin/RepManager -connect (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle11)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl))) -repos_user SYSMAN -action drop -verbose -output_file /u01/app/oracle/cfgtoollogs/emca/orcl/emca_repos_drop_2018_07_12_18_52_14.log  时出错
2018-7-12 18:52:14 oracle.sysman.emcp.EMReposConfig invoke
严重: 删除资料档案库时出错。
2018-7-12 18:52:14 oracle.sysman.emcp.EMReposConfig invoke
信息: 有关详细资料, 请参阅 /u01/app/oracle/cfgtoollogs/emca/orcl/emca_repos_drop_<日期>.log 中的日志文件。
2018-7-12 18:52:14 oracle.sysman.emcp.EMConfig perform
严重: 删除资料档案库时出错。
有关详细资料, 请参阅 /u01/app/oracle/cfgtoollogs/emca/orcl/emca_2018_07_12_18_51_44.log 中的日志文件。
无法完成配置。 有关详细资料, 请参阅 /u01/app/oracle/cfgtoollogs/emca/orcl/emca_2018_07_12_18_51_44.log 中的日志文件。
 
[oracle@oracle11 ~]$ emca -config dbcontrol db -repos recreate #然后重新开始创建EM
 
EMCA 开始于 2018-7-12 18:53:21
EM Configuration Assistant, 11.2.0.0.2 正式版
版权所有 (c) 2003, 2005, Oracle。保留所有权利。
 
输入以下信息:
数据库 SID: orcl
监听程序端口号: 1521
监听程序 ORACLE_HOME [ /u01/app/oracle/product/11.2.0 ]: 
SYS 用户的口令:  oracle
DBSNMP 用户的口令: oracle 
SYSMAN 用户的口令:  oracle
通知的电子邮件地址 (可选): 
通知的发件 (SMTP) 服务器 (可选): 
-----------------------------------------------------------------
 
已指定以下设置
 
数据库 ORACLE_HOME ................ /u01/app/oracle/product/11.2.0
 
本地主机名 ................ oracle11
监听程序 ORACLE_HOME ................ /u01/app/oracle/product/11.2.0
监听程序端口号 ................ 1521
数据库 SID ................ orcl
通知的电子邮件地址 ............... 
通知的发件 (SMTP) 服务器 ............... 
 
-----------------------------------------------------------------
是否继续? [是(Y)/否(N)]: y
2018-7-12 18:53:58 oracle.sysman.emcp.EMConfig perform
信息: 正在将此操作记录到 /u01/app/oracle/cfgtoollogs/emca/orcl/emca_2018_07_12_18_53_21.log。
2018-7-12 18:53:59 oracle.sysman.emcp.EMReposConfig invoke
信息: 正在删除 EM 资料档案库 (此操作可能需要一段时间)...
2018-7-12 18:55:19 oracle.sysman.emcp.EMReposConfig invoke
信息: 已成功删除资料档案库
2018-7-12 18:55:19 oracle.sysman.emcp.EMReposConfig createRepository
信息: 正在创建 EM 资料档案库 (此操作可能需要一段时间)...
2018-7-12 18:59:34 oracle.sysman.emcp.EMReposConfig invoke
信息: 已成功创建资料档案库
2018-7-12 18:59:41 oracle.sysman.emcp.EMReposConfig uploadConfigDataToRepository
信息: 正在将配置数据上载到 EM 资料档案库 (此操作可能需要一段时间)...
2018-7-12 19:00:26 oracle.sysman.emcp.EMReposConfig invoke
信息: 已成功上载配置数据
2018-7-12 19:00:28 oracle.sysman.emcp.util.DBControlUtil configureSoftwareLib
信息: 软件库已配置成功。
2018-7-12 19:00:28 oracle.sysman.emcp.EMDBPostConfig configureSoftwareLibrary
信息: 正在部署预配档案...
2018-7-12 19:01:02 oracle.sysman.emcp.EMDBPostConfig configureSoftwareLibrary
信息: 预配档案部署成功。
2018-7-12 19:01:02 oracle.sysman.emcp.util.DBControlUtil secureDBConsole
信息: 正在保护 Database Control (此操作可能需要一段时间)...
2018-7-12 19:01:06 oracle.sysman.emcp.util.PlatformInterface executeCommand
警告: 执行 /u01/app/oracle/product/11.2.0/bin/emctl secure dbconsole -host oracle11 -sid orcl  时出错
2018-7-12 19:01:06 oracle.sysman.emcp.EMDBPostConfig performConfiguration
警告: 保护 Database control 时出错。
2018-7-12 19:01:06 oracle.sysman.emcp.EMDBPostConfig setWarnMsg
信息: 保护 Database Control 时出错, Database Control 已在非安全模式下启动。要保护 Database Control, 请执行以下命令: 
 
 1) 将环境变量 ORACLE_SID 设置为 orcl 
 2) /u01/app/oracle/product/11.2.0/bin/emctl stop dbconsole 
 3) /u01/app/oracle/product/11.2.0/bin/emctl config emkey -repos -sysman_pwd < SYSMAN 用户的口令 >  
 4) /u01/app/oracle/product/11.2.0/bin/emctl secure dbconsole -sysman_pwd < SYSMAN 用户的口令 >  
 5) /u01/app/oracle/product/11.2.0/bin/emctl start dbconsole 
 
 要保护 EM 密钥, 请运行 /u01/app/oracle/product/11.2.0/bin/emctl config emkey -remove_from_repos -sysman_pwd < SYSMAN 用户的口令 >
2018-7-12 19:01:06 oracle.sysman.emcp.util.DBControlUtil startOMS
信息: 正在启动 Database Control (此操作可能需要一段时间)...
2018-7-12 19:01:11 oracle.sysman.emcp.EMDBPostConfig performConfiguration
信息: 已成功启动 Database Control
2018-7-12 19:01:11 oracle.sysman.emcp.EMDBPostConfig performConfiguration
信息: >>>>>>>>>>> Database Control URL 为 http://oracle11:1158/em <<<<<<<<<<<
 
 
保护 Database Control 时出错, Database Control 已在非安全模式下启动。要保护 Database Control, 请执行以下命令: 
 
 1) 将环境变量 ORACLE_SID 设置为 orcl 
 2) /u01/app/oracle/product/11.2.0/bin/emctl stop dbconsole 
 3) /u01/app/oracle/product/11.2.0/bin/emctl config emkey -repos -sysman_pwd < SYSMAN 用户的口令 >  
 4) /u01/app/oracle/product/11.2.0/bin/emctl secure dbconsole -sysman_pwd < SYSMAN 用户的口令 >  
 5) /u01/app/oracle/product/11.2.0/bin/emctl start dbconsole 
 
 要保护 EM 密钥, 请运行 /u01/app/oracle/product/11.2.0/bin/emctl config emkey -remove_from_repos -sysman_pwd < SYSMAN 用户的口令 >
[oracle@oracle11 ~]$ netstat -tnlp|grep 1158
(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 :::1158                 :::*                    LISTEN      22484/java      
 
[oracle@oracle11 ~]$ emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0 
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
http://oracle11:1158/em/console/aboutApplication
EM Daemon is  running.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/11.2.0/oracle11_orcl/sysman/log 
 
 
打开浏览器,输入https:/localhost:1158/em,可打开Database Control管理界面,则Oracle已经开始运行了。
用户名:sys
密码:oracle
 
 
2、oracle常用命令
创建表空间:
 create tablespace mobilespace datafile '/u01/app/oracle/oradata/orcl/mobile.dbf' size 500M autoextend on next 500m maxsize 1000m extent management local;
 
 Tablespace created.
 
 创建用户并指定表空间
 create user mobile identified by mobile default tablespace mobilespace;
 User created.
 
 用户授权
grant connect,resource,dba to mobile;
 
[oracle@oracle11 ~]$ sqlplus mobile/mobile@oracle11:1521/orcl
 
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jul 12 20:16:35 2018
 
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 username,default_tablespace from user_users;
 
USERNAME       DEFAULT_TABLESPACE
------------------------------ ------------------------------
MOBILE       MOBILESPACE
 
 
SQL> create table roster(c1 int primary key,c2 varchar(20) not null);
 
Table created.
 
SQL> desc roster;
 Name   Null?    Type
 ----------------------------------------- -------- ----------------------------
 C1   NOT NULL NUMBER(38)
 C2   NOT NULL VARCHAR2(20)
SQL> select * from roster;
 
C1 C2
---------- --------------------
1 liang
 
(责任编辑:liangzh)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
推荐内容