最近准备写下oracle 11g r2单机部署(图形方式)---本案、oracle 11g r2单机部署(命令方式)、oracle 11g r2 RAC方案等。
1、创建运行oracle数据库的系统用户和用户组
[root@localhost ~]# groupadd oinstall [root@localhost ~]# groupadd dba [root@localhost ~]# useradd -g oinstall -g dba -m oracle [root@localhost ~]# passwd oracle 更改用户 oracle 的密码 。 新的 密码: 无效的密码: 密码未通过字典检查 - 它基于字典单词 重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。 [root@localhost ~]# id oracle uid=1000(oracle) gid=1001(dba) 组=1001(dba)
2、创建oracle数据库安装目录
[root@localhost /]# mkdir -p /data/oracle #oracle数据库安装目录 [root@localhost /]# mkdir -p /data/oraInventory #oracle数据库存储安装软件目录 [root@localhost /]# mkdir -p /data/database #oracle数据库软件包解压目录 [root@localhost /]# cd /data [root@localhost data]# ll 总用量 0 drwxr-xr-x. 2 root root 6 1月 31 14:09 database drwxr-xr-x. 2 root root 6 1月 31 14:08 oracle drwxr-xr-x. 2 root root 6 1月 31 14:08 oraInventory [root@localhost data]# chown -R oracle:oinstall /data/oracle [root@localhost data]# chown -R oracle:oinstall /data/oraInventory [root@localhost data]# chown -R oracle:oinstall /data/database [root@localhost data]# ll 总用量 0 drwxr-xr-x. 2 oracle oinstall 6 1月 31 14:09 database drwxr-xr-x. 2 oracle oinstall 6 1月 31 14:08 oracle drwxr-xr-x. 2 oracle oinstall 6 1月 31 14:08 oraInventory [root@localhost ~]# mkdir /data/recovery_area [root@localhost ~]# chown oracle:oinstall /data/recovery_area [root@localhost ~]# chmod 775 /data/recovery_area/ [root@localhost ~]# cd /data/ [root@localhost data]# ll total 8 drwxr-xr-x. 3 oracle oinstall 21 Feb 1 11:33 database drwxrwx---. 5 oracle dba 4096 Feb 1 13:37 oraInventory drwxr-xr-x. 9 oracle oinstall 4096 Feb 1 13:38 oracle drwxrwxr-x. 2 oracle oinstall 6 Feb 1 15:10 recovery_area 备注:生产环境/data最好是存储挂载点,不要存储再本地磁盘。
3、设置主机名和修改OS系统标识(oracle默认不支持Centos系统,如果是centos请修改成redhat-7)
[root@localhost data]# hostnamectl --static set-hostname Oracle-gxm [root@Oracle-gxm src]# cat /etc/hosts 127.0.0.1 localhost Oracle-gxm localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.146.129 Oracle-gxm [root@Oracle-gxm src]# systemctl restart network [root@localhost data]# cat /proc/version Linux version 3.10.0-514.26.2.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Jul 4 15:04:05 UTC 2017 [root@localhost data]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@localhost data]# vi /etc/redhat-release [root@localhost data]# cat /etc/redhat-release redhat-7
4、安装oracle数据库所需要的软件包
[root@localhost data]# yum -y install binutils* compat-libcap1* compat-libstdc++* gcc* gcc-c++* glibc* glibc-devel* ksh* libaio* libaio-devel* libgcc* libstdc++* libstdc++-devel* libXi* libXtst* make* sysstat* elfutils* unixODBC*
5、关闭防火墙和selinux
[root@localhost data]# systemctl status firewalld.service [root@localhost data]# systemctl stop firewalld.service [root@localhost data]# systemctl status firewalld.service [root@localhost data]# systemctl disable firewalld.service [root@localhost data]# setenforce 0 [root@localhost data]# 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
6、修改内核参数
[root@localhost data]# cat /etc/sysctl.conf # System default settings live in /usr/lib/sysctl.d/00-system.conf. # To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file # # For more information, see sysctl.conf(5) and sysctl.d(5). 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 kernel.shmmax = 2147483648 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 [root@localhost data]# sysctl -p [root@localhost data]# vi /etc/security/limits.conf oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536
7、设置环境变量
[root@localhost data]# 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 #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 #防止安装过程出现乱码 export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK #设置Oracle客户端字符集,必须与Oracle安装时设置的字符集保持一致 [root@localhost data]# source /home/oracle/.bash_profile
8、重启服务器并上传oracle安装包到/usr/local/src/目录
[root@localhost data]# yum -y install wget lrzsz unzip xterm xorg-x11-xauth [root@localhost data]# cd /usr/local/src/ 上传linux.x64_11gR2_database_1of2.zip和linux.x64_11gR2_database_2of2.zip文件 解压: [root@localhost data]# unzip linux.x64_11gR2_database_1of2.zip -d /data/database/ [root@localhost data]# unzip linux.x64_11gR2_database_2of2.zip -d /data/database/ 给解压目录设置权限: [root@localhost src]# ll /data/database/database/ total 24 drwxr-xr-x. 12 root root 4096 Aug 17 2009 doc drwxr-xr-x. 4 root root 4096 Aug 15 2009 install drwxrwxr-x. 2 root root 58 Aug 15 2009 response drwxr-xr-x. 2 root root 33 Aug 15 2009 rpm -rwxr-xr-x. 1 root root 3226 Aug 15 2009 runInstaller drwxrwxr-x. 2 root root 28 Aug 15 2009 sshsetup drwxr-xr-x. 14 root root 4096 Aug 15 2009 stage -rw-r--r--. 1 root root 5402 Aug 18 2009 welcome.html [root@localhost src]# chown -R oracle:oinstall /data/database/database/ [root@localhost src]# ll /data/database/database/ total 24 drwxr-xr-x. 12 oracle oinstall 4096 Aug 17 2009 doc drwxr-xr-x. 4 oracle oinstall 4096 Aug 15 2009 install drwxrwxr-x. 2 oracle oinstall 58 Aug 15 2009 response drwxr-xr-x. 2 oracle oinstall 33 Aug 15 2009 rpm -rwxr-xr-x. 1 oracle oinstall 3226 Aug 15 2009 runInstaller drwxrwxr-x. 2 oracle oinstall 28 Aug 15 2009 sshsetup drwxr-xr-x. 14 oracle oinstall 4096 Aug 15 2009 stage -rw-r--r--. 1 oracle oinstall 5402 Aug 18 2009 welcome.html [root@localhost src]# export DISPLAY=192.168.146.129:0.0
9、使用xstart工具连接oracle账号,相关配置如下,最后点击“运行”(或者安装桌面环境):
[oracle@localhost ~]$ export.UTF-8 [oracle@localhost ~]$ cd /data/database/database/ [oracle@localhost ~]$ ./runInstatller
备注:网上说可以忽略i386的包,也有的说一定要强制安装,以下是强制安装的方法: [root@localhost src]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm [root@localhost src]# rpm -ivh compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm [root@Oracle-gxm ~]# wget ftp://ftp.pbone.net/mirror/www.whiteboxlinux.org/whitebox/4/en/updates/i386/libaio-0.3.105-2.i386.rpm [root@Oracle-gxm ~]# rpm -ivh libaio-0.3.105-2.i386.rpm --nodeps --force [root@Oracle-gxm ~]# wget http://vault.centos.org/5.11/os/x86_64/CentOS/compat-libstdc++-33-3.2.3-61.i386.rpm [root@Oracle-gxm ~]# rpm -ivh compat-libstdc++-33-3.2.3-61.i386.rpm --nodeps --force [root@Oracle-gxm ~]# wget ftp.redhat.com/pub/redhat/dst2007/APPLICATIONS/gcj/RHEL4/3.4.6-3.1/i386/libgcc-3.4.6-3.1.i386.rpm [root@Oracle-gxm ~]# rpm -ivh libgcc-3.4.6-3.1.i386.rpm --nodeps --force [root@Oracle-gxm ~]# wget ftp://ftp.nluug.nl/pub/os/Linux/distr/RedHat/ftp/redhat/dst2007/APPLICATIONS/gcj/RHEL4/3.4.6-3.1/i386/libstdc++-3.4.6-3.1.i386.rpm [root@Oracle-gxm ~]# rpm -ivh libstdc++-3.4.6-3.1.i386.rpm --nodeps --force [root@Oracle-gxm ~]# wget ftp://ftp.icm.edu.pl/vol/rzm3/linux-oracle-repo/EnterpriseLinux/EL4/latest/i386/glibc-2.3.4-2.41.i686.rpm [root@Oracle-gxm ~]# rpm -ivh glibc-2.3.4-2.41.i686.rpm --nodeps --force [root@Oracle-gxm ~]# wget ftp://ftp.pbone.net/mirror/yum.trixbox.org/centos/5/old/unixODBC-2.2.11-7.1.i386.rpm [root@Oracle-gxm ~]# rpm -ivh unixODBC-2.2.11-7.1.i386.rpm --nodeps --force [root@Oracle-gxm ~]# wget ftp://ftp.nluug.nl/pub/os/Linux/distr/startcom/AS-5.0.0/os/x86_64/StartCom/RPMS/unixODBC-devel-2.2.11-7.1.i386.rpm [root@Oracle-gxm ~]# rpm -ivh unixODBC-devel-2.2.11-7.1.i386.rpm --nodeps --force [root@Oracle-gxm ~]# wget http://ftp.pbone.net/mirror/www.whiteboxlinux.org/whitebox/3.0/en/os/x86_64/RedHat/RPMS/pdksh-5.2.14-21.x86_64.rpm [root@Oracle-gxm ~]# rpm -ivh pdksh-5.2.14-21.x86_64.rpm --nodeps --force #pdksh-5.2.14-30.x86_64.rpm不用安装,oracle现在用ksh。 [root@Oracle-gxm ~]# wget ftp://ftp.pbone.net/mirror/www.whiteboxlinux.org/whitebox/4/en/updates/i386/libaio-devel-0.3.105-2.i386.rpm [root@Oracle-gxm ~]# rpm -ivh libaio-devel-0.3.105-2.i386.rpm --nodeps --force
1)ins_ctx.mk编译错误 查看日志有以下错误: INFO: /lib64/libstdc++.so.5: undefined reference to `memcpy@GLIBC_2.14' INFO: collect2: error: ld returned 1 exit status INFO: make: *** [ctxhx] Error 1 网上说是glibc的版本2.17过高所致(高于2.14),解决办法: 进入管理员权限安装glibc-static [oracle@localhost ~]# su - root password [root@localhost ~]# yum -y install glibc-static 该软件包包含一个静态链接库,地址是:/usr/lib64/libc.a [root@localhost ~]# vi /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继续安装。
2)”Error in invoking target 'agent nmhs' of makefile '/data/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk.' 解决方法:在makefile中添加链接libnnz11库的参数 vi /data/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk $(MK_EMAGENT_NMECTL) 修改为: $(MK_EMAGENT_NMECTL) -lnnz11
[root@Oracle-gxm ~]# /data/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. [root@Oracle-gxm ~]# /data/oracle/product/11.2.0/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.
web访问地址: 刚才默认新建的数据库为orcl,如下图:
连接数据库验证: [oracle@Oracle-gxm ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 1 14:50:13 2019 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 status from v$instance; STATUS ------------------------ OPEN SQL> 启动监听: [oracle@Oracle-gxm database]$ netca
显示监听状态: [oracle@Oracle-gxm ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 01-FEB-2019 15:00:32 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 01-FEB-2019 13:37:52 Uptime 0 days 1 hr. 22 min. 40 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /data/oracle/diag/tnslsnr/Oracle-gxm/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(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 dbca建库: [oracle@Oracle-gxm database]$ dbca
https://192.168.146.129:5500/em/
[oracle@Oracle-gxm ~]$ sqlplus sys/gxm as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 1 15:36:59 2019 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>
------------------------------------------------------------华丽的分隔线------------------------------------------------------------
附:
1.Linux下sqlplus不能使用光标箭头 解决办法:安装rlwrap包 1)下载rlwrap压缩包(我下载的是rlwrap-0.37.tar.gz); 2)yum安装readline [root@Oracle-gxm ~]# yum -y install readline* 3)解压,安装 [root@Oracle-gxm ~]# tar -xzvf rlwrap-0.37.tar.gz [root@Oracle-gxm ~]# cd rlwrap-0.37.tar.gz [root@Oracle-gxm ~]# ./configure [root@Oracle-gxm ~]# make [root@Oracle-gxm ~]# make install 4)编辑oracle账号的bash_profile文件 [root@Oracle-gxm rlwrap-0.37]# vi /home/oracle/.bash_profile 在最后添加 alias sqlplus='rlwrap sqlplus' alias rman='rlwrap rman' [root@Oracle-gxm rlwrap-0.37]# source /home/oracle/.bash_profile
2.vim中文乱码 设置~下或者oracle用户下的.vimrc文件,加上fileencodings、enc、fencs,代码如下: [root@Oracle-gxm ~]# vim /home/oracle/.vimrc #添加如下代码 set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1 set enc=utf8 set fencs=utf8,gbk,gb2312,gb18030