Oraliux+mysql5单机多实例安装文档
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Oraliux+mysql5单机多实例安装文档

on

  • 436 views

Oraliux+mysql5单机多实例安装文档

Oraliux+mysql5单机多实例安装文档

Statistics

Views

Total Views
436
Views on SlideShare
436
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Oraliux+mysql5单机多实例安装文档 Document Transcript

  • 1. oraliux+mysql5 单机多实例源码安装文档谭雪锋20120621安装目录分配: 源码安装时,可以针对 MYSQL 进行各种个性化的需求配置,包括软件目录结构。对于计 划在同主机上安装多版本或多数据库实例的需求,可根据配置不同的目录和不同端口来实 现。 目录 位置 备注软件安装目录 HOME /app/mysql/home/mysql_XX mysqlXX 为版本:mysql5519配置文件 my.cnf $HOME/etc/my.cnf数据文件目录 DATA /mysqldata/XXX XXX 为实例名:kmac,sgpm,erm日志文件目录 $data/log/ Log 放到各自的数据文件目录下端口配置 330433063308 预设 3 个端口给实例一、前期准备1、OS 版本检查:[root@Tanxuefeng /]# uname -aLinux Tanxuefeng 2.6.32-71.el6.i686 #1 SMP Wed Sep 1 01:26:34 EDT 2010 i686 i686 i386GNU/Linux[root@Tanxuefeng /]# cat /etc/issueRed Hat Enterprise Linux Server release 6.0 (Santiago)Kernel r on an m2、支撑软件包的检查与安装 源码安装时,需要相关的软件进行源码编译( gcc cmake ncurses-devel),检查 OS 中是否已安装相关软件:[root@Tanxuefeng /]# rpm -q gcc cmake ncurses-develgcc-4.4.4-13.el6.i686cmake-2.6.4-5.el6.i686ncurses-devel-5.7-3.20090208.el6.i686本 OS 中已安装,若未安装则需要从 OS 安装 CD 中找出软件进行安装,见附录 1:支撑软件包安装。3、下载 MYSQL 源码安装包:MYSQL 软件源码安装包下载地址:http://dev.mysql.com/downloads/mysql/
  • 2. 选(GA)选项板,Select Platform: 选择源码 :最后,根据 OS 版本选择相应的源码版本进行下载(mysql-5.5.25.tar.gz):二、安装环境配置1、规划安装目录[root@Tanxuefeng /]# mkdir -p /app/mysql/home/mysql_5525 ##软件目录[root@Tanxuefeng /]# mkdir -p /mysqldata/kmac ##实例 kmac 的数据文件目录[root@Tanxuefeng /]# mkdir -p /mysqldata/sgpm ##实例 sgpm 的数据文件目录[root@Tanxuefeng /]# mkdir -p /mysqldata/erm ##实例 erm 的数据文件目录[root@Tanxuefeng /]# mkdir -p /mysqldata/kmac/log ##实例 kmac 的日志文件目录[root@Tanxuefeng /]# mkdir -p /mysqldata/sgpm/log ##实例 sgpm 的日志文件目录[root@Tanxuefeng /]# mkdir -p /mysqldata/erm/log ##实例 erm 的日志文件目录2、创建用户组及用户[root@Tanxuefeng]# groupadd mysqldba[root@Tanxuefeng]# useradd -g mysqldba mysql[root@Tanxuefeng ]# passwd mysql[root@Tanxuefeng /]# id mysqluid=501(mysql) gid=501(mysqldba) 组=501(mysqldba)说明:对于在同一台主机上安装不同版本的数据库时,建议采用不同的账户来进行管理,可用版本名作为账户名,如 useradd –g mysqldba mysql5519 用于管理 5519 版本的 mysql3、配置目录权限[root@Tanxuefeng /]# chown -R mysql:mysqldba /app/mysql /mysqldata
  • 3. 4、配置环境变量[root@Tanxuefeng /]# su - mysql[mysql@Tanxuefeng ~]$ vi .bash_profilePATH=$PATH:/app/mysql/home/mysql_5525/bin:/app/mysql/home/mysql_5525/libexport PATH说明:用户可分别在 root 或 mysql 账户下配置环境变量。对于同一主机安装不同版本的数据库,建议采用不同的账户进行管理5、配置防火墙 由于一个实例只能占用一个端口,多实例时需要分配多个端口号,固需要对防火墙进行处理,以打开相应的端口。(1) 检查 OS 防火墙是否打开[mysql@Tanxuefeng ~]$ chkconfig|grep iptabiptables 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭说明:打开防火器指定端口的方法,见附录 2:开启防火器端口.开启: chkconfig iptables on关闭: chkconfig iptables off(2) 使用 root 账户打开防火墙三个端口 330433063308[root@Tanxuefeng /]# iptables -I INPUT -i eth0 -p tcp --dport 3304 -j ACCEPT[root@Tanxuefeng /]# iptables -I OUTPUT -O eth0 -p tcp --sport 3304 -j ACCEPT(3) 检查指定端口是否已打开[root@Tanxuefeng /]# /etc/init.d/iptables status表格:filterChain INPUT (policy ACCEPT)num target prot opt source destination1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3304Chain FORWARD (policy ACCEPT)num target prot opt source destinationChain OUTPUT (policy ACCEPT)num target prot opt source destination1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:3304以同样的方法,分别打开其它两个端口。三、源码安装 MYSQL 软件(root)1、上传并解压源码文件[root@Tanxuefeng soft]# tar zxvf mysql-5.5.25.tar.gz……………………………………………………..2、构 建 自 定 义 安 装 配 置
  • 4. [root@Tanxuefeng soft]# cmake -DCMAKE_INSTALL_PREFIX=/app/mysql/home/mysql_5525 -DSYSCONFDIR=/app/mysql/home/mysql_5525/etc -DEXTRA_CHARSET=utf8 -DEXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=13、编译源码[root@Tanxuefeng mysql-5.5.25]# make…………………………………………………4、安装软件2、编译源码[root@Tanxuefeng mysql-5.5.25]# make install…………………………………………………源码软件安装完成。下面进行配置。四、配置多实例1、删除原来的数据文件目录[root@Tanxuefeng ~]# cd /app/mysql/home/mysql_5525[root@Tanxuefeng mysql_5525]# lsbin data include lib mysql-test scripts sql-benchCOPYING docs INSTALL-BINARY man README share support-files[root@Tanxuefeng mysql_5525]# rm -rf data2、创建需要的目录[root@Tanxuefeng mysql_5525]# cd /app/mysql/home/mysql_5525/[root@Tanxuefeng mysql_5525]# mkdir etc tmp run log binlogs[root@Tanxuefeng mysql_5525]# chown -R mysql:mysqldba etc tmp run log binlogs[mysql@Tanxuefeng mysqldata]$ mkdir -p /mysqldata/kmac/socket[mysql@Tanxuefeng mysqldata]$ mkdir -p /mysqldata/kmac/pid-file[mysql@Tanxuefeng mysqldata]$ mkdir -p /mysqldata/kmac/log[mysql@Tanxuefeng mysqldata]$ mkdir -p /mysqldata/sgpm/socket[mysql@Tanxuefeng mysqldata]$ mkdir -p /mysqldata/sgpm/pid-file[mysql@Tanxuefeng mysqldata]$ mkdir -p /mysqldata/sgpm/log3、创建支持多实例的配置文件 my.cnf
  • 5. (1)复制已有的最小化配置文件,作为基础[root@Tanxuefeng mysql_5525]# pwd/app/mysql/home/mysql_5525[root@Tanxuefeng mysql_5525]# cp ./support-files/my-small.cnf my.cnf(2)调整修改 my.cnf 加入多实例配置参数在文件最后增加以下配置:[root@Tanxuefeng mysql_5525]# vi my.cnf[mysqld_multi]mysqld = /app/mysql/home/mysql_5525/bin/mysqld_safemysqladmin = /app/mysql/home/mysql_5525/bin/mysqladminuser = mysqlpassword = mysql#instance: kmac[mysqld1]datadir = /mysqldata/kmacsocket = /mysqldata/kmac/socket/mysql.sockpid-file = /mysqldata/kmac/pid-file/mysqld.pidlog=/mysqldata/kmac/log/mysqld_kmac_common.loglog-error=/mysqldata/kmac/log/mysqld_kmac_err.loglog-bin=/mysqldata/kmac/log/mysqld_kmac_bin.binuser = mysqlport = 3304server-id = 100#instance: sgpm[mysqld2]datadir = /mysqldata/sgpmsocket = /mysqldata/sgpm/socket/mysql.sockpid-file = /mysqldata/sgpm/pid-file/mysqld.pidlog=/mysqldata/sgpm/log/mysqld_sgpm_common.loglog-error=/mysqldata/sgpm/log/mysqld_sgpm_err.loglog-bin=/mysqldata/sgpm/log/mysqld_sgpm_bin.binuser = mysqlport = 3308server-id = 100(3) 修改 my.cnf 读写权限,避免普通用户获取到 MySQL 密码# chown -R root:root /opt/mysql/etc# chmod 600 /opt/mysql/etc/my.cnf
  • 6. 五、初始化数据库(1)初始化实例[mysqld1][mysql@Tanxuefeng]$ scripts/mysql_install_db --basedir=/app/mysql/home/mysql_5525--user=mysql --datadir=/mysqldata/kmac(2)初始化实例[mysqld2][mysql@Tanxuefeng]$ scripts/mysql_install_db --basedir=/app/mysql/home/mysql_5525--user=mysql --datadir=/mysqldata/sgpm六、设置多实例启动参数文件为 my.cnf 复 制 $HOME/support-files/mysqld_multi.server 启 动 文 件 到 /usr/sbin/ 下 , 并 进 行 调 整 加 入my.cnf 文件路径,修改 basedirbindir 的路径。[mysql@Tanxuefeng mysql_5525]$ cp ./support-files/mysqld_multi.server ./etc/[mysql@Tanxuefeng etc]$ vi mysqld_multi.serverbasedir=/app/mysql/home/mysql_5525bindir=/app/mysql/home/mysql_5525/bincase "$1" in start ) "$mysqld_multi" --defaults-extra-file =/app/mysql/home/mysql_5525/etc/my.cnf start $2 ;; stop ) "$mysqld_multi" --defaults-extra-file =/app/mysql/home/mysql_5525/etc/my.cnf stop $2 ;; report ) "$mysqld_multi" --defaults-extra-file =/app/mysql/home/mysql_5525/etc/my.cnf report $2 ;; restart ) "$mysqld_multi" --defaults-extra-file =/app/mysql/home/mysql_5525/etc/my.cnf stop $2 "$mysqld_multi" --defaults-extra-file =/app/mysql/home/mysql_5525/etc/my.cnf start $2 ;; *) echo "Usage: $0 {start|stop|report|restart}" >&2 ;;esac在文件中加入 config-file 参数文件之后,多实例启动时不需要指定—config-file 参数.否则需要 mysqld_multi --defaults-extra-file=/app/mysql/home/mysql_5525/my.cnf start 1,2七、启动多实例[mysql@Tanxuefeng mysql_5525]$ mysqld_multi start 1,2[mysql@Tanxuefeng mysql_5525]$ ps -ef|grep mysql|grep kmacmysql 18884 1 0 10:07 pts/1 00:00:00 /bin/sh /app/mysql/home/mysql_5525/bin/mysqld_safe--datadir=/mysqldata/kmac --socket=/mysqldata/kmac/socket/mysql.sock --pid-file=/mysqldata/kmac/
  • 7. pid-file/mysqld.pid --user=mysql --port=3304 --server-id=100mysql 19233 18884 0 10:07 pts/1 00:00:00 /app/mysql/home/mysql_5525/bin/mysqld --basedir=/app/mysql/home/mysql_5525 --datadir=/mysqldata/kmac --plugin-dir=/app/mysql/home/mysql_5525/lib/plugin --server-id=100 --log-error=/var/log/mysqld.log --pid-file=/mysqldata/kmac/pid-file/mysqld.pid --socket=/mysqldata/kmac/socket/mysql.sock --port=3304八、客户端连接实例与权限[mysql@Tanxuefeng ~]$ mysql -u root -h127.0.0.1 -P3308Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 2Server version: 5.5.25-log Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type help; or h for help. Type c to clear the current input statement.mysql> grant all privileges on *.* to root@"%" identified by "root123";Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)创建账户:mysql> insert into mysql.user(Host,User,Password) values(localhost,admin,password(admin));Query OK, 1 row affected, 3 warnings (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> grant all on *.* to admin@% identified by admin with grant option;Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)附录 1:支撑软件包安装
  • 8. (1)安装 GCC[root@Tanxuefeng app]# mount /dev/cdrom /app/cdmount: block device /dev/sr0 is write-protected, mounting read-only[root@Tanxuefeng app]# cd /app/cd[root@Tanxuefeng cd]# find ./ -name gcc*./Packages/gcc-4.4.4-13.el6.i686.rpm./Packages/gcc-c++-4.4.4-13.el6.i686.rpm./Packages/gcc-gfortran-4.4.4-13.el6.i686.rpm…………[root@Tanxuefeng cd]# rpm -ivh ./Packages/gcc-4.4.4-13.el6.i686.rpm ./Packages/gcc-c++-4.4.4-13.el6.i686.rpmwarning: ./Packages/gcc-4.4.4-13.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key IDfd431d51: NOKEYPreparing... ########################################### [100%] package gcc-4.4.4-13.el6.i686 is already installed package gcc-c++-4.4.4-13.el6.i686 is already installed[root@Tanxuefeng cd]#( 2)安装 cmake[root@Tanxuefeng cd]# find ./ -name cmake*./Packages/cmake-2.6.4-5.el6.i686.rpm[root@Tanxuefeng cd]# rpm -ivh ./Packages/cmake-2.6.4-5.el6.i686.rpmwarning: ./Packages/cmake-2.6.4-5.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key IDfd431d51: NOKEYPreparing... ########################################### [100%] package cmake-2.6.4-5.el6.i686 is already installed[root@Tanxuefeng cd]#(3)安装 ncurses-devel[root@Tanxuefeng cd]# find ./ -name ncurses-devel*./Packages/ncurses-devel-5.7-3.20090208.el6.i686.rpm[root@Tanxuefeng cd]# rpm -ivh ./Packages/ncurses-devel-5.7-3.20090208.el6.i686.rpmwarning: ./Packages/ncurses-devel-5.7-3.20090208.el6.i686.rpm: Header V3 RSA/SHA256 Signature,key ID fd431d51: NOKEYPreparing... ########################################### [100%] package ncurses-devel-5.7-3.20090208.el6.i686 is already installed[root@Tanxuefeng cd]#附录 2:开启防火器端口:在防火墙上打开端口 3306[root@Tanxuefeng app]# iptables -I INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT[root@Tanxuefeng app]# iptables -I OUTPUT -o eth0 -p tcp --sport 3306 -j ACCEPT[root@Tanxuefeng app]# /etc/rc.d/init.d/iptables save
  • 9. iptables:将防火墙规则保存到 /etc/sysconfig/iptables:[确定]