设为首页 收藏本站
查看: 840|回复: 0

[经验分享] mysql主从复制及mysql-proxy0.8安装

[复制链接]

尚未签到

发表于 2018-9-27 10:10:54 | 显示全部楼层 |阅读模式
  Mysql主从复制
  (一)安装mysql(主从服务器皆相同) 先创建用户 useradd mysql -s /sbin/nologin
  tar zxvf mysql-5.1.49.tar.gz
  cd mysql-5.1.49
  [root@centos mysql-5.1.49]# ./configure --prefix=/usr/local/mysql --localstatedir=/opt/data --with-extra-charsets=utf8,gb2312,gbk --with-pthread --enable-thread-safe-client
  注:配置过程指定数据文件的位置及另加的字符集.
  make
  make install
  cp support-files/my-large.cnf /etc/my.cnf
  cd /usr/local/mysql
  chgrp -R mysql .
  生成基本的数据库和表: /usr/local/mysql/bin/mysql_install_db --user=mysql
  成功执行后察看数据目录/opt/data,看是否有文件或目录生成.
  chown -R mysql:mysql /opt/data
  记得给每个数据库设置root密码.
  (二)修改配置文件
  不同的地方就是server-id,主服务器配置文件不用修改,从服务器的配置文件server-id=10.其他的内容基本相同.
  (三)启动服务
  /usr/local/mysql/bin/mysqld_safe --user=mysql&
  这个过程主辅服务器都相同.
  (四)授权(在主服务器上进行)

  GRANT REPLICATION SLAVE ON *.* to 'rep1'@192.168.0.17>  (五)查询主数据库状态(主服务器上进行)
  mysql> show master status;
  +------------------+----------+--------------+------------------+
  | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  +------------------+----------+--------------+------------------+
  | mysql-bin.000003 |      240 |              |                  |
  +------------------+----------+--------------+------------------+
  1 row in set (0.00 sec)
  记下file及position的值,后面做从服务器操作的时候需要用.
  (六)配置从服务器
  mysql> change master to master_host='192.168.0.16', master_user='rep1', master_password='mysql', master_log_file='mysql-bin.000003', master_log_pos=240;
  正确执行后再执行:
  mysql> start slave;
  就启用了复制功能.这里我们运行一下 mysql> show slave status\G 来检查一下,一个正常的输出结果应该如下面的形式:
  mysql> show slave status\G;
  *************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
  Master_Host: 192.168.0.16
  Master_User: rep1
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: mysql-bin.000003
  Read_Master_Log_Pos: 240

  >
  >
  >  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Replicate_Do_DB:
  Replicate_Ignore_DB:
  Replicate_Do_Table:
  Replicate_Ignore_Table:
  Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
  Last_Errno: 0
  Last_Error:
  Skip_Counter: 0
  Exec_Master_Log_Pos: 240

  >  Until_Condition: None
  Until_Log_File:
  Until_Log_Pos: 0
  Master_SSL_Allowed: No
  Master_SSL_CA_File:
  Master_SSL_CA_Path:
  Master_SSL_Cert:
  Master_SSL_Cipher:
  Master_SSL_Key:
  Seconds_Behind_Master: 0
  Master_SSL_Verify_Server_Cert: No
  Last_IO_Errno: 0
  Last_IO_Error:
  Last_SQL_Errno: 0
  Last_SQL_Error:
  1 row in set (0.00 sec)
  ERROR:
  No query specified
  mysql>
  (七)主数据库有数据的情况:
  1、数据库锁表操作,不让数据再进行写入动作。mysql> FLUSH TABLES WITH READ LOCK;
  2、察看主数据库的状态 mysql> show master status; 照第(五)步记录输出值。
  3、把主服务器数据文件复制到从服务器,最好先用tar处理一下。
  4、取消主数据库锁定 mysql> UNLOCK TABLES;
  5、从服务器的操作。跟前面的步骤一样(略过)
  mysql代理安装配置
  一、安装mysql-proxy.需要按下列顺序安装其所依赖的包:
  (一)安装LUA
  tar zxvf lua-5.1.4.tar.gz
  cd lua-5.1.4
  用vi修改Makefile,使"INSTALL_TOP=/usr/local/lua",这样做的目的是为了是lua的所有文件都安装在目录/usr/local/lua/
  make posix
  make install
  (二)安装 libevent
  tar zxvf libevent-1.4.14b-stable.tar.gz
  cd libevent-1.4.14b-stable
  ./configure --prefix=/usr/local/libevent
  make
  make install
  (三)安装check
  tar zxvf check-0.9.8.tar.gz
  cd check-0.9.8
  ./configure
  make
  make install
  (四)设置安装mysql-proxy所需的环境变量.把下面的内容追加到/etc/profile中
  export LUA_CFLAGS="-I/usr/local/lua/include" LUA_LIBS="-L/usr/local/lua/lib -llua -ldl" LDFLAGS="-L/usr/local/libevent/lib -lm"
  export CPPFLAGS="-I/usr/local/libevent/include"
  export CFLAGS="-I/usr/local/libevent/include"
  然后执行 source /etc/profile (安装完mysql-proxy不再需要这些变量,可以删除之)
  (五)安装mysql(只安装mysql客户端即可)
  tar zxvf  mysql-5.1.49.tar.gz
  cd mysql-5.1.49
  ./configure --prefix=/usr/local/mysql  --without-server
  make
  make install
  编译安装glib-2.24.2.tar.gz
  [root@mysqlM ~]# cd glib-2.24.2
  [root@mysqlM glib-2.24.2]# ./configure
  [root@mysqlM glib-2.24.2]# make&make install
  #export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
  如果上面的不行,应该
  #export PKG_CONFIG_PATH=/usr/lib/pkgconfig
  (六)安装mysql-proxy
  tar zxvf  mysql-proxy-0.8.0.tar.gz
  cd  mysql-proxy-0.8.0
  [root@mysqlM mysql-proxy-0.8.0]# ./configure --prefix=/usr/local/mysql-proxy --with-mysql=/usr/local/mysql --with-lua
  [root@mysqlM mysql-proxy-0.8.0]# make
  [root@mysqlM mysql-proxy-0.8.0]# make install
  把路径加入path中
  [root@mysqlM bin]# pwd
  /usr/local/mysql-proxy/bin
  [root@mysqlM bin]# vi /etc/profile
  export PATH=$PATH:/usr/local/mysql-proxy/bin
  [root@mysqlM bin]# source /etc/profile
  [root@xutest opt]#mysql-proxy -V

  mysql-proxy: error while loading shared libraries: /usr/local/mysql-proxy/lib/libmysql-chassis.so.0: cannot restore segment prot after>  解决办法:
  编辑/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 - SELinux is fully disabled.
  SELINUX=enforcing
  把 SELINUX=enforcing 注释掉:#SELINUX=enforcing ,然后新加一行为:
  SELINUX=disabled
  保存,关闭
  在你保证SElinux 被disable后.还执行下:chcon -t texrel_shlib_t
  例:
  [root@testserver mysql-proxy-0.8.0]# chcon -t texrel_shlib_t /usr/local/mysql-proxy/lib/libmysql-chassis.so.0
  二:使用:
  [root@xutest opt]#mysql-proxy --help-all           #查看所有的设置选项
  管理功能选项
  --admin-address=host:port -- 指定一个mysqo-proxy的管理端口,缺省是 4041
  代理功能选项
  --proxy-address=host:port -- 这个是mysql-proxy 服务器端的监听端口,缺省是 4040
  --proxy-read-only-backend-addresses= -- 远程只读Slave服务器的地址和端口,缺省为不设置(本选项在mysql-proxy0.5.0版本中没有)
  --proxy-backend-addresses=host:port -- 指定远程MySQL服务器地址和端口,可以设置多个,
  --proxy-skip-profiling -- 关闭查询分析功能,缺省是打开的
  --proxy-fix-bug-25371 -- 修正 mysql的libmysql版本大于5.1.12的一个#25371号bug
  --proxy-lua-script=file -- 指定一个Lua脚本程序来控制mysql-proxy的运行和设置,这个脚本在每次新建连接和脚本发生修改的的时候将重新调用
  其他选项
  --daemon -- mysql-proxy以守护进程方式运行
  --pid-file=file -- 设置mysql-proxy的存储PID文件的路径
  看来mysql-proxy只能研究到这儿了,很多人都不建议这个东西应用到生产环境中,我也很害怕业务应用中我会死在这上面,还是等他成熟之后再说吧,听取秋香姐的建议,读写分离还是采用程序(他使用的是正则表达式)来实现吧。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-602669-1-1.html 上篇帖子: SuSE11安装MySQL5.6.40:RPM安装方式 下篇帖子: 3分钟了解Mysql空间搜GeoHash-DBAspace
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表