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

[经验分享] 利用tcmalloc优化mysql主从

[复制链接]

尚未签到

发表于 2018-9-30 09:58:57 | 显示全部楼层 |阅读模式
  实现环境:mysql 5.5.27,cenot 6.2 64bit,centos 最小化安装。软件cmake-2.8.8.tar.gz,
  libunwind-1.0.tar.gz ,gperftools-2.0.tar.gz 。
  一,主服务器IP:192.168.1.15,从服务器IP:192.168.1.16。先配置主服务器,安装好系统后需要安装开发环境:yum -y groupinstall 'Development tools' ,centos 6.0的系统只需安装Development tools。
  二,安装libunwind和gperftools。

  •   安装libunwind库。
  •   # tar xf libunwind-1.0.tar.gz
  •   # tar xf libunwind-1.0
  •   #CFLAGS=-fPIC ./configure添加编译参数
  •   # make CFLAGS=-fPIC
  •   # make CFLAGS=-fPIC install
  •   这样执行会出现如下错误:

  •   libtool: install: error:>
  •   make[3]: *** [install-libLTLIBRARIES] Error 1
  •   make[3]: Leaving directory `/down/libunwind-1.0/src'
  •   make[2]: *** [install-am] Error 2
  •   make[2]: Leaving directory `/down/libunwind-1.0/src'
  •   make[1]: *** [install] Error 2
  •   make[1]: Leaving directory `/down/libunwind-1.0/src'
  •   make: *** [install-recursive] Error 1
  •   产生这种问题的原因:autotools兼容性的问题,运行命令autoreconf -i -f ,在重新编译安装下。
  •   #autoreconf -i -f
  •   #make clean
  •   #CFLAGS=-fPIC ./configure
  •   #make CFLAGS=-fPIC
  •   #make CFLAGS=-fPIC install
  •   安装gpperftools:
  •   #tar xf gperftools-2.0.tar.gz
  •   # cd gperftools-2.0
  •   #./configure
  •   #make && make install
  •   这样安装会会报如下错误:
  •   cc1plus: warning: unrecognized command line option "-Wno-unused-result"
  •   ake: *** [stacktrace.lo] Error 1
  •   为什么出现在这种错误,因此是64bit系统,至于更深度的解释,安装说明中有。下面重新编译。
  •   #make clean
  •   #./configure --enable-frame-pointers
  •   #make && make install
  •   #echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  •   #ldconfig
  三,安装cmake与mysql

  •   安装cmake
  •   #tar xf cmake-2.8.8.tar.gz
  •   #cd cmake-2.8.8
  •   # ./bootstrap
  •   # gmake && gmake install
  •   安装mysql
  •   #useradd -r mysql -s /sbin/nologin
  •   #mkdir -p /data/mysql/{data,binlog,relaylog}
  •   #chown mysql:mysql -R /data/mysql
  •   # tar xf mysql-5.5.27.tar.gz
  •   #cd mysql-5.5.27
  •   #cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1       -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/data -DWITH_DEBUG=0-DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306
  •   #会编译不过去,提示需要安装ncurses-devel,yum -y install ncurses-devel
  •   #rm -f CMakeCache.txe 重新执行./configure
  •   # make && make install
  •   #cd /usr/local/mysql
  •   #chown -R mysql:mysql *
  •   # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
  •   #chmod +x /etc/init.d/mysqld
  •   #chkconfig mysqld on
  •   # vim /etc/profile 添加PATH=$PATH:/usr/local/mysql/bin
  •   # . /etc/profile(或者export PATH=$PATH:/usr/local/mysql/bin)
  •   # ln -sv /usr/local/mysql/include/ /usr/include/mysql
  •   # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf 加载库文件
  •   # ldconfig -v |grep mysql
  •   # vim /etc/man.config 添加一行MANPATH /usr/local/mysql/man
  •   #sed -i '/# executing mysqld_safe/a\export LD_PRELOAD=/usr/local/lib/libtcmalloc.so' /usr/local/mysql/bin/mysqld_safe
  •   环境已经基本Ok
  •   # cd /usr/local/mysql
  •   scripts/mysql_install_db --user=mysql--datadir=/data/mysql
  将主服务器克隆一份,并修改IP与MAC地址,保证两台机器能够互相ping通。
  三,下面是master的配置文件:

  •   [client]
  •   default-character-set = utf8
  •   port=3306
  •   socket = /tmp/mysql.sock
  •   [mysqld]
  •   user = mysql
  •   port=3306
  •   socket = /tmp/mysql.sock
  •   basedir = /usr/local/mysql
  •   datadir=/data/mysql/data
  •   pid-file = /data/mysql/mysql.pid
  •   log-error = /data/mysql/mysql-error.log
  •   log_slave_update =1
  •   log-bin = /data/mysql/binlog/mysql-bin
  •   log-bin-index = /data/mysql/binlog/mysql-bin.index
  •   binlog_format = mixed
  •   binlog_cache_size = 4M
  •   max_binlog_cache_size = 8M
  •   max_binlog_size = 1G
  •   expire_logs_days = 30
  •   key_buffer_size = 384M
  •   sort_buffer_size = 2M
  •   read_buffer_size = 2M
  •   read_rnd_buffer_size =16M
  •   join_buffer_size =2M
  •   thread_cache_size = 300
  •   query_cache_limit = 2M
  •   query_cache_min_res_unit =2K
  •   thread_concurrency = 8
  •   table_cache =614
  •   table_open_cache = 512
  •   open_files_limit = 10240
  •   back_log = 600
  •   max_connections = 5000
  •   max_connect_errors = 6000
  •   external-locking = FALSE
  •   max_allowed_packet =16M
  •   default_storage_engine = MyISAM
  •   #default_storage_engine = InnoDB
  •   thread_stack =192K
  •   transaction_isolation = REPEATABLE-READ
  •   tmp_table_size = 256M
  •   max_heap_table_size =512M
  •   bulk_insert_buffer_size = 64M
  •   myisam_sort_buffer_size = 64M
  •   myisam_max_sort_file_size = 10G
  •   myisam_repair_threads = 1
  •   myisam_recover
  •   long_query_time = 2
  •   skip-name-resolve
  •   skip-external_locking
  •   #skip-innodb
  •   innodb_additional_mem_pool_size = 16M
  •   innodb_buffer_pool_size = 512M
  •   innodb_data_file_path = ibdata1:256M:autoextend
  •   innodb_file_io_threads = 4
  •   innodb_thread_concurrency = 8
  •   innodb_flush_log_at_trx_commit =2
  •   innodb_log_file_size =128M
  •   innodb_log_files_in_group = 3
  •   innodb_max_dirty_pages_pct = 90
  •   innodb_lock_wait_timeout =120
  •   innodb_file_per_table = 0
  •   interactive_timeout=120
  •   wait_timeout=120
  •   slave-skip-errors=1032,1062,126,1114,1146,1048,1396
  •   server-id=1
  •   [mysqldump]
  •   quick
  •   max_allowed_packet = 64M
  •   [mysql]
  •   no-auto-rehash
  •   [myisamchk]
  •   key_buffer_size = 256M
  •   sort_buffer_size = 256M
  •   read_buffer = 2M
  •   write_buffer = 2M
  slave的配置信息:
  #vim /etc/my.cnf

  •   [client]
  •   default-character-set = utf8
  •   port=3306
  •   socket = /tmp/mysql.sock
  •   [mysqld]
  •   user = mysql
  •   port=3306
  •   socket = /tmp/mysql.sock
  •   basedir = /usr/local/mysql
  •   datadir=/data/mysql/data
  •   pid-file = /data/mysql/mysql.pid
  •   log-error = /data/mysql/mysql-error.log
  •   replicate-ignore-db=mysql
  •   replicate-ignore-db=test
  •   replicate-ignore-db=information_schema
  •   log_slave_update =1
  •   log-bin = /data/mysql/binlog/mysql-bin
  •   log-bin-index = /data/mysql/binlog/mysql-bin.index
  •   binlog_format = mixed
  •   binlog_cache_size = 4M
  •   max_binlog_cache_size = 8M
  •   max_binlog_size = 1G
  •   expire_logs_days = 30
  •   relay-log-index=/data/mysql/relaylog/relay.index
  •   relay-log-info-file=/data/mysql/relaylog/relay.info
  •   relay-log=/data/mysql/relaylog/relaylog
  •   key_buffer_size = 384M
  •   sort_buffer_size = 2M
  •   read_buffer_size = 2M
  •   read_rnd_buffer_size =16M
  •   join_buffer_size =2M
  •   thread_cache_size = 300
  •   query_cache_limit = 2M
  •   query_cache_min_res_unit =2K
  •   thread_concurrency = 8
  •   table_cache =614
  •   table_open_cache = 512
  •   open_files_limit = 10240
  •   back_log = 600
  •   max_connections = 5000
  •   max_connect_errors = 6000
  •   external-locking = FALSE
  •   max_allowed_packet =16M
  •   default_storage_engine = MyISAM
  •   #default_storage_engine = InnoDB
  •   thread_stack =192K
  •   transaction_isolation = REPEATABLE-READ
  •   tmp_table_size = 256M
  •   max_heap_table_size =512M
  •   bulk_insert_buffer_size = 64M
  •   myisam_sort_buffer_size = 64M
  •   myisam_max_sort_file_size = 10G
  •   myisam_repair_threads = 1
  •   myisam_recover
  •   long_query_time = 2
  •   slow_query_log =on
  •   slow_query_log_file = /data/mysql/slow.log
  •   skip-name-resolve
  •   skip-external_locking
  •   #skip-innodb
  •   innodb_additional_mem_pool_size = 16M
  •   innodb_buffer_pool_size = 512M
  •   innodb_data_file_path = ibdata1:256M:autoextend
  •   innodb_file_io_threads = 4
  •   innodb_thread_concurrency = 8
  •   innodb_flush_log_at_trx_commit =2
  •   innodb_log_file_size =128M
  •   innodb_log_files_in_group = 3
  •   innodb_max_dirty_pages_pct = 90
  •   innodb_lock_wait_timeout =120
  •   innodb_file_per_table = 0
  •   interactive_timeout=120
  •   wait_timeout=120
  •   slave-skip-errors=1032,1062,126,1114,1146,1048,1396
  •   server-id=2
  •   read-only=1
  •   [mysqldump]
  •   quick
  •   max_allowed_packet = 64M
  •   [mysql]
  •   no-auto-rehash
  •   [myisamchk]
  •   key_buffer_size = 256M
  •   sort_buffer_size = 256M
  •   read_buffer = 2M
  •   write_buffer = 2M
  到此可以分别对两台服务器进行初始化:分别执行

  •   #cd /usr/local/mysql
  •   #scripts/mysql_install_db --user=mysql--datadir=/data/mysql/data
  •   #/etc/init.d/mysqld start
  如果启动出现错误在mysql-error.log中出现:
  Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

  •   解决步骤:
  •   #cd /data/mysql
  •   #rm -rf *
  •   #mkdir {data,binlog,relaylog}
  •   #chown -R mysql:mysql /data/mysql
  •   #cd /usr/local/mysql
  •   #scripts/mysql_install_db --user=mysql--datadir=/data/mysql/data
  •   #/etc/init.d/mysqld start
  导致这种问题的产生是因为数据目录不一到导致的。
  四,在主服务器上添加复制用户:


  •   mysql>grant replication slave on *.* to 'rpuser'@'192.168.1.16'>
  •   mysql> flush privileges;
  •   mysql> flush tables with read lock;
  •   mysql> show master status;这一步显示的信息对我没用,因为我的主服务器已经运行一段时间。但是数据量又不是大。
      +------------------+----------+-------------------------------+------------------+
      | File  | Position | Binlog_Do_DB   | Binlog_Ignore_DB |
      +------------------+----------+-------------------------------+------------------+
      | mysql-bin.000005 | 102020 | billing,birdtalk,imsi,meeting |   |
  •   mysql> unlock tables;
  五,在从服务器上先测试刚创建的用户能否登录
  #mysql -urpuser -p -h192.168.1.15 能正常登录,则继续下一下。

  •   mysql> slave stop;
  •   mysql>change master to
  •   ->master_host='192.168.1.15',
  •   ->master_user='rpuser',
  •   ->master_password='123456',
  •   ->master_log_file='mysql-bin.000005',
  •   ->master_log_pos=102020;
  •   mysql>start slave;
  •   mysql>show slave status\G;
  •   mysql>show databases;过几分钟执行
  •   泥玛,四个数据库既然没有同步过来。速度不指定复制位置,
  •   mysql>slave stop;
  •   mysql>change master tomaster_host='192.168.1.15',master_user='rpuser',master_password=123456;
  •   mysql>start slave;
  •   mysql> show slave status \G
      *************************** 1. row ***************************

      Slave_IO_State: Queueing master event to the>  Master_Host: 192.168.1.15
      Master_User: rpuser
      Master_Port: 3306
      Connect_Retry: 60
      Master_Log_File: mysql-bin.000004
      Read_Master_Log_Pos: 160393581

      Relay_Log_File:>  Relay_Log_Pos: 32226033

      >  Slave_IO_Running: Yes 这个两个线程正常启动,表示从服务器成功。
      Slave_SQL_Running: Yes
      Replicate_Do_DB:
      Replicate_Ignore_DB: mysql,test,information_schema
      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: 32225887
      Relay_Log_Space: 186392166
      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: 737685
      Master_SSL_Verify_Server_Cert: No
      Last_IO_Errno: 0
      Last_IO_Error:
      Last_SQL_Errno: 0
      Last_SQL_Error:
      Replicate_Ignore_Server_Ids:
      Master_Server_Id: 1

  ERROR 1201 (HY000) at line 22: Could not initialize master info structure; more error messages can be found in the MySQL error log。
  如果出现这个错误,则需要检查配置文件中的日志的路径是否正确,如是不正确会导致这个问题的发生,

  •   #/etc/init.d/mysqld stop
  •   #vim /etc/my.cnf
  •   #cd /data/mysql/data
  •   #rm -f master.info
  •   #/etc/init.d/mysqld start
  •   #mysql> stop slave;
  •   #mysql>change master to master_host='192.168.1.15',master_user='rpuser',master_password='123456';



运维网声明 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-606593-1-1.html 上篇帖子: 【MySQL】《高性能MySQL》学习笔记,第四章,Schema与数据类型优化 下篇帖子: mysql cluster 7.2在线添加数数据节点
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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