实现基于mysql主从模式的mogilefs
来源:互联网 发布:无线网卡安装后无网络 编辑:程序博客网 时间:2024/05/29 04:23
实验环境:
Mysql-Master:172.17.253.96 mysql+tracker
Mysql-slave: 172.17.253.101 mysql+tracker
Node1:172.17.253.77 tracker+store
Node2:172.17.253.34 tracker+store
Node3:172.17.253.13 tracker+store
1、 首先实现数据库的主从复制。
mysql-master(172.17.253.96):
[root@centos7 ~]# yum install mairadb-server vim /etc/my.cnf [mysqld] server_id=1 log_bin=master_bin[root@centos7 ~]# systemctl start mariadb[root@centos7 ~]# mysql –urootMariaDB [(none)]> grant replication slave,replication client on *.* to slave@'%' identified by 'centos';MariaDB [(none)]> show master status; +-------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+-------------------+----------+--------------+------------------+| master_bin.000002 | 604 | | |+-------------------+----------+--------------+------------------+1 row in set (0.00 sec)
mysql-slave(172.17.253.101):
vim /etc/my.cnf [mysqld] server_id=2 relay_log=mysql_relay_bin log_bin=master_bin log_slave_updates=1[root@centos7 ~]# systemctl start mariadb[root@centos7 ~]# mysql –urootMariaDB [(none)]> change master to master_host='172.17.253.96',master_user='slave',master_password='centos',master_log_file='master_bin.000002',master_log_pos=604;MariaDB [(none)]> start slave;MariaDB [(none)]> show slave status\G;*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 172.17.253.96 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master_bin.000002 Read_Master_Log_Pos: 95693 Relay_Log_File: mysql_relay_bin.000002 Relay_Log_Pos: 95619 Relay_Master_Log_File: master_bin.000002 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: 95693 Relay_Log_Space: 95913 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: 0Master_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: 11 row in set (0.00 sec)ERROR: No query specified
Mysql数据库主从实现~~~
2、配置Perl环境、安装包:
[root@centos7 ~]# yum install perl-Net-Netmask perl-IO-String perl-Sys-Syslog perl-IO-AIO –y
实验包:
MogileFS-Server-2.46-2.el7.centos.noarch.rpm
perl-Danga-Socket-1.61-1.el6.rf.noarch.rpm
MogileFS-Server-mogilefsd-2.46-2.el7.centos.noarch.rpm
perl-MogileFS-Client-1.14-1.el7.centos.noarch.rpm
MogileFS-Server-mogstored-2.46-2.el7.centos.noarch.rpm
perl-Perlbal-1.78-1.el6.noarch.rpm
MogileFS-Utils-2.19-1.el7.centos.noarch.rpm
各自对照相应主机的环境,安装相应的包。
Mysql-master:
[root@centos7 ~]# mysql –urootMariaDB [(none)]> GRANT ALL PRIVILEGES ON mogilefs.* TO mogile@'172.17.%.%' IDENTIFIED BY 'mogile' WITH GRANT OPTION;Query OK, 0 rows affected (0.00 sec)[root@centos7-4 ~]# mogdbsetup --dbhost=127.0.0.1 --dbuser=mogilefs --dbpass=mogile --yes登录数据库查看是否已经生成数据库:[root@centos7 ~]# mysql -urootMariaDB [(none)]> show databases;+--------------------+| Database |+--------------------+| information_schema || mogilefs || mysql || performance_schema || test || wan || wan2 || wan3 |+--------------------+8 rows in set (0.12 sec)MariaDB [(none)]> use mogilefs;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedMariaDB [mogilefs]> show tables;+----------------------+| Tables_in_mogilefs |+----------------------+| checksum || class || device || domain || file || file_on || file_on_corrupt || file_to_delete || file_to_delete2 || file_to_delete_later || file_to_queue || file_to_replicate || fsck_log || host || server_settings || tempfile || unreachable_fids |+----------------------+17 rows in set (0.00 sec)
在使用安装包直接安装mogilefs时会有安装脚本来创建mogilefs用户,如果是编译安装,则需要手动创建这个用户。
[root@centos7 ~]# useradd mogilefs
修改tracker配置文件,配置文件为/etc/mogilefs/mogilefsd.conf:
Vim /etc/mogilefs/mogilefsd.conf# Enable daemon mode to work in background and use syslogdaemonize = 1# Where to store the pid of the daemon (must be the same in the init script)pidfile = /var/run/mogilefsd/mogilefsd.pid# Database connection informationdb_dsn = DBI:mysql:mogilefs:host=127.0.0.1db_user = mogiledb_pass = mogile# IP:PORT to listen on for mogilefs client requestslisten = 172.17.253.96:7001# Optional, if you don't define the port above.conf_port = 7001# Number of query workers to start by default.query_jobs = 10# Number of delete workers to start by default.delete_jobs = 1# Number of replicate workers to start by default.replicate_jobs = 5# Number of reaper workers to start by default.# (you don't usually need to increase this)reaper_jobs = 1# Number of fsck workers to start by default.# (these can cause a lot of load when fsck'ing)#fsck_jobs = 1# Minimum amount of space to reserve in megabytes# default: 100# Consider setting this to be larger than the largest file you# would normally be uploading.#min_free_space = 200# Number of seconds to wait for a storage node to respond.# default: 2# Keep this low, so busy storage nodes are quickly ignored.#node_timeout = 2# Number of seconds to wait to connect to a storage node.# default: 2# Keep this low so overloaded nodes get skipped.#conn_timeout = 2# Allow replication to use the secondary node get port,# if you have apache or similar configured for GET's#repl_use_get_port = 1
启动tracker服务,服务脚本为:
[root@centos7 ~]# /etc/init.d/mogilefsd start
Starting mogilefsd (via systemctl): [ OK ]
【注】如果服务启动服务报错,查看错误日志,再次检查Perl环境是否配置完整。
Mysql-slave主机上同样启动track服务即可。
3、配置节点上三台主机。Tracker+store
Tracker配置同上面所设置,只是数据库设置时,要指向mysql-master 主机地址,即:
vim /etc/mogilefs/mogilefsd.conf db_dsn = DBI:mysql:mogilefs:host=172.17.253.96 db_user = mogile db_pass = mogile listen = 172.17.253.77:7001store节点配置文件:vim /etc/mogilefs/mogstored.conf maxconns = 10000 httplisten = 0.0.0.0:7500 mgmtlisten = 0.0.0.0:7501 docroot = /data/mogdata #数据存储的路径
创建数据存储路径:
[root@centos7 ~]# mkdir –p /data/mogdata
[root@centos7 ~]# chown –R mogilefs:mogilefs /data/mogdata/
启动服务:
[root@centos7-4 ~]# /etc/init.d/mogilefsd start[root@centos7-4 ~]# /etc/init.d/mogstored start[root@centos7-4 ~]# ss –ntlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:7500 *:* LISTEN 0 128 *:7501 *:* LISTEN 0 128 *:111 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 128 172.17.253.77:7001 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:9000 *:* LISTEN 0 128 :::111 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::*
其余两台主机同样配置。
mogstored程序的启动使主机自身成为一个存储的节点,mogstored的启动后,还需要使用mogadm来让当前的这个主机加入到mogilefs的系统中,这就是一个存储节点。注意存储节点中还需要添加设备,每个设备有一个唯一的ID号,同样也要使用mogadm来加入到mogilefs的系统中。
4、tracker主机上配置
增加节点:
[root@centos7 ~]# mmogadm --trackers=172.17.253.96:7001 host add node1 --ip=172.17.253.77 --port=7500 --status=alive[root@centos7 ~]# mogadm --trackers=172.17.253.96:7001 host add node2 --ip=172.17.253.34 --port=7500 --status=alive[root@centos7 ~]# mogadm --trackers=172.17.253.96:7001 host add node3 --ip=172.17.253.11 --port=7500 --status=alive
删除节点:
mogadm –trackers=172.17.253.96:7001 host delete node1
修改节点:
mogadm –trackers=172.17.253.96:7001 host modify node2 –ip=xxxx –port=7500 –status=alive
查看增加的节点:
[root@centos7 ~]# mogadm --trackers=172.17.253.96:7001 host listnode1 [1]: alive IP: 172.17.253.77:7500node2 [2]: alive IP: 172.17.253.34:7500node3 [3]: alive IP: 172.17.253.13:7500或者使用:[root@centos7 ~]# mogadm --trackers=172.17.253.96:7001 checkChecking trackers... 172.17.253.96:7001 ... OKChecking hosts... [ 1] node1 ... OK [ 2] node2 ... OK [ 3] node3 ... OKChecking devices... host device size(G) used(G) free(G) use% ob state I/O% ---- ------------ ---------- ---------- ---------- ------ ---------- ----- [ 1] dev1 46.543 5.138 41.405 11.04% writeable 0.0 [ 2] dev2 49.976 3.755 46.221 7.51% writeable 0.0 [ 3] dev3 49.976 1.678 48.297 3.36% writeable N/A ---- ------------ ---------- ---------- ---------- ------ total: 146.494 10.571 135.923 7.22%
5、添加设备存储节点:
[root@centos7 ~]# modadm –trackers=172.17.253.96:7001 device add node1 1[root@centos7 ~]# modadm –trackers=172.17.253.96:7001 device add node2 2[root@centos7 ~]# modadm –trackers=172.17.253.96:7001 device add node3 3 #ID号不能重复
分别在store节点上创建存储路径:
node1: # mkdir /data/mogdata/dev1 -p # chown mogilefs:mogilefs dev1/node2: # mkdir /data/mogdata/dev2 -p # chown mogilefs:mogilefs dev2/node3: # mkdir /data/mogdata/dev3 -p # chown mogilefs:mogilefs dev3/
查看添加的节点:
[root@centos7 ~]# mogadm --trackers=172.17.253.96:7001 device listnode1 [1]: alive used(G) free(G) total(G) weight(%) dev1: alive 5.138 41.404 46.542 100node2 [2]: alive used(G) free(G) total(G) weight(%) dev2: alive 3.755 46.221 49.976 100node3 [3]: alive used(G) free(G) total(G) weight(%) dev3: alive 1.678 48.298 49.976 100
删除设备存储节点:
[root@centos7 ~]# mogadm –trackers=172.17.253.96:7001 device mark node1 1 dead
6、添加域
[root@centos7 ~]# mogadm –trackers=172.17.253.96:7001 domain add img
[root@centos7 ~]# mogadm –trackers=172.17.253.96:7001 domain add html
7、添加类:
默认会自动创建类:[root@centos7 ~]# mogadm --trackers=172.17.253.96:7001 domain list domain class mindevcount replpolicy hashtype-------------------- -------------------- ------------- ------------ ------- html default 2 MultipleHosts() NONE NONE img default 2 MultipleHosts() NONE 创建自定义类:[root@centos7 ~]# mogadm --trackers=172.17.253.96:7001 class add img ckltext --mindevcount=3查看类列表:[root@centos7 ~]# mogadm --trackers=172.17.253.96:7001 domain list domain class mindevcount replpolicy hashtype-------------------- -------------------- ------------- ------------ ------- html default 2 MultipleHosts() NONE img ckltext 3 MultipleHosts() NONE img default 2 MultipleHosts() NONE
8、上传文件测试:
[root@centos7 ~]# mogupload --trackers=172.17.253.77:7001 --domain=img --key='110' --file=/root/test2.jpg[root@centos7 ~]# mogfileinfo --trackers=172.17.253.77:7001 --domain=img --key='110'- file: 110 class: default devcount: 1 domain: img fid: 28 key: 110 length: 73309 - http://172.17.253.13:7500/dev3/0/000/000/0000000028.fid[root@centos7 ~]# mogupload --trackers=172.17.253.96:7001 --domain=img --key='111' --file=/root/test.jpg[root@centos7 ~]# mogfileinfo --trackers=172.17.253.96:7001 --domain=img --key='111' - file: 111 class: default devcount: 1 domain: img fid: 29 key: 111 length: 17316 - http://172.17.253.34:7500/dev2/0/000/000/0000000029.fid
网页访问:
【注】对于mysql主从复制的实现,还可以结合keepalived。IP漂移来更完美的实现数据库的自动复制。
- 实现基于mysql主从模式的mogilefs
- MogileFS DB 安装及配置--Mysql的主从安装&
- MySQL基于GTID模式的主从复制设置
- MySQL基于非GTID模式的主从同步设置
- 基于SSL实现MySQL的加密主从复制
- 基于semisync实现MySQL的主从半同步复制
- 基于SSL实现MySQL的加密主从复制
- MySQL主从复制实现基于日志点的复制
- 基于SSL实现Mysql加密的主从复制配置
- Mysql主从模式的原理
- SSM框架下Mysql主从模式实现
- mysql主从复制的实现
- Mysql主从方案的实现
- mysql主从复制的实现
- mysql主从复制的实现
- MySql基于GTID主从复制的搭建
- MySQL基于GTIDs的主从复制
- 基于mysql主从的读写分离
- 排序算法
- 封装适配器
- Java技术----Java泛型详解
- String.split()方法,返回是一个数组
- Caffe转换图像为lmdb并计算均值
- 实现基于mysql主从模式的mogilefs
- 2017 ACM-ICPC 南宁站 总结!
- HTTPS的介绍
- leetcode 21-Merge Two Sorted Lists
- web 面试
- Impala-大数据时代快速SQL引擎
- Android studio 编译报错 Error:null value in entry: outputDirectory=null
- Google Data Binding Library 谷歌官方数据绑定库(四) 语法和运算符
- ionic2/ionic3自由隐藏底部tab栏---让ionic3自己解决!手把手教程