CENTOS7下部署数据库与应用
CENTOS7下部署数据库与应用
Author: 张翔龙Xianglong.Zhang
E-Mail: [email protected]
Creation Date: July 25, 2017
Last Updated: July 25, 2017
Document Ref: <Document Reference Number>
Version: 1.0
-
Title, Subject, Last Updated Date, Reference Number, and Version are marked by a Word Bookmark so that they can be easily reproduced in the header and footer of documents. When you change any of these values, be careful not to accidentally delete the bookmark. You can make bookmarks visible by selecting Tools->Options…View and checking the Bookmarks option in the Show region.
Approvals:
<Approver 1> |
Xianglong.Zhang |
<Approver 2> |
Copy No. _____
- To add additional approval lines, press [Tab] from the last cell in the table above.
- You can delete any elements of this cover page that you do not need for your document. For example, Copy Number is only required if this is a controlled document and you need to track each copy that you distribute.
Document Control
Change Record
1
Date |
Author |
Version |
Change Reference |
2017-7-25 |
Xianglong.Zhang |
1.0 |
No Previous Document |
Reviewers
Name |
Position |
Distribution
Copy No. |
Name |
Location |
Library Master |
Project Library |
|
Project Manager |
||
-
The copy numbers referenced above should be written into the Copy Number space on the cover of each distributed copy. If the document is not controlled, you can delete this table, the Note To Holders, and the Copy Number label from the cover page.
Note To Holders:
If you receive an electronic copy of this document and print it out, please write your name on the equivalent of the cover page, for document control purposes.
If you receive a hard copy of this document, please write your name on the front cover, for document control purposes.
Contents
Document Control ii
总体说明 1
文档目的 1
内容 1
(一)CentOS7 2
1. 安装 2
2. 重设SWAP 2
3. VM下添加硬盘空间 3
(二)Oracle Database 12C 6
1. 工具/原料 6
2. 配置系统环境 6
3. 修改系统参数 7
4. 开始安装 9
5. 图形界面安装 9
6. 数据库启停 13
(三)MySQL 14
(四)应用服务 15
(五) 16
Open and Closed Issues for this Deliverable 17
Open Issues 17
Closed Issues 17
- To update the table of contents, put the cursor anywhere in the table and press [F9]. To change the number of levels displayed, select the menu option Insert>Index and Tables, make sure the Table of Contents tab is active, and change the Number of Levels to a new value.
总体说明
文档目的
将数据库与应用部署到服务器是必须掌握的技能,本文就CentOS7系统为例,介绍部署数据库与应用的步骤。
内容
- CentOS7
- Oracle Database 12C
- MySQL
- 应用服务
(一)CentOS7
-
安装
-
重设SWAP
- 查看当前swap大小:
free -m
- 查看硬盘空间是否足够配置swap文件:
df -h
- 查看是否已经配置过swap:
swapon -s
-
如果swap文件已经存在,则修改改swap文件:
关闭swap:
sudo swapoff -a
把当前swap文件增大:
sudo dd if=/dev/zero of=/dev/dm-1 bs=1M count=4096
注:of设置为swap文件,bs为单位,count为数量。
把增大后的文件设置为swap文件:
sudo mkswap /swapfile
重新打开swap:
sudo swapon /swapfile
让swap在启动时自动生效,编辑/etc/fstab文件:
sudo nano /etc/fstab
添加:
/swapfile swap swap defaults 0 0
-
如果未配置过swap,则新建swap文件:
创建:
sudo fallocate -l 4G /swapfile
检查:
ls -lh /swapfile
-rw-r--r-- 1 root root 4.0G Oct 30 11:00 /swapfile
启用swap:
sudo chmod 600 /swapfile
sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=b99230bb-21af-47bc-8c37-de41129c39bf
sudo swapon /swapfile
检查:
swapon -s
free -m
使swap开机自动生效:
sudo nano /etc/fstab
添加:
/swapfile swap swap sw 0 0
-
VM下添加硬盘空间
如果CentOS7文件系统空间不足,可以添加硬盘空间,这里给出VM下添加硬盘空间的方法。
PV:物理卷
VG:逻辑卷组
LV:逻辑卷
-
VM中添加一块硬盘
- 查看新硬盘
fdisk -l
- 对新硬盘分区
fdisk /dev/sdb
n
p
1
null
null
t
L
8e
P
w
partprobe
注:/dev/sdb为新硬盘名
- 创建物理卷(PV)
pvcreate /dev/sdb1
pvdisplay
- 将PV加入卷组(VG)
vgdisplay
vgextend centos /dev/sdb1
- 创建逻辑卷(LV)
lvcreate -L 4G -n newlv cl
lvdisplay
- 格式化逻辑卷并挂载
mkfs.xfs /dev/cl/newlv
mount -t xfs /dev/cl/newlv /dev/
df -Th
- 设置开机自动挂载
vi /etc/fstab
添加:
/dev/cl/newlv /dev
- 逻辑卷扩容
lvextend -l +100%FREE /dev/cl/newlv
xfs_growfs /dev/cl/newlv
-
(二)Oracle Database 12C
-
工具/原料
-
CentOS7
CentOS-7-x86_64-DVD-1611.iso
下载地址:官方网站
确保系统有足够的 RAM 和交换空间大小:
free –mh
注:所需最小 RAM 为 512MB,而所需最小交换空间为 1GB。对于 RAM 小于或等于 2GB 的系统,交换空间应为 RAM 数量的两倍;对于 RAM 大于 2GB 的系统,交换空间应为 RAM 数量的一到两倍。
确保有足够的磁盘空间:
df -h
注:Oracle 10g软件大约需要 2.5GB 的可用磁盘空间,数据库则另需至少1.2G的磁盘空间;/tmp 目录至少需要 400MB 的可用空间。
-
Oracle Database 12C
linuxamd64_12102_database_1of2.zip
linuxamd64_12102_database_2of2.zip
下载地址:官方网站
-
-
配置系统环境
- 安装所需RPM程序包,执行以下代码:
yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*.i686 elfutilslibelf-devel gcc gcc-c++ glibc*.i686 glibc glibc-devel glibc-devel*.i686 ksh libgcc*.i686 libgcc libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.i686 libaio libaio*.i686 libaio-devel libaio-devel*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBCdevel*.i686 libXp
- 建立用户和组:
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba,oper oracle #初始群组为 oinstall,有效群组为 dba、oper
passwd oracle #为oracle帐号设置密码(安装的时候需要登录)
- 安装目录:
mkdir -p /orcl/app/oracle/product/12.1.0/db_1
chown -R oracle:oinstall /orcl/app
chmod -R 775 /orcl/app
-
修改系统参数
- 修改内核参数:
编辑内核参数配置文件:
vi /etc/sysctl.conf
在该文件下修改或添加如下行:
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
再执行以下命令使以上配置立即生效:
sysctl -p
- 修改文件限制
编辑系统资源限制配置文件:
vi /etc/security/limits.conf
在该文件下添加如下行:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
编辑login文件:
vi /etc/pam.d/login
注释,无则跳过:
#session required /lib/security/pam_limits.so
添加:
session required pam_limits.so
- 修改ulimit:
vi /etc/profile
添加:
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536a
else
ulimit -u 16384 -n 65536
fi
fi
- 修改Oracle用户环境变量:
vi ~oracle/.bash_profile
添加:
ORACLE_BASE=/orcl/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/12.1.0/db_1
ORACLE_SID=orcl
export ORACLE_BASE ORACLE_HOME ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH
export PATH
-
开始安装
将安装文件复制到/orcl/app/oracle目录下,执行:
su - oracle
cd /orcl/app/oracle
unzip linuxamd64_12102_database_se2_1of2.zip
unzip linuxamd64_12102_database_se2_2of2.zip
export LANG="en_US"
cd /orcl/app/oracle/database
./runInstaller
-
图形界面安装
如果是远程服务器,可以使用vnc远程连接服务器进行图形视窗安装。
这里直接在虚拟机中进行图形界面操作。
注:上图设置应与.bash_profile文件保持一致,并设置好用户名和密码。
上图check了安装环境是否符合要求,前面的配置步骤也就是为这里check做准备,可以根据结果重新调整。例如这里显示交换内存不够的警告。
-
数据库启停
(三)MySQL
(四)应用服务
(五)
- If the Functional Design included a Technical Overview section, duplicate that information here and add additional details.
- Add other components above as required
- Indicate the specific menu options added to access new forms.
Open and Closed Issues for this Deliverable
- Add open issues that you identify while writing or reviewing this document to the open issues section. As you resolve issues, move them to the closed issues section and keep the issue ID the same. Include an explanation of the resolution.
When this deliverable is complete, any open issues should be transferred to the project- or process-level Risk and Issue Log (PJM.CR.040) and managed using a project level Risk and Issue Form (PJM.CR.040). In addition, the open items should remain in the open issues section of this deliverable, but flagged in the resolution column as being transferred.
Open Issues
ID |
Issue |
Resolution |
Responsibility |
Target Date |
Impact Date |
Closed Issues
ID |
Issue |
Resolution |
Responsibility |
Target Date |
Impact Date |