转载请注明出处!
文章目录
- 前言
- 一、环境搭建:
- 开启虚拟机,进行操作:
- 切换到root用户下:
- 进行用户组的创建(2组:dba、oinstall):
- 创建数据库安装目录:
- ==修改OS系统标识==:
- 安装数据库所需要的软件包:
- 通过ISO文件作为yum安装源(1):
- 关闭防火墙:
- 关闭selinux(重启生效)
- 关闭selinux(重启生效):
- 修改内核参数:
- 使配置参数生效:
- 对oracle用户进行限制,提高软件性能:
- 配置用户环境变量:
- 使用户环境变量立即生效:
- 将安装包放置在/usr/local/src目录下:
- 使用oracle 用户登录:
- 进入/usr/local/src目录:
- 解压两个软件包到/data/database目录下:
- 进入管理员权限,设置目录所有者为oinstall用户组的oracle用户,执行安装脚本:
- 使用oracle用户登录:
- 使用图形化界面安装:
- Xhell使用图形化界面安装:
- 二、图形化界面流程:
- 三、启动监听:
- 四、启动Oracle服务:
前言
网上有很多Oracle学习资料,我也是从小白走过来的,也遇到很多的坑,觉得网上没有一些对小白很友好的文章,所以!现在!我来了,我会逐渐更新从第一篇开始手把手教你Oracle数据库入门奥。so,就从最简单安装数据库开始吧,注意目录安装步骤。
提示:以下是本篇文章正文内容,下面案例可供参考
一、环境搭建:
虚拟机搭建部分省略,注意网络设置 改为手动设置的固定IP
注意虚机网段
开启虚拟机,进行操作:
查看IP地址:ifconfig(手动配置ipv4)
更改hostname:vi /etc/hosts
127.0.0.1开头缺省不可更改,最后行添加IP地址、计算机全名、计算机名—>保存
更改:hostname tdcxl.com
关闭/注销后 再次打开终端名称已改变
切换到root用户下:
进行用户组的创建(2组:dba、oinstall):
[root@tdcxl ~]# su - root
上一次登录:三 9月 25 12:38:58 CST 2019:0 上
[root@tdcxl ~]# groupadd oinstall
[root@tdcxl ~]# groupadd dba
[root@tdcxl ~]# useradd -g oinstall -g dba -m oracle
[root@tdcxl ~]# passwd oracle
更改用户 oracle 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@tdcxl ~]# id oracle
uid=1001(oracle) gid=1002(dba) 组=1002(dba)
创建数据库安装目录:
[root@tdcxl ~]# cd /.
[root@tdcxl /]# mkdir -p /data/oracle #oracle数据库安装目录
[root@tdcxl /]# mkdir -p /data/oraInventory #oracle数据库配置文件目录
[root@tdcxl /]# mkdir -p /data/database #oracle数据库软件包解压目录
[root@tdcxl /]# cd /data
[root@tdcxl data]# ls
database oracle oraInventory
[root@tdcxl data]# chown -R oracle:oinstall /data/oracle
[root@tdcxl data]# chown -R oracle:oinstall /data/oraInventory
[root@tdcxl data]# chown -R oracle:oinstall /data/database
修改OS系统标识:
此步骤可以忽略!
[root@tdcxl data]# cat /proc/version
Linux version 3.10.0-957.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Thu Nov 8 23:39:32 UTC 2018
[root@tdcxl data]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@tdcxl data]# vi /etc/redhat-release
[root@tdcxl data]# cat /etc/redhat-release
redhat-7
安装数据库所需要的软件包:
需要确定是否具有yum源,可用"yum install tree" 先进行测试,如若无法正常安装,可参照下一目录小节(极特殊情况下无法挂载镜像文件,此时需要自己下载对应版本的镜像文件手动挂载,后续会出单独文章,敬请期待!)。
[root@tdcxl data]# yum -y install binutils compat-libstdc++-33 gcc gcc-c++ glibc glibc-common glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat openssh-clients compat-libcap1 xorg-x11-utils xorg-x11-xauth elfutils unixODBC unixODBC-devel libXp elfutils-libelf elfutils-libelf-devel smartmontools
(省略…)
通过ISO文件作为yum安装源(1):
查看是否挂载光盘(最后一行是否存在sr0):
[root@tdcxl /]# df -h
挂载:
[root@tdcxl ~]# mount /dev/sr0 /mnt/
mount: 在 /dev/sr0 上找不到媒体
[root@tdcxl /]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@tdcxl /]# ll /dev/sr0 /mnt/
挂载好光盘以后,确认/etc/yum.repos.d/文件下是否存在.repo文件,如果存在则备份后删除。
[root@tdcxl etc]# cd yum.repos.d/
[root@tdcxl yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@tdcxl yum.repos.d]# mkdir repofile
[root@tdcxl yum.repos.d]# cp /etc/yum.repos.d/* /etc/yum.repos.d/repofile/
cp: 略过目录"/etc/yum.repos.d/repofile"
[root@tdcxl yum.repos.d]# cd repofile/
[root@tdcxl repofile]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@tdcxl yum.repos.d]# rm -rf *.repo
[root@tdcxl yum.repos.d]# ls
Repofile
进行创建编辑repo文件:
[root@tdcxl yum.repos.d]# vi /etc/yum.repos.d/file.repo
注:内容路径进行对应
[softinstll]
name=rhel7repo
baseurl=file:///mnt
enabled=1
gpgckeck=0
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7
[softinstll]
name=rhel7repo
baseurl=file:///mnt
enabled=1
gpgckeck=0
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7
清除cache:
[root@tdcxl yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: softinstll
Cleaning up list of fastest mirrors
Other repos take up 67 M of disk space (use --verbose for details)
验证:
[root@tdcxl yum.repos.d]# yum -y install tree
取消光盘挂载:
[root@tdcxl ~]# umount /dev/sr0
umount: /dev/sr0:未挂载
关闭防火墙:
[root@tdcxl data]# systemctl status firewalld.service #查看防火墙状态(打开)
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 三 2019-09-25 12:37:36 CST; 27min ago
Docs: man:firewalld(1)
Main PID: 7679 (firewalld)
CGroup: /system.slice/firewalld.service
└─7679 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
9月 25 12:37:34 localhost.localdomain systemd[1]: Starting firewalld - dynam...
9月 25 12:37:36 localhost.localdomain systemd[1]: Started firewalld - dynami...
Hint: Some lines were ellipsized, use -l to show in full.
[root@tdcxl data]# systemctl stop firewalld.service #关闭防火墙
[root@tdcxl data]# systemctl status firewalld.service #查看防火墙状态(关闭)
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since 三 2019-09-25 13:05:43 CST; 13s ago
Docs: man:firewalld(1)
Process: 7679 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 7679 (code=exited, status=0/SUCCESS)
9月 25 12:37:34 localhost.localdomain systemd[1]: Starting firewalld - dynam...
9月 25 12:37:36 localhost.localdomain systemd[1]: Started firewalld - dynami...
9月 25 13:05:42 tdcxl.com systemd[1]: Stopping firewalld - dynamic firewal.....
9月 25 13:05:43 tdcxl.com systemd[1]: Stopped firewalld - dynamic firewall...n.
Hint: Some lines were ellipsized, use -l to show in full.
关闭selinux(重启生效)
[root@tdcxl data]# vi /etc/selinux/config #改为disable
关闭selinux(重启生效):
查看selinux工作状态:
[root@tdcxl ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
查看selinux服务状态:
[root@tdcxl ~]# getenforce
Enforcing
将参数修改为SELINUX 参数修改为disabled
修改内核参数:
[root@tdcxl data]# vi /etc/sysctl.conf
#在文件中添加:
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 17179869180
kernel.panic_on_oops = 1
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
使配置参数生效:
[root@tdcxl data]# sysctl -p
#参数注释:
[root@tdcxl data]# sysctl -p
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
fs.file-max = 6815744 #设置最大打开文件数
fs.aio-max-nr = 1048576
kernel.shmall = 2097152 #共享内存的总量,8G内存设置:2097152*4k/1024/1024
kernel.shmmax = 2147483648 #最大共享内存的段大小
kernel.shmmni = 4096 #整个系统共享内存端的最大数
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500 #可使用的IPv4端口范围
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
对oracle用户进行限制,提高软件性能:
[root@tdcxl ~]# vi /etc/security/limits.conf
[root@tdcxl ~]# cat /etc/security/limits.conf
在 /etc/security/limits.conf 文件中添加(12C以上版本注意添加最后两行):
oracle soft nofile 10240
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
oracle hard memlock 134217728
oracle soft memlock 134217728
配置用户环境变量:
[root@tdcxl ~]# vi /home/oracle/.bash_profile
[root@tdcxl ~]# cat /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_BASE=/data/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=orcl
export ORACLE_TERM=xterm
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export LANG=C
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
#环境变量代码注释如下:
export PATH
export ORACLE_BASE=/data/oracle #oracle数据库安装目录
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 #oracle数据库路径
export ORACLE_SID=orcl #oracle启动数据库实例名
export ORACLE_UNQNAME=orcl
export ORACLE_TERM=xterm #xterm窗口模式安装
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH #添加系统环境变量
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib #添加系统环境变量
export LANG=C #防止安装过程出现乱码
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK #设置Oracle客户端字符集,必须与Oracle安装时设置的字符集保持一致
注意:不能给/etc/profile文件里等号前后加空格
使用户环境变量立即生效:
[root@tdcxl ~]# source /home/oracle/.bash_profile
将安装包放置在/usr/local/src目录下:
目录请根据实际需求设置
[root@tdcxl ~]# cd /usr/local/src/
[root@tdcxl src]# ls
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
或进入安装包所在目录:
[root@localhost ~]# cd /.
[root@localhost /]# cd /home/anzerong/Desktop/
[root@localhost Desktop]# ls
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
[root@localhost Desktop]# mv linux.x64_11gR2_database_1of2.zip /usr/local/src
[root@localhost Desktop]# ls
linux.x64_11gR2_database_2of2.zip
[root@localhost Desktop]# mv linux.x64_11gR2_database_2of2.zip /usr/local/src
使用oracle 用户登录:
进入/usr/local/src目录:
[oracle@tdcxl ~]$ cd /usr/local/src
[oracle@tdcxl src]$ ls
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
解压两个软件包到/data/database目录下:
[oracle@tdcxl src]$ unzip linux.x64_11gR2_database_1of2.zip -d /data/database/
(省略…)
[oracle@tdcxl src]$ unzip linux.x64_11gR2_database_2of2.zip -d /data/database/
(省略…)
进入管理员权限,设置目录所有者为oinstall用户组的oracle用户,执行安装脚本:
[oracle@tdcxl src]$ su - root
Password:
Last login: Wed Sep 25 13:30:11 CST 2019 from 192.168.221.1 on pts/1
[root@tdcxl ~]#
[root@tdcxl ~]# chown -R oracle:oinstall /data/database/database/
使用oracle用户登录:
[root@tdcxl ~]# su oracle
[oracle@tdcxl root]$ cd /data/database/database/
[oracle@tdcxl database]$ ls
doc install response rpm runInstaller sshsetup stage welcome.html
使用图形化界面安装:
###切换至Root用户:
[root@tdcxl ~]# xhost +
xhost: unable to open display ""
[root@tdcxl ~]# export DISPLAY=:0.0
[root@tdcxl ~]# xhost +
access control disabled, clients can connect from any host
###切换至oracle用户:
[root@tdcxl ~]# su oracle
[oracle@tdcxl root]$
[oracle@tdcxl root]$ cd /data/database/database/
[oracle@tdcxl database]$ ls
doc install response rpm runInstaller sshsetup stage welcome.html
[oracle@tdcxl database]$ ./runInstaller
此处建议xshell登录oracle用户不做任何设置,直接呼出图形化界面
Xhell使用图形化界面安装:
如使用oracle登录请忽略此步骤
[root@tdcxl ~]# xhost +
access control disabled, clients can connect from any host
[root@tdcxl ~]# su – oracle
[oracle@tdcxl ~]$ DISPLAY=192.168.119.1:0.0
#设置DISPLAY变量,注意配置使用xshell客户端的ip
[oracle@tdcxl ~]$ export DISPLAY
[oracle@tdcxl ~]$ cd /data/database/database/
[oracle@tdcxl database]$ ls
doc install response rpm runInstaller sshsetup stage welcome.html
[oracle@tdcxl database]$ ./runInstaller
图形化显示小方块问题:
安装字体库(文件拷贝至新建目录):
[root@tdcxl ~]# mkdir -p /usr/share/fonts/zh_CN/TrueType
cp zysong.ttf /usr/share/fonts/zh_CN/TrueType/
乱码问题:临时调用:
[oracle@tdcxl database]$ export LANG=en_US.UTF-8
[oracle@tdcxl database]$ ./runInstaller
二、图形化界面流程:
Makefile 安装目标 install 出错:
[root@tdcxl ~]# vim /data/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk
将
ctxhx: $(CTXHXOBJ)
$(LINK_CTXHX) $(CTXHXOBJ) $(INSO_LINK)
修改为:
ctxhx: $(CTXHXOBJ)
-static $(LINK_CTXHX) $(CTXHXOBJ) $(INSO_LINK) /usr/lib64/libc.a
点击Retry继续安装。
Makefile 安装目标 agent nmhs 出错:
[root@tdcxl ~]# vim /data/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk
#===========================
# emdctl
#===========================
$(SYSMANBIN)emdctl:
$(MK_EMAGENT_NMECTL) -lnnz11
#===========================
# nmocat
#===========================
将$(MK_EMAGENT_NMECTL)修改为:$(MK_EMAGENT_NMECTL) -lnnz11
点击Retry继续安装。
安装后的root脚本:
脚本1:
[root@tdcxl ~]# cd /data/oraInventory/
[root@tdcxl oraInventory]# ./orainstRoot.sh
Changing permissions of /data/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /data/oraInventory to dba.
The execution of the script is complete.
脚本2:
[root@tdcxl oraInventory]# cd /data/oracle/product/11.2.0/db_1/
[root@tdcxl db_1]# ./root.sh
Running Oracle 11g root.sh script...
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /data/oracle/product/11.2.0/db_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.sh script.
Now product-specific root actions will be performed.
Finished product-specific root actions.
三、启动监听:
Oracle用户下:
[oracle@tdcxl ~]$ lsnrctl start
监听启动异常:
Connecting to
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=wodeoraclefuwuqi)(PORT=1521)))TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
解决办法:
这个问题和IP有关系,vi /etc/hosts 下:
192.168.221.12 tdcxl.com tdcxl 删掉保存再加上
之后执行:
[root@tdcxl oracle]# hostname tdcxl.com
注销在登陆后进行lsnrctl start
四、启动Oracle服务:
[oracle@tdcxl ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 25 19:12:21 2019
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1586708480 bytes
Fixed Size 2213736 bytes
Variable Size 973080728 bytes
Database Buffers 603979776 bytes
Redo Buffers 7434240 bytes
Database mounted.
Database opened.
SQL> connect / as sysdba
数据库到这里基础安装完成。