本文内容的来源包含并不限于如下几位数据库大神的视频课堂或博客,由本人或原文转载、或二次整理,在此由衷感谢!
小麦苗博客:
http://blog.itpub.net/26736162/
风哥博客:
http://blog.51cto.com/oracle18c
乐沙弥博客
http://blog.csdn.net/leshami
1. Linux的安装(Centos6.9)
1.1 最小化安装centos6.9。
最小化安装的软件包请参考:http://blog.51cto.com/oldboy/1564620
(安装过程省略)
1.2 系统设置及其它软件安装
1.2.1 设置固定IP地址
获取当前的IP地址、子网掩码、网关和DNS地址
编辑vi /etc/sysconfig/network-scripts/ifcfg-eth0文件,设置固定IP地址。
vi /etc/sysconfig/network-scripts/ifcfg-eth0 ##设置部分如下: BOOTPROTO=static DNS1=172.16.23.254 DNS2=114.114.114.114 IPADDR=172.16.17.190 NETMASK=255.255.255.0 GATEWAY=172.16.17.1
1.2.2 中文环境切换成英文环境(如果需要)
cat /etc/sysconfig/i18n LANG="en_US.UTF-8" ##若之前安装了中文环境的系统,请讲LANG按如下设置 #LANG="zh_CN.UTF-8" LANG="en_US.UTF-8"
1.2.3 配置本地yum源 或 更换为本地epel源
配置本地光盘yum源
更换为本地源
1、备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/ CentOS 6 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 3、之后运行 yum clean all,yum makecache 生成缓存
1.2.4 安装pdksh-5.2.14和rlwrap
wget https://files.cnblogs.com/files/llill/pdksh-5.2.14-30.x86_64.rpm.tar.gz tar zxvf pdksh-5.2.14-30.x86_64.rpm.tar.gz rpm -e ksh-20120801-37.el6_9.x86_64 rpm -ivh pdksh-5.2.14-30.x86_64.rpm wget https://files.cnblogs.com/files/llill/rlwrap-0.37.tar.gz yum -y install readline* tar -xvf rlwrap-0.42.tar.gz cd rlwrap-0.42 ./configure make && make install
1.2.5 安装lrzsz
yum install lrzsz -y
1.2.6 安装vnc
yum install tigervnc tigervnc-server fontforge -y
配置VNC请参考:http://blog.csdn.net/jkxsanger/article/details/8897306
1.2.7 安装桌面(使用图形化节目安装软件和创建数据库需要,若选择静默安装软件和静默创建数据库则不需要)
yum groupinstall -y "X Window System" "Desktop Platform" Desktop
2. Oracle软件单机安装和卸载
2.1 安装前的准备工作
2.1.1 软件准备
2.1.2 检查硬件
2.1.3 修改hosts文件、修改主机名
# 其中 HOSTNAME=oracle表示主机名设置为oracle
more /etc/sysconfig/network hostname oracle
# 查看/etc/hosts 文件中必须包含a fully qualified name for the server,必须包含127.0.0.1和真实的IP 地址这2 行 more /etc/hosts
注意:
1.将主机名对应到真实IP 地址,否则Oracle 有可能将监听程序仅仅建立在127.0.0.1 上。
2.修改主机名后,需要重启系统后生效。
2.1.4 安装Oracle所需的依赖包:
yum install binutils -y yum install compat-libcap1 -y yum install compat-libstdc++-33 -y yum install gcc -y yum install gcc-c++ -y yum install glibc -y yum install glibc-devel -y yum install ksh -y yum install libgcc -y yum install libstdc++ -y yum install libstdc++-devel -y yum install libaio -y yum install libaio-devel -y yum install libXext -y yum install libXtst -y yum install libX11 -y yum install libXau -y yum install libxcb -y yum install libXi -y yum install make -y
yum install elfutils-libelf-devel-* yum install sysstat -y yum install unixODBC -y yum install unixODBC-devel -y
2.1.5 配置系统内核参数:
2.1.5.1 /etc/security/limits.conf
vim /etc/security/limits.conf #Setting For Oracle oracle soft nofile 65536 oracle hard nofile 65536 oracle soft nproc 16384 oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
2.1.5.2 /etc/pam.d/login
vim /etc/pam.d/login #Setting For Oracle session required /lib/security/pam_limits.so session required pam_limits.so
2.1.5.3 /etc/profile
vim /etc/profile #Setting For Oracle if [ $USER = "oracle" ]; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 16384 else ulimit -u 16384 -n 16384 fi fi
2.1.5.4 /etc/sysctl.conf
vim /etc/sysctl.conf #Setting For Oracle fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152 kernel.shmmax = 4294967295 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
生效: sysctl -p
2.1.6 关闭防火墙
service iptables stop chkconfig iptables off chkconfig --list | grep iptables
2.1.7 禁用selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config setenforce 0
2.2 新建安装Oracle所需的用户和组
groupadd oinstall groupadd dba useradd -g oinstall -G dba -m oracle #修改oracle用户密码: passwd oracle
2.2.1 配置Oracle用户的环境变量
vi /home/oracle/.bash_profile #Setting For Oracle export ORACLE_SID=orac01 export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS" export TMP=/tmp export TMPDIR=$TMP export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH export EDITOR=vi export TNS_ADMIN=$ORACLE_HOME/network/admin export ORACLE_PATH=.:$ORACLE_BASE/dba_scripts/sql:$ORACLE_HOME/rdbms/admin export SQLPATH=$ORACLE_HOME/sqlplus/admin #export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" --AL32UTF8 SELECT userenv('LANGUAGE') db_NLS_LANG FROM DUAL; export NLS_LANG="AMERICAN_CHINA.ZHS16GBK" alias sqlplus='rlwrap sqlplus' alias rman='rlwrap rman' alias asmcmd='rlwrap asmcmd' alias sas='sqlplus / as sysdba'
stty erase ^H #export PS1="[\u@\h-\`echo \$ORACLE_SID\` \W]$ " #export PS1='[$LOGNAME@'`hostname`:'$PWD'']# '
2.3 新建安装目录
mkdir -p /u01/app/oracle chown -R oracle:oinstall /u01/app chmod -R 775 /u01/app
2.4 将oracle 使用者加入到sudo 群组中
vi /etc/sudoers 找到 root ALL=(ALL) ALL 这行,并且在底下再加入 oracle ALL=(ALL) NOPASSWD: ALL 输入wq!(由于这是一份只读文档所以需要再加上!)并且按下Enter
2.5 准备oracle安装软件
1. 使用rz命令将文件拷贝到/soft目录下来(建议在安装完毕lrzsz软件后就上传oracle安装文件)
oracle安装文件拷贝完毕后计算其MD5值,用于确认是否拷贝完整。
[root@oracle ~]# cd /soft/ [root@oracle soft]# pwd /soft [root@oracle soft]# ls -lha total 3.5G drwxr-xr-x 2 root root 4.0K Mar 16 16:05 . dr-xr-xr-x. 24 root root 4.0K Mar 16 16:05 .. -rw-r--r--. 1 root root 1.3G May 16 2017 p13390677_112040_Linux-x86-64_1of7.zip -rw-r--r--. 1 root root 1.1G May 16 2017 p13390677_112040_Linux-x86-64_2of7.zip -rw-r--r--. 1 root root 1.2G May 16 2017 p13390677_112040_Linux-x86-64_3of7.zip [root@oracle soft]# md5sum p13390677_112040_Linux-x86-64_1of7.zip 1616f61789891a56eafd40de79f58f28 p13390677_112040_Linux-x86-64_1of7.zip [root@oracle soft]# md5sum p13390677_112040_Linux-x86-64_2of7.zip 67ba1e68a4f581b305885114768443d3 p13390677_112040_Linux-x86-64_2of7.zip [root@oracle soft]# md5sum p13390677_112040_Linux-x86-64_3of7.zip 04cef37991db18f8190f7d4a19b26912 p13390677_112040_Linux-x86-64_3of7.zip [root@oracle soft]# [root@oracle soft]# chmod 777 * [root@oracle soft]# [root@oracle soft]# ls -lha total 3.5G drwxr-xr-x 2 root root 4.0K Mar 16 16:05 . dr-xr-xr-x. 24 root root 4.0K Mar 16 16:05 .. -rwxrwxrwx. 1 root root 1.3G May 16 2017 p13390677_112040_Linux-x86-64_1of7.zip -rwxrwxrwx. 1 root root 1.1G May 16 2017 p13390677_112040_Linux-x86-64_2of7.zip -rwxrwxrwx. 1 root root 1.2G May 16 2017 p13390677_112040_Linux-x86-64_3of7.zip
[root@oracle soft]# chown -R oracle:oinstall /soft/
[root@oracle soft]# ls -lha
total 3.5G
drwxr-xr-x 2 oracle oinstall 4.0K Mar 16 16:05 .
dr-xr-xr-x. 24 root root 4.0K Mar 16 16:05 ..
-rwxrwxrwx. 1 oracle oinstall 1.3G May 16 2017 p13390677_112040_Linux-x86-64_1of7.zip
-rwxrwxrwx. 1 oracle oinstall 1.1G May 16 2017 p13390677_112040_Linux-x86-64_2of7.zip
-rwxrwxrwx. 1 oracle oinstall 1.2G May 16 2017 p13390677_112040_Linux-x86-64_3of7.zip
切换到oracle用户解压oracle安装文件。
[oracle@oracle soft]$ id
uid=500(oracle) gid=500(oinstall) groups=500(oinstall),501(dba)
[oracle@oracle soft]$ cd /soft/ [oracle@oracle soft]$ unzip p13390677_112040_Linux-x86-64_1of7.zip [oracle@oracle soft]$ unzip p13390677_112040_Linux-x86-64_2of7.zip [oracle@oracle soft]$ ls -lha total 3.5G drwxr-xr-x 3 oracle oinstall 4.0K Mar 16 16:19 . dr-xr-xr-x. 24 root root 4.0K Mar 16 16:05 .. drwxr-xr-x 7 oracle oinstall 4.0K Aug 27 2013 database -rwxrwxrwx. 1 oracle oinstall 1.3G May 16 2017 p13390677_112040_Linux-x86-64_1of7.zip -rwxrwxrwx. 1 oracle oinstall 1.1G May 16 2017 p13390677_112040_Linux-x86-64_2of7.zip -rwxrwxrwx. 1 oracle oinstall 1.2G May 16 2017 p13390677_112040_Linux-x86-64_3of7.zip [oracle@oracle soft]$ du -sh database/ 2.5G database/ [oracle@oracle soft]$ ll database/ total 60 drwxr-xr-x 4 oracle oinstall 4096 Aug 27 2013 install -rw-r--r-- 1 oracle oinstall 30016 Aug 27 2013 readme.html drwxr-xr-x 2 oracle oinstall 4096 Aug 27 2013 response drwxr-xr-x 2 oracle oinstall 4096 Aug 27 2013 rpm -rwxr-xr-x 1 oracle oinstall 3267 Aug 27 2013 runInstaller drwxr-xr-x 2 oracle oinstall 4096 Aug 27 2013 sshsetup drwxr-xr-x 14 oracle oinstall 4096 Aug 27 2013 stage -rw-r--r-- 1 oracle oinstall 500 Aug 27 2013 welcome.html
2.6 补充:安装oracle数据库rac时需要让两台机器的swap分区一致;如果不一致这里就需要手动的去创建swap分区了
下面介绍两种创建swap的方法
首先, swapoff -a #停止所有的swap分区
--新建磁盘分区作为swap分区
1. 用fdisk命令(例:# fdisk /dev/sdb)对磁盘进行分区,添加swap分区,新建分区,在fdisk中用“t”命令将新添的分区id改为82(Linux swap类型)
2. # mkswap /dev/sdb1 #格式化swap分区,这里的sdb2要看您加完后p命令显示的实际分区设备名
3. # swapon /dev/sdb1 #启动新的swap分区
4. 让系统启动时能自动启用这个交换分区,可以编辑/etc/fstab,加入下面一行
/dev/sdb1 swap swap defaults 0 0
--用文件作为Swap分区
1.创建要作为swap分区的文件:增加1GB大小的交换分区,则命令写法如下,其中的count等于想要的块的数量(bs*count=文件大小)。
# dd if=/dev/zero of=/root/swapfile bs=1M count=1024
2.格式化为交换分区文件:
# mkswap /root/swapfile #建立swap的文件系统
3.启用交换分区文件:
# swapon /root/swapfile #启用swap文件
4.使系统开机时自启用,在文件/etc/fstab中添加一行:
/root/swapfile swap swap defaults 0 0
做完以后用free -g查看以下
3. 安装Oracle软件
注意:安装之前最好重启一下OS,因为前边做了很多操作。 重启完成之后,对虚拟机做一次快照。
以oracle 用户进行登录(注意:不要登录root 用户,然后切换成oracle):
图形界面安装Oracle软件
静默方式安装Oracle软件
[oracle@oracle soft]$ id uid=500(oracle) gid=500(oinstall) groups=500(oinstall),501(dba) [oracle@oracle soft]$ pwd /soft [oracle@oracle soft]$ cd database/ [oracle@oracle database]$ ls -lha total 68K drwxr-xr-x 7 oracle oinstall 4.0K Aug 27 2013 . drwxr-xr-x 3 oracle oinstall 4.0K Mar 16 16:19 .. drwxr-xr-x 4 oracle oinstall 4.0K Aug 27 2013 install -rw-r--r-- 1 oracle oinstall 30K Aug 27 2013 readme.html drwxr-xr-x 2 oracle oinstall 4.0K Aug 27 2013 response drwxr-xr-x 2 oracle oinstall 4.0K Aug 27 2013 rpm -rwxr-xr-x 1 oracle oinstall 3.2K Aug 27 2013 runInstaller drwxr-xr-x 2 oracle oinstall 4.0K Aug 27 2013 sshsetup drwxr-xr-x 14 oracle oinstall 4.0K Aug 27 2013 stage -rw-r--r-- 1 oracle oinstall 500 Aug 27 2013 welcome.html
ALL_DB_SWONLY \
> DECLINE_SECURITY_UPDATES=true \
> UNIX_GROUP_NAME=oinstall \
> INVENTORY_LOCATION=/u01/app/oraInventory \
> SELECTED_LANGUAGES=en \
> ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 \
> ORACLE_BASE=/u01/app/oracle \
> oracle.install.db.InstallEdition=EE \
> oracle.install.db.isCustomInstall=false \
> oracle.install.db.DBA_GROUP=dba \
> oracle.install.db.OPER_GROUP=dba \
> oracle.install.db.isRACOneInstall=false \
> oracle.install.db.config.starterdb.type=GENERAL_PURPOSE \
> SECURITY_UPDATES_VIA_MYORACLESUPPORT=false \
> oracle.installer.autoupdates.option=SKIP_UPDATES
[oracle@oracle ~]$ /soft/database/runInstaller -silent -force -noconfig -ignoreSysPreReqs -ignorePrereq -showProgress \ > oracle.install.option=INSTALL_DB_SWONLY \ > DECLINE_SECURITY_UPDATES=true \ > UNIX_GROUP_NAME=oinstall \ > INVENTORY_LOCATION=/u01/app/oraInventory \ > SELECTED_LANGUAGES=en \ > ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 \ > ORACLE_BASE=/u01/app/oracle \ > oracle.install.db.InstallEdition=EE \ > oracle.install.db.isCustomInstall=false \ > oracle.install.db.DBA_GROUP=dba \ > oracle.install.db.OPER_GROUP=dba \ > oracle.install.db.isRACOneInstall=false \ > oracle.install.db.config.starterdb.type=GENERAL_PURPOSE \ > SECURITY_UPDATES_VIA_MYORACLESUPPORT=false \ > oracle.installer.autoupdates.option=SKIP_UPDATES Starting Oracle Universal Installer... Checking Temp space: must be greater than 120 MB. Actual 5127 MB Passed Checking swap space: must be greater than 150 MB. Actual 4095 MB Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2018-03-16_05-37-41PM. Please wait ...[oracle@oracle ~]$ You can find the log of this install session at: /u01/app/oraInventory/logs/installActions2018-03-16_05-37-41PM.log Prepare in progress. .................................................. 9% Done. Prepare successful. Copy files in progress. .................................................. 14% Done. .................................................. 20% Done. .................................................. 26% Done. .................................................. 31% Done. .................................................. 36% Done. .................................................. 41% Done. .................................................. 46% Done. .................................................. 51% Done. .................................................. 56% Done. .................................................. 63% Done. .................................................. 68% Done. .................................................. 73% Done. .................................................. 78% Done. .................................................. 83% Done. .............................. Copy files successful. Link binaries in progress. .......... Link binaries successful. Setup files in progress. .................................................. 88% Done. .................................................. 94% Done. Setup files successful. The installation of Oracle Database 11g was successful. Please check '/u01/app/oraInventory/logs/silentInstall2018-03-16_05-37-41PM.log' for more details. Execute Root Scripts in progress. As a root user, execute the following script(s): 1. /u01/app/oraInventory/orainstRoot.sh 2. /u01/app/oracle/product/11.2.0/dbhome_1/root.sh .................................................. 100% Done. Execute Root Scripts successful. Successfully Setup Software.
3. 创建数据库
3.1 图形界面创建数据库
3.2 静默方式建库
dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \ -gdbname orac01 -sid orac01 \ -sysPassword oracle -systemPassword oracle \ -datafileDestination '/u01/app/oracle/oradata' \ -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \ -storageType FS \ -characterset AL32UTF8 -nationalCharacterSet AL16UTF16 \ -sampleSchema true \ -memoryPercentage 10 \ -databaseType OLTP \ -emConfiguration NONE
#racle 11g 静默建库脚本如下所示:
dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
-gdbname mydb -sid mydb \
-sysPassword oracle -systemPassword oracle \
-datafileDestination 'DATA/' -recoveryAreaDestination 'FRA/' \
-redoLogFileSize 50 \
-storageType ASM -asmsnmpPassword oracle -diskGroupName 'DATA' \
-characterset AL32UTF8 -nationalCharacterSet AL16UTF16 \
-sampleSchema true \
-automaticMemoryManagement true -totalMemory 2048 \
-databaseType OLTP \
-emConfiguration NONE \
-nodeinfo NODE1,NODE2
#其中,每个参数的含义如下所示: gdbname:全局数据库名 sid:数据库SID,sid 和gdbname 保持一致 sysPassword:数据库sys 密码 systemPassword:数据库system 密码 sysmanPassword:数据库sysman 密码 datafileDestination:数据库数据文件的位置,若是磁盘组则写磁盘组名,例如:'DATA/',若是文件系统就写具体路径,例如:'/u01/app/oracle',需要注意的是,由于数据文件路径会自动加上数据库名,所以,这里不用加数据库名 recoveryAreaDestination:闪回恢复区的位置,该值一般和datafileDestination 保持一致 redoLogFileSize:数据库Redo 文件的大小 emConfiguration:数据库管理方式,是本地管理还是使用Grid Control 进行管理,一般设置为NONE storageType 存储方式,若是磁盘组则为ASM,若是文件系统则为FS,当取值为FS 的时候,应该去掉asmsnmpPassword 和diskGroupName 参数 diskGroupName:存放数据库文件的磁盘组名称,注意此处不加“+” nodeinfo:安装数据库的节点信息,若是RAC 库则必须使用该参数,该参数的值为主机名列表,中间用逗号隔开 characterset:数据库字符集,一般为AL32UTF8 或ZHS16GBK nationalCharacterSet:国家字符集,一般为AL16UTF16 automaticMemoryManagement:是否开启AMM(Automatic Memory Management,自动管理内存),Oracle 11g 可以选择true;Oracle 10g 需要删除该参数 totalMemory:Oracle 11g 代表数据库占用内存大小,单位为MB,例如2048 代表2GB;Oracle10g 用memoryPercentage 参数,代表数据库占用OS 内存大小的百分比 sampleSchema:是否安装用于学习实验的示例数据,测试库选择true,生产库选择false在以上命令中需要注意的是,每个正斜杠“\”的后面不能有空格,否则不能执行。当然,也可以去掉该斜杠,让所有参数保持在一行上。 #在静默建库时产生的日志文件路径: Oracle 11g:$ORACLE_BASE/cfgtoollogs/dbca Oracle 10g:$ORACLE_HOME/cfgtoollogs/dbca #静默建库创建的数据库默认为非归档模式,所以,需要修改文件: $ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc,将该文件里边的参数 “<archiveLogMode>false</archiveLogMode>”修改为 “<archiveLogMode>true</archiveLogMode>”即可。这样,以后每次静默创建的数据库都是归档模式了。
4. 管理工具的使用
5. Oracle ASM的安装
6.补充:
Oracle配置完毕后记得设置 取消默认的密码180天有效期的限制:
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED ;