给数据库用户配置
groupadd mysql
useradd -g mysql mysql -s /sbin/nologin
rm -rf /home/mysql
mkdir -p /opt/mysql
chmod -R 755 /opt/mysql
chown -R mysql:mysql /opt/mysql
准备工作:安装基本依赖包,先用yum安装cmake、automake 、autoconf ,另MySQL 5.5.x需要最少安装的包有:bison,gcc、gcc-c++、ncurses-devel
yum -y install gcc gcc-c++ autoconf bison automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*
安装cmake(mysql5.5以后是通过cmake来编译的)
axel -n 10 http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
tar zxvf cmake-2.8.4.tar.gz
./bootstrap
gmake install
下载解压mysql 5.5.11
axel -n 10 http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.30.tar.gz
tar zxfv mysql-5.5.30.tar.gz
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/opt/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=0 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=no \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_ZLIB=system \
-DINSTALL_PLUGINDIR=lib64/mysql/plugin \
-DINSTALL_LIBDIR=lib64/mysql \
-DINSTALL_INCLUDEDIR=include/mysql \
-DWITH_DEBUG=0
碰到了错误:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:127 (FIND_CURSES)
cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:269 (MYSQL_CHECK_READLINE)
-- Configuring incomplete, errors occurred!
是因为少了ncurses-devel这个包。
用yum安装后,然后把目录下的CMakeCache.txt 删除,否则还是报之前的错误
然后就是make && make install
cp support-files/my-medium.cnf /etc/my.cnf
chown -R mysql:mysql mysql/
opt]# /opt/mysql/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/opt/data
/usr/local/mysql/bin/mysqld_safe --user=mysql & 启动mysql
cp mysql-5.5.30/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chown .mysql /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
接下来开始部署主从环境
在主服务器上配置mysql的配置文件
确保/etc/my.cnf中有如下参数,没有的话需手工添加,并重启mysql服务。
[mysqld]
log-bin=mysql-bin 启动二进制文件
server-id=1 服务器ID
然后进入到mysql数据库里进行授权
grant replication slave on *.* to 'backup'@'x.x.x.x' identified by 'backup';
查询主数据库状态,并记下FILE及Position的值,这个在后面配置从服务器的时候要用到
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000010 | 264 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
主数据库的操作就到这里,下面的操作在从服务器上操作
确保/etc/my.cnf中有log-bin=mysql-bin和server-id=1参数,并把server-id=1修改为server-id=10。修改之后如下所示:
[mysqld]
log-bin=mysql-bin 启动二进制文件
server-id=10 服务器ID
重启mysql服务。登录mysql,执行如下语句
change master to master_host='o.o.o.o',master_user='backup',master_password='backup',master_log_file='mysql-bin.000010',master_log_pos=264;
启动slave同步。
start slave;
检查主从同步,如果您看到Slave_IO_Running和Slave_SQL_Running均为Yes,则主从复制连接正常。
show slave status\G
注: 删除mysql日志文件后报I/O error reading the header from the binary log, errno=175, io cache
data目录下日志文件很多,很烦,把mysql-bin.000001~mysql-bin.0000018都删掉了。结果报以下错误:
120914 10:23:31 [ERROR] I/O error reading the header from the binary log, errno=175, io cache code=0
120914 10:23:31 [ERROR] I/O error reading the header from the binary log
120914 10:23:31 [ERROR] Can't init tc log
120914 10:23:31 [ERROR] Aborting
解决办法:
把剩下的有关日志的文件都删掉。把ibdata1,ib_logfile0,ib_logfile1,mysql-bin.index,再启动就可以了