第一步:到oracle官网上下载oracle12c的镜像文件
第二步:添加用户和组
用普通用户登录后,打开命令行工具(terminal)
转到root用户
[vmtest@localhost ~]$ su root
Password:
添加组
[root@localhost vmtest]# groupadd dba
添加用户
[root@localhost vmtest]# useradd oracle
将oracle用户分配给dba组
[root@localhost vmtest]# usermod -g dba oracle
为oracle用户设置密码
[root@localhost vmtest]# passwd oracle
Changing password for user oracle.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
检查刚才创建的用户和密码
[root@localhost vmtest]# tail /etc/group
gdm:x:42:
gnome-initial-setup:x:983:
avahi:x:70:
slocate:x:21:
sshd:x:74:
tcpdump:x:72:
oprofile:x:16:
vmtest:x:1000:vmtest
dba:x:1001:
oracle:x:1002:
[root@localhost vmtest]# tail /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFSUser:/var/lib/nfs:/sbin/nologin
pulse:x:171:171:PulseAudio SystemDaemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:988:983::/run/gnome-initial-setup/:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SDStack:/var/run/avahi-daemon:/sbin/nologin
sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
oprofile:x:16:16:Special user account to be used byOProfile:/var/lib/oprofile:/sbin/nologin
vmtest:x:1000:1000:vmtest:/home/vmtest:/bin/bash
oracle:x:1001:1001::/home/oracle:/bin/bash
第三步:创建安装目录
新建文件夹(软件目录)
[root@localhost vmtest]# mkdir -p /u01/app/oracle
将文件夹分配给用户oracle
[root@localhost vmtest]# chown oracle:dba /u01/app/oracle
设置文件夹权限
[root@localhost vmtest]# chmod 777 /u01/app/oracle
新建附属文件夹
[root@localhost vmtest]# mkdir /u01/app/oraInventory
[root@localhost vmtest]# chown oracle:dba /u01/app/oraInventory
[root@localhost vmtest]# chmod 775 /u01/app/oraInventory
验证刚才的操作
[root@localhost vmtest]# ls -l /u01/app
total 0
drwxrwxrwx. 2 oracle dba 6 Aug 2 07:52 oracle
drwxrwxr-x. 2 oracle dba 6 Aug 2 07:55 oraInventory
第四步:修改linux内核文件
打开/etc/sysctl.conf,
[root@localhost vmtest]# vi /etc/sysctl.conf
按键盘上i,进入插入模式,将红色那一段文字添加到文件末尾,按esc,然后输入:wq保存
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
kernel.shmmax = 68719476736
kernel.shmall = 6029312
kernel.shmmni = 4096
kernel.sem =250 32000 100 128
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 262144
net.ipv4.ip_local_port_range =9000 65500
fs.file-max=65536
fs.aio-max-nr=1048576
~
~
"/etc/sysctl.conf" 55L, 794C written
修改limits文件
[root@localhost vmtest]# vi /etc/security/limits.conf
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in viaPAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.ddirectory,
#which are read in alphabetical order, override the settings inthis
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domainhere
#can be overriden with a wildcard setting in a config file inthe
#subdirectory, but a user specific setting here can be overridenonly
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#
#
#Where:
#
# - a user name
# - a group name,with @group syntax
# - the wildcard *,for default entry
# - the wildcard %,can be also used with %group syntax,
# formaxlogin limit
#
#
# -"soft" for enforcing the soft limits
# -"hard" for enforcing hard limits
#
#
# - core - limitsthe core file size (KB)
# - data - max data size (KB)
# - fsize - maximumfilesize (KB)
# - memlock - maxlocked-in-memory address space (KB)
# - nofile - maxnumber of open file descriptors
# - rss - maxresident set size (KB)
# - stack - maxstack size (KB)
# - cpu - max CPUtime (MIN)
# - nproc - maxnumber of processes
# - as - addressspace limit (KB)
# - maxlogins - maxnumber of logins for this user
# - maxsyslogins -max number of logins on the system
# - priority - thepriority to run user process with
# - locks - maxnumber of file locks the user can hold
# - sigpending -max number of pending signals
# - msgqueue - maxmemory used by POSIX message queues (bytes)
# - nice - max nicepriority allowed to raise to values: [-20, 19]
# - rtprio - maxrealtime priority
#
#
#
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4
# End of file
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 10240
"/etc/security/limits.conf" 84L, 2588C written
[root@localhost vmtest]# vi /etc/pam.d/login
#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad]pam_securetty.so
auth substack system-auth
auth include postlogin
account required pam_nologin.so
account include system-auth
password include system-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
session optional pam_console.so
# pam_selinux.so open should only be followed by sessions to beexecuted in the user context
session required pam_selinux.so open
session required pam_namespace.so
session optional pam_keyinit.so force revoke
session include system-auth
session include postlogin
-session optional pam_ck_connector.so
session required /lib/security/pam_limits.so
session required pam_limits.so
~
"/etc/pam.d/login" 23L, 878C written
修改hosts
[root@localhost vmtest]# vi /etc/hosts
127.0.0.1 localhostlocalhost.localdomain localhost4 localhost4.localdomain4
::1 localhostlocalhost.localdomain localhost6 localhost6.localdomain6
192.168.189.128 localhost.localdomain //主机名
192.168.189.128 localhost
"/etc/hosts" 6L, 224C written
内核文件修改结束,重启电脑并以oracle用户登录
第五步:配置oracle用户下的概要文件
在oracle用户下,修改文件.bashrc,红色为需要添加的内容
[oracle@localhost ~]$ vi /home/oracle/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl'sauto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
umask 002
ORACLE_BASE=/u01/app/oracle //oracle安装目录,与第三步创建的安装目录相同
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/12.2.0/dbhome_1 //oracle软件包目录
export ORACLE_HOME
ORACLE_SID=orcl
export ORACLE_SID
PATH=/usr/bin:/bin:usr/local/bin:/usr/bin/X11:/usr/bin/X11R6
PATH=$PATH:$ORACLE_HOME/bin
export PATH
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
".bashrc" 37L, 515C written
.bash_profile环境变量设置
#vi .bash_profile
exportORACL_BASE=/u01/app/oracle /*oracle安装目录*/
export ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1 /运行目录/
exportORACLE_SID=orcl /数据库实例名/
export PATH=$PATH:$ORACLE_HOME/bin /sqlplus运行目录/
第六步:上传并解压oracle软件包
我用的是secureCRT远程工具,用secureCRT连接到linux服务器后,定位到想上传的文件夹
# cd /home/oracle/Downloads
# rz
输入rz,打开文件框,
找到要上传的文件,点击“add”,然后点击“OK”,开始上传
注:如果服务器安装的是centos,默认会带有rzsz工具,如果没有这个工具,在服务器上下载lrzsz软件包,安装上就行。
上传之后,解压文件
用命令行检查加压后的文件是否属于用户oracle
[oracle@localhost ~]$ cd /home/oracle/Downloads
[oracle@localhost Downloads]$ ls -l
total 4176512
drwxr-xr-x. 7 oracle dba 117 Jan 27 2017 database
-rw-r--r--. 1 oracle dba 3453696911 Jul 27 08:40linuxx64_12201_database.zip
第七步:安装oracle
定位到刚才解压的文件夹
# cd /home/oracle/Downloads/database
# ./runInstaller
等一会,安装程序启动
不注册,到下一步
选第二项:只安装数据库软件,(到后面进行手动配置)
这里两个路径是第五步中设置的ORACLE_BASE和ORACLE_HOME变量
这个路径是第三步建的第二个文件夹
到这一步,会有依赖项提示,解决依赖包问题会是比较麻烦的,我们选的centos7系统本身带的依赖包是比较全的,现在我们只解决划红线这一项,其他都忽略即可。
首先查一下与所需依赖包相关的其他包的版本号
# rpm –qa | grep libaio
Libaio-0.3.109-13.el7.x86_64
现在根据这个版本号,找libaio-devel-0.3.109-13.el7.x86_64这个rpm包(网上搜)
定位到上传的文件夹
$ cd /home/oracle/Downloads
显示所有文件
$ ls
切换到root账号下,安装文件
$ su root
Password:
$ rpm –ivh libaio-devel-0.3.109-13.el7.x86_64
重新检查依赖项,发现刚才那个警告没有了。
其他三项全部忽略,如果在安装过程中还报其他依赖项的错误,反过头来按照这个步骤安装相应依赖包。
等吧…
安装完成。
切换到root用户
运行 ./root.sh
# cd $ORACLE_HOME
# ./root.sh
Performing root user operation.
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/12.2.0/dbhome_1
Enter the full pathname of the local bin directory:[/usr/local/bin]:
Copying dbhome to/usr/local/bin ...
Copying oraenv to/usr/local/bin ...
Copying coraenv to/usr/local/bin ...
Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Do you want to setup Oracle Trace File Analyzer (TFA) now ?yes|[no] :
yes
Installing Oracle Trace File Analyzer (TFA).
Log File:/u01/app/oracle/product/12.2.0/dbhome_1/install/root_localhost.localdomain_2017-08-08_08-15-23-754009678.log
Finished installing Oracle Trace File Analyzer (TFA)
安装完成。
第八步:创建数据库
在命令行输入
# dbca
如果输入dbca没反应,那应该是第五步里的ORACLE_BASE和ORACLE_HOME环境变量设置错误。
等吧。。。
安装完成
第九步:配置监听(用于远程连接数据库)
在命令行输入netca
服务名与第五步里SID一致
修改配置文件
打开listener.ora
$ cd $ORACLE_HOME/network/admin
$ vi listener.ora
在文件末尾添加
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
#BEQUEATH CONFIG
(GLOBAL_DBNAME=orcl)
(SID_NAME=orcl)
(ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1)
#PRESPAWN CONFIG
(PRESPAWN_MAX=20)
(PRESPAWN_LIST=
(PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1))
)
)
)
保存,重启
第十步:启动数据库和监听
在命令行输入
$ sqlplus / as sysdba
启动数据库
SQL> startup
退出sql
Sql>exit
启动监听
$ lsnrctl start
OK,服务器和监听全部启动。
第十一步:其他设置
如果没有安装防火墙组件,先安装,指令如下
#yum install systemd #yum install firewalld
关闭防火墙
# systemctl stop firewalld.service
关闭开机制动启动
# systemctl disable firewalld.service
如果客户端不是oracle12c,比如是oracle11g,需要修改文件(如果没有则新建):
$ORACLE_HOME/network/admin/sqlnet.ora,在该文件最后添加一行文字(不需重启oracle):
SQLNET.ALLOWED_LOGON_VERSION=8
在登录时,如果出现ORA-01017:用户名密码错误的信息,可能是由于oracle12c对用户名大小写敏感造成的,可以通过系统用户登录sqlplus
#sqlplus / as sysdba
并通过下列语句修改
sql> alter system set sec_case_sensitive_logon = false;
修改后如果还报用户名错误,那么在服务器端重新设置用户的密码,就可以了
Sql>alter user test1user identified by ****;
第十二步:测试远程连接
通过sqlplus创建表空间
SQL> create tablespaceNOTIFYDB datafile '$ORACLE_BASE/oradata/orcl/test1.dbf' size 100M reuse autoextendon next 40M maxsize 1000M;
Tablespace created.
创建用户
SQL> create user test1user identified by test1pw defaulttablespace NOTIFYDB
2 ;
User created.
为用户授权
SQL> grant dba to test1user;
Grant succeeded.
SQL> grant connect,resource to test1user;
Grant succeeded.
SQL> grant select any table to test1user;
Grant succeeded.
SQL> grant delete any table to test1user;
Grant succeeded.
SQL> grant update any table to test1user;
Grant succeeded.
SQL> grant insert any table to test1user;
Grant succeeded.
通过plsql连接该表空间
成功。
最后一步:设置oracle数据库和监听程序开机自动启动。
切换到root用户
编辑文件/etc/oratab
[root@localhost dbhome_1]# vi /etc/oratab
#
# This file is used by ORACLE utilities. It is created by root.sh
# and updated by either Database Configuration Assistant whilecreating
# a database or ASM Configuration Assistant while creating ASMinstance.
# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Linesbeginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third field indicates
# to the dbstart utility that the database should ,"Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcl:/u01/app/oracle/product/12.2.0/dbhome_1:Y
添加上面最后一行文字,保存。
编辑文件rc.local并添加最后两行文字
[root@localhost dbhome_1]# vi /etc/rc.d/rc.local
su oracle -lc "/opt/oracle/102/bin/lsnrctl start"
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udevrules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel executionduring boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' toensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
su oracle -lc"/u01/app/oracle/product/12.2.0/dbhome_1/bin/lsnrctl start"
su oracle -lc/u01/app/oracle/product/12.2.0/dbhome_1/bin/dbstart
其中第一行因为lsnrctl之后有空格,需要引号,第二行加不加引号都可以。修改完保存退出即可。
但是还有一个很重要的问题,如果是在以前的centos版本中,这样就可以了。但是centos7 的/etc/rc.local不会开机执行,是因为
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In constrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
翻译:
#这个文件是为了兼容性的问题而添加的。
#强烈建议创建自己的systemd服务或udev规则来在开机时运行脚本而不是使用这个文件。
#与以前的版本引导时的并行执行相比较,这个脚本将不会在其他所有的服务后执行。
#请记住,你必须执行“chmod +x /etc/rc.d/rc.local”来确保确保这个脚本在引导时执行。
好,现在执行指令
# chmod +x /etc/rc.d/rc.local
设置完成
重启
用指令lsnrctl status 看监听程序是否打开
登录sqlplus / as sysdba
如果显示
表示数据库已经启动,
如果现实:
Connect to an idle database
说明数据库没有启动