- 使用到的命令:
#windows 探测端口是否打开:
telnet 114.67.110.190 1521
Permission denied
是权限没设好,只是拷贝粘贴一个文件,怎么会这样?
解决的办法:
$ sudo chmod -R 777 myResources
其中
-R 是指级联应用到目录里的所有子目录和文件
777 是所有用户都拥有最高权限
#CentOS 7 启动Oracle
1. 切换用户
su - oracle -- 使用户环境变量生效
cd /home/oracle
source ~/.bash_profile
2. 检查监听
lsnrctl status -- 查看状态
lsnrctl start -- 启动监听
3. 登录SqlPlus
sqlplus /nolog
4. 登录数据库
conn / as sysdba
5. 启动数据库
startup
6. 查看oracle 实例进程
ps -ef | grep ora_ | grep -v grep
1. 安装地址:
Oracle Database Software Downloads 11.2.0.1.0
由于国外地址下载速度太慢使用以下地址:
oracle 11g各种下载地址
http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.zip
http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_2of2.zip
2. 环境搭建
搭建环境:
京东云、centos7.6
vim /etc/hosts
192.168.1.1 ambari.master.com
# 如果是虚拟机请用内网ip
# 一开始没用内网ip 被坑了,1521 端口 ping 不通,找了半天原因
- 安装依赖
- 先安装pdksh
centos7没有相关安装包可用,可下载pdksh的rpm包
wget http://vault.centos.org/5.11/os/x86_64/CentOS/pdksh-5.2.14-37.el5_8.1.x86_64.rpm
rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm
- 安装其他依赖
yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel
- 检查所有依赖是否安装完整
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel | grep "not installed"
- 添加oracle用户组和用户
groupadd oinstall
groupadd dba
groupadd asmadmin
groupadd asmdba
useradd -g oinstall -G dba,asmdba oracle -d /home/oracle
- 查看oracle用户
id oracle
- 为oracle 用户设置密码
passwd oracle
- 优化系统内核
vim /etc/sysctl.conf
#添加下面参数
fs.aio-max-nr=1048576
fs.file-max=6815744
kernel.shmall=2097152
kernel.shmmni=4096
kernel.shmmax = 2147483648
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=1048586
#其中kernel.shmmax为内存的一半,比如内存为4G,则kernel.shmmax=210241024*1024=2147483648
使参数生效
sysctl -p
- 限制oracle用户的shell权限
vim /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
vim /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
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
- 创建oracle相关目录
mkdir -p /db/app/oracle/product/11.2.0
mkdir /db/app/oracle/oradata
mkdir /db/app/oracle/inventory
mkdir /db/app/oracle/fast_recovery_area
chown -R oracle:oinstall /db/app/oracle
chmod -R 775 /db/app/oracle
mkdir -p /u01/app/oracle/inventory
chown -R oracle:oinstall /u01/app/oracle/inventory
- 配置oracle用户环境变量
su oracle
cd /home/oracle
vim .bash_profile
umask 022
export ORACLE_HOSTNAME=ambari.master.com
export ORACLE_BASE=/db/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"
立刻生效:
source ~/.bash_profile
- 解压安装包
如果安装包在root用户下,现切换到root用户
su - root
cd /opt/oracle
unzip linux.x64_11gR2_database_1of2.zip -d /db
unzip linux.x64_11gR2_database_2of2.zip -d /db
mkdir /db/etc/
cp /db/database/response/* /db/etc/
vim /db/etc/db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=ambari.master.com
ORACLE_HOME=/db/app/oracle/product/11.2.0
ORACLE_BASE=/db/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
3. 安装oracle
安装之前,配置下 swap
否则报错:
Failed <<<<
Some requirement checks failed. You must fulfill these requirements before
continuing with the installation,
su - oracle
cd /db/database/
./runInstaller -silent -ignorePrereq -responseFile /db/etc/db_install.rsp
# 安装需要等待几分钟
#可按他提示的查看日志,新增一个命令窗口,执行
tail -f /u01/app/oracle/inventory/logs/installActions2018-05-04_11-48-18AM.log
根据提示,执行
su - root
sh /u01/app/oracle/inventory/orainstRoot.sh
sh /db/app/oracle/product/11.2.0/root.sh
- 配置静默监听
su oracle
netca /silent /responsefile /db/etc/netca.rsp
-
查看监听端口
netstat -tnulp | grep 1521
静默创建数据库
vim /db/etc/dbca.rsp
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/db/app/oracle/oradata
RECOVERYAREADESTINATION=/db/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "3277"
#在root用户下执行(如果没有权限)
chown -R oracle:oinstall /db/etc/dbca.rsp
- 执行静默建库
dbca -silent -responseFile /db/etc/dbca.rsp
#然后查看一下日志看看有没有报错
vim /db/app/oracle/cfgtoollogs/dbca/orcl/orcl.log
#日志如下:
Copying database files
DBCA_PROGRESS : 1%
DBCA_PROGRESS : 3%
DBCA_PROGRESS : 11%
DBCA_PROGRESS : 18%
DBCA_PROGRESS : 26%
DBCA_PROGRESS : 37%
Creating and starting Oracle instance
DBCA_PROGRESS : 40%
DBCA_PROGRESS : 45%
DBCA_PROGRESS : 50%
DBCA_PROGRESS : 55%
DBCA_PROGRESS : 56%
DBCA_PROGRESS : 60%
DBCA_PROGRESS : 62%
Completing Database Creation
DBCA_PROGRESS : 66%
DBCA_PROGRESS : 70%
DBCA_PROGRESS : 73%
DBCA_PROGRESS : 85%
DBCA_PROGRESS : 96%
DBCA_PROGRESS : 100%
Database creation complete. For details check the logfiles at:
/db/app/oracle/cfgtoollogs/dbca/orcl.
Database Information:
Global Database Name:orcl
System Identifier(SID):orcl
- 查看oracle实例进程
ps -ef | grep ora_ | grep -v grep
root@ambari:~# ps -ef | grep ora_ | grep -v grep
oracle 3531 1 0 05:48 ? 00:00:00 ora_pmon_orcl
oracle 3533 1 11 05:48 ? 00:00:12 ora_vktm_orcl
oracle 3537 1 0 05:48 ? 00:00:00 ora_gen0_orcl
oracle 3539 1 0 05:48 ? 00:00:00 ora_diag_orcl
oracle 3541 1 0 05:48 ? 00:00:00 ora_dbrm_orcl
oracle 3543 1 0 05:48 ? 00:00:00 ora_psp0_orcl
oracle 3545 1 0 05:48 ? 00:00:00 ora_dia0_orcl
oracle 3547 1 16 05:48 ? 00:00:17 ora_mman_orcl
oracle 3549 1 0 05:48 ? 00:00:00 ora_dbw0_orcl
oracle 3551 1 0 05:48 ? 00:00:00 ora_lgwr_orcl
oracle 3553 1 0 05:48 ? 00:00:00 ora_ckpt_orcl
oracle 3555 1 0 05:48 ? 00:00:00 ora_smon_orcl
oracle 3557 1 0 05:48 ? 00:00:00 ora_reco_orcl
oracle 3559 1 1 05:48 ? 00:00:01 ora_mmon_orcl
oracle 3561 1 0 05:48 ? 00:00:00 ora_mmnl_orcl
oracle 3563 1 0 05:48 ? 00:00:00 ora_d000_orcl
oracle 3565 1 0 05:48 ? 00:00:00 ora_s000_orcl
oracle 3615 1 0 05:48 ? 00:00:00 ora_qmnc_orcl
oracle 4088 1 1 05:48 ? 00:00:00 ora_cjq0_orcl
oracle 4121 1 0 05:48 ? 00:00:00 ora_q000_orcl
oracle 4134 1 0 05:48 ? 00:00:00 ora_q001_orcl
- 监听
lsnrctl status
lsnrctl stop
lsnrctl statr
- 登录到oracle,测试
sqlplus / as sysdba
select status from v$instance;
- 各种错误及解决
sqlplus / as sysdba
startup
[centos 安装oracle 报Checking swap space: 0 MB available, 150 MB required. Failed <<<<]
解决参考地址: (https://www.cnblogs.com/a9999/p/6957280.html)
#错误
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/db/app/oracle/product/11.2.0/dbs/initORCL.ora'
cd $ORACLE_BASE/admin/orcl/pfile/
#查看下面的文件
cp ./文件名 $ORACLE_HOME/dbs/initORCL.ora
#继续startup
# 错误
SQL> startup
ORA-00845: MEMORY_TARGET not supported on this system
su - root
mount -t tmpfs shmfs -o size=7g /dev/shm
#继续startup
#错误
SQL> startup
ORACLE instance started.
Total System Global Area 1720328192 bytes
Fixed Size 2214056 bytes
Variable Size 1006634840 bytes
Database Buffers 704643072 bytes
Redo Buffers 6836224 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode
#先关闭数据库
shutdown immediate
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
su - root
cd /db/app/oracle/product/11.2.0/dbs
fuser -k lkORCL
报错:fuser:command not found
yum install -y psmisc
/db/app/oracle/product/11.2.0/dbs/lkORCL: 2933 2939 2943 2945 2949 2951 2953 2955 2957 2959 2961 2963 3138 3140 3142 3144 3341 3343 3345 3869 3961
再执行fuser -u lkORCL没有任何输出即可
#这时再执行startup就可以了
SQL> startup
ORACLE instance started.
Total System Global Area 1720328192 bytes
Fixed Size 2214056 bytes
Variable Size 1006634840 bytes
Database Buffers 704643072 bytes
Redo Buffers 6836224 bytes
Database mounted.
Database opened.
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
SQL>
- Oracle 修改SYS、system用户密码
概念
SYS用户是Oracle中权限最高的用户,而SYSTEM是一个用于数据库管理的用户。在数据库安装完之后,应立即修改SYS,SYSTEM这两个用户的密码,以保证数据库的安全。
安装完之后修改密码方法
实际上这个是没修改成功的
SQL> alter user scott identified by zpf
2 ^C
搞了半天,头晕
oracle 修改完 要加;
cmd命令行下输入 sqlplus / as sysdba;
法1.SQL>alter user sys identified by huozhe
法2.SQL>grant connect to sys identified by 123456
法3. SQL> password system
更改 system 的口令
新口令:
重新键入新口令:
口令已更改
(注:法3只适用于SYSTEM)
验证:
SQL> conn system/huozhe
已连接。
sys 是超级管理员所以要这样连接
SQL> conn sys/"123456" as sysdba
SQL> show user
USER 为 "SYSTEM"
SQL> exit
问题:
linux 在~/.bash_profile配置完oracle每次都要source 才能使用的问题
解决:
在root模式下修改.bash_profile或者oracle下修改.bashrc
#cd ~
#vim .bashrc
增加以下环境配置内容:
export ORACLE_BASE=/db/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export ORACLE_SID=orcl
export PS1='[\u@\h \W]\$'
export ORACLE_PID=orcl
:wq
source .bashrc
reboot
5. 设置oracle数据库自启动
1、安装好Oracle数据库后: 执行 dbstart和dbshut
dbshut
dbstart
错误原因:dbstart和dbshut脚本文件中ORACLE_HOME_LISTNER的设置有问题
解决:
vim $ORACLE_HOME/bin/dbstart
vim $ORACLE_HOME/bin/dbshut
分别打开两个文件修改如下内容
ORACLE_HOME_LISTNER=$1
修改为:
ORACLE_HOME_LISTNER=$ORACLE_HOME
2、Linux启动时自动启动Oracle监听和实例
第一步:
vi /etc/oratab
找到: orcl:/db/app/oracle/product/11.2.0:N
修改为: orcl:/db/app/oracle/product/11.2.0:Y
(这个路径跟安装路径有关,$ORACLE_SID:$ORACLE_HOME:<N|Y>)
CentOS 7添加开机启动服务/脚本
参考:
https://www.jianshu.com/p/9cd8708422c0
以下命令添加到
autostart.sh 脚本
su - oracle -lc "/db/app/oracle/product/11.2.0/bin/lsnrctl start"
su - oracle -lc "/db/app/oracle/product/11.2.0/bin/dbstart"
说明:
第一行为开机启动数据库监听服务
第二行为开机启动数据库。(路径跟安装路径相关)。
reboot
查看oracle 实例进程
ps -ef | grep ora_ | grep -v grep
查看监听状态:
lsnrctl status
lsnrctl stop
lsnrctl statr
主要参考文章:
Centos7 安装oracle11
CentOS 7静默(无图形化界面)安装Oracle 11g
CentOS 7 启动Oracle
设置oracle数据库自启动
linux 在~/.bash_profile配置完oracle每次都要source 才能使用的问题
CentOS 7添加开机启动服务/脚本