6543 发表于 2017-1-16 09:04:34

初始化mysql数据库提示缺少Data:dumper模块解决方法

本帖最后由 6543 于 2017-1-16 09:06 编辑

初始化mysql数据库时出现下面错误,原因是缺少Data:dumper模块

1
2
3
# ./scripts/mysql_install_db --user=mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper




解决方法 :安装autoconf库
命令:yum -y install autoconf   //此包安装时会安装Data:Dumper模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# yum -y install autoconf
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 autoconf.noarch.0.2.69-11.el7 将被 安装
--> 正在处理依赖关系 m4 >= 1.4.14,它被软件包 autoconf-2.69-11.el7.noarch 需要
--> 正在处理依赖关系 perl(Data::Dumper),它被软件包 autoconf-2.69-11.el7.noarch 需要
--> 正在检查事务
---> 软件包 m4.x86_64.0.1.4.16-10.el7 将被 安装
---> 软件包 perl-Data-Dumper.x86_64.0.2.145-3.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================================================================
Package                           架构                      版本                               源                     大小
================================================================================================================================
正在安装:
autoconf                            noarch                  2.69-11.el7                        base                  701 k
为依赖而安装:
m4                                  x86_64                  1.4.16-10.el7                      base                  256 k
perl-Data-Dumper                  x86_64                  2.145-3.el7                        base                     47 k

事务概要
================================================================================================================================
安装1 软件包 (+2 依赖软件包)

总下载量:1.0 M
安装大小:2.8 M
Downloading packages:
(1/3): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                         |47 kB00:00:00   
(2/3): autoconf-2.69-11.el7.noarch.rpm                                                                   | 701 kB00:00:00   
(3/3): m4-1.4.16-10.el7.x86_64.rpm                                                                     | 256 kB00:00:02   
--------------------------------------------------------------------------------------------------------------------------------
总计                                                                                          455 kB/s | 1.0 MB00:00:02   
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装    : m4-1.4.16-10.el7.x86_64                                                                                     1/3
正在安装    : perl-Data-Dumper-2.145-3.el7.x86_64                                                                         2/3
正在安装    : autoconf-2.69-11.el7.noarch                                                                                 3/3
验证中      : perl-Data-Dumper-2.145-3.el7.x86_64                                                                         1/3
验证中      : m4-1.4.16-10.el7.x86_64                                                                                     2/3
验证中      : autoconf-2.69-11.el7.noarch                                                                                 3/3

已安装:
autoconf.noarch 0:2.69-11.el7                                                                                                

作为依赖被安装:
m4.x86_64 0:1.4.16-10.el7                              perl-Data-Dumper.x86_64 0:2.145-3.el7                              

完毕!





安装完autoconf库,再运行./scripts/mysql_install_db --user=mysql,问题消失!!!

------------------------------------------------------------

下面再备上源码安装autoconf
下载地址:http://ftp.gnu.org/gnu/autoconf/
我这里选择的是2.69版本下载http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# tar -zxvf autoconf-2.69.tar.gz
# cd autoconf-2.69
# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
configure: autobuild project... GNU Autoconf
configure: autobuild revision... 2.69
configure: autobuild hostname... bogon
configure: autobuild timestamp... 20170115T063135Z
checking whether /bin/sh -n is known to work... yes
checking for characters that cannot appear in file names... none
checking whether directories can have trailing spaces... yes
checking for expr... /usr/bin/expr
checking for GNU M4 that supports accurate traces... configure: error: no acceptable m4 could be found in $PATH.
GNU M4 1.4.6 or later is required; 1.4.16 or newer is recommended.
GNU M4 1.4.15 uses a buggy replacement strstr on some systems.
Glibc 2.9 - 2.12 and GNU M4 1.4.11 - 1.4.15 have another strstr bug.




执行./configure时出现下面错误:
checking for GNU M4 that supports accurate traces... configure: error: no acceptable m4 could be found in $PATH.
GNU M4 1.4.6 or later is required; 1.4.16 or newer is recommended.
原因是需要安装M4

打开m4下载地址:
http://ftp.gnu.org/gnu/m4/
我这里下载的是最新版本http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz

1
2
3
4
5
# tar -zxvf m4-1.4.18.tar.gz
# cd m4-1.4.18
# ./configure
# make
# make install




m4安装完成之后再次执行再次切换到autoconf目录继续安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# cd autoconf-2.69
# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
configure: autobuild project... GNU Autoconf
configure: autobuild revision... 2.69
configure: autobuild hostname... bogon
configure: autobuild timestamp... 20170115T064711Z
checking whether /bin/sh -n is known to work... yes
checking for characters that cannot appear in file names... none
checking whether directories can have trailing spaces... yes
checking for expr... /usr/bin/expr
checking for GNU M4 that supports accurate traces... /usr/local/bin/m4
checking whether /usr/local/bin/m4 accepts --gnu... yes
checking how m4 supports trace files... --debugfile
checking for perl... no
configure: error: perl is not found




发现了新的错误:

checking for perl... no
configure: error: perl is not found
是因为没有安装perl
可以快速yum安装,也可以向下看源码安装

1
# yum -y install perl perl-devel




下载地址:https://www.perl.org/get.html
源码包地址:http://www.cpan.org/src/5.0/perl-5.24.0.tar.gz

1
2
3
4
5
# tar -zxvf perl-5.24.0.tar.gz
# cd perl-5.24.0
# ./Configure
# make
# make install




perl安装完成之后再次执行再次切换到autoconf目录继续安装

1
2
3
4
# cd autoconf-2.69
# ./configure
# make
# make install




至此autoconf通过源码方式安装完成
1. 实验环境:
1.1. mysql-proxy 调度器:
    Centos6.6ip:192.168.38.151   
1.2. mysql 主服务器master:
    Centos6.6ip:192.168.38.152
1.3. mysql 从服务器slave:
    Centos6.6ip:192.168.38.153
2.搭建mysql主从复制的环境
使用的mysql版本:mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
2.1. Master上安装mysql数据库:
2.1. 1. 下载到 /usr/local/src 目录。
2.1. 2. 解压缩
tarzxvf    mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
2.1. 3. 移动并且从命名安装包
mv mysql-5.1.40-linux-i686-icc-glibc23   /usr/local/mysql
2.1. 4. 开始安装mysql,但是需要在安装之前,创建一个用户以及创建一个“datadir”即数据库路径。
useradd-s/sbin/nologin-Mmysql
mkdir -p/data/mysql
chown -R mysql/data/mysql
安装mysql的文件在 ./scripts/
具体: ./scripts/mysql_install_db--user=mysql--datadir=/data/mysql
这一步安装完成后,可以用echo$? 查看是否已经安装成功。
2.1. 5. 现在,将 support-files/my-large.cnf覆盖到/etc/my.cnf文件。
cp support-files/my-large.cnf/etc/my.cnf    将其覆盖。


2.1. 6. 添加mysql开机启动,即需要将 mysql.server 添加到/etc/init.d/目录下。
具体命令就是:cpmysql.server/etc/init.d/mysqld   
然后,还需要将/etc/init.d/mysqld 文件里的参数进行配置。
vim /etc/init.d/mysqld
主要就是配置 以下这两个参数:
basedir=/usr/local/mysql
datadir=/data/mysql
2.1. 7. 接着,用chkconfig --add mysqld添加服务。
    用 chkconfig mysqld on开启服务
2.1. 8./etc/init.d/mysqld start启动了
2.1. 9. 最后,我们用 psaux | grep 'mysqld'
    以及   netstat-lnp | grep 'mysqld'
    两条命令都可以查看mysqld 是否已经在某个端口监听运行了。
2.2 在slave上安装mysql数据库,方法和master上的一样。
2.3 配置主从上的mysql配置文件
主端:
vim   /etc/my.cnf   增加:
log-bin=mysql-bin         #这个选项是为了打开主的二进制日志记录
binlog_format=mixed
server-id= 1         #整数,和从的区分
binlog-ignore-db = mysql    #这个选项是不同步的数据库,因为是实验,就不同步mysql库了

从端:
vim   /etc/my.cnf修改:
server-id=2       #和主的不相同
2.4 主备需要同步的数据库
在开始做主从复制的环境的时候,这一步是不能省略的。
首先在主上: mysql-e "createdatabase   db1";
然后,mysqldump -S /tmp/mysql.sock mysql > 123.sql
      mysql -S /tmp/mysql.sock db1 < 123.sql    拷贝回去。
这时的db1数据库和mysql数据库就是一样的了。我们现在用db1做实验。

然后,将123.sql 拷贝到从机上,用 scp   123.sql    root@192.168.38.153:/tmp/
然后在从机上操作:
mysql   -e   "createdatabase   db1;"   #就是创建一个空的db1数据库
mysql   -S   /tmp/mysql.sock   db1   </tmp/123.sql   #恢复备份,现在主从的db1都是相同的数据
2.5在主从上进行用户授权:
主,登陆数据库:
mysql> grant   replication slave   on *.*to   'repl'@'192.168.38.%'identifiedby '123456';
#这步给repl用户授权,它可以连接到master这里,下载二进制日志,然后同步数据库。
mysql>flushprivileges;
mysql>flush   tableswithread lock;
mysql>showmaster   status;
大概的样子:记录下File的名字,和Position的值,


从机,登陆mysql:
mysql>slave   stop;    #将slave 暂停
mysql>
change master to master_host='192.168.38.152', master_port=3306, master_user='repl', master_password='123456', master_log_file='mysql-bin.000039', master_log_pos=840;
#这里的意思,就是设定主服务器的ip端口,登陆的用户,权限,已经二进制日志的名字,同步的位置现在是840.
然后,
mysql>slave   start;
然后 slave start; 然后,show slave status\G;



需要看到两个Yes 才代表成功。

记得刚刚修改了从机的server-id后,要重启一下数据库生效。
在“主”
由于之前都是mysql> flush tables with read lock;
所以,现在要unlock一下:unlock tables;
2.6主从测试
在“主”操作一下:
例如,
use   db1;
show tables;
然后,我们把help_category删掉

然后,在从上,看看,发现这个表也不存在了。测试主从复制成功。


3.部署mysql-proxy服务

现在开始在192.168.38.151这台机器上安装mysql-proxy。


3.1.1   安装依赖的东西
由于mysql-proxy需要的依赖包比较多,在开始前先用yum将下面的包都安装一下:
gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* flex* pkgconfig*libevent*glib*
3.1.2编译安装lua
mysql-proxy的读写分离主要是通过rw-splitting.lua脚本实现的,因此需要安装lua。
这里采用源码包进行安装,需要自行下载lua的源码包,实验的时候,放在/usr/local/src 目录,,下载地址:http://www.lua.org/ftp/选择一个版本进行下载。
cd /usr/local/srctar zvfx lua-5.1.4.tar.gzcd lua-5.1.4visrc/Makefile在 CFLAGS= -O2 -Wall $(MYCFLAGS) 这一行记录里加上-fPIC,更改为 CFLAGS= -O2 -Wall -fPIC $(MYCFLAGS) 来避免编译过程中出现错误。
make linux出现系列错误提示解决办法make linux在包含自 lua.h:16 的文件中,从 lua.c:15:luaconf.h:275:31: 错误:readline/readline.h:没有那个文件或目录luaconf.h:276:30: 错误:readline/history.h:没有那个文件或目录lua.c: In function ‘pushline’:lua.c:182: 警告:隐式声明函数 ‘readline’lua.c:182: 警告:赋值时将整数赋给指针,未作类型转换lua.c: In function ‘loadline’:lua.c:210: 警告:隐式声明函数 ‘add_history’make: *** 错误 1make: Leaving directory `/data0/software/lua-5.1.4/src’make: *** 错误 2make: Leaving directory `/data0/software/lua-5.1.4/src’make: *** 错误 2
解决方法: yum install libtermcap-devel ncurses-devel libevent-devel readline-devel重新make linux make install
cp etc/lua.pc /usr/lib/pkgconfig/export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig


3.2 下载mysql-proxy下载:http://dev.mysql.com/downloads/mysql-proxy/ 一定要下载对应的版本,由于实验用的系统是centos6.632位,所以就选择了以下的安装包:tar zxvf mysql-proxy-0.8.5-linux-glibc2.3-x86-32bit.tar.gzmv mysql-proxy-0.8.5-linux-glibc2.3-x86-32bit /usr/local/mysql-proxy3.3 配置mysql-proxy,创建主配置文件

cd /usr/local/mysql-proxymkdir lua #创建脚本存放目录mkdir logs #创建日志目录cp share/doc/mysql-proxy/rw-splitting.lua./lua #复制读写分离配置文件vi /etc/mysql-proxy.cnf   #创建配置文件user=root #运行mysql-proxy用户admin-username=proxyuser #主从mysql共有的用户admin-password=123456 #用户的密码proxy-address=192.168.38.151:4040 #mysql-proxy运行ip和端口,不加端口,默认4040proxy-read-only-backend-addresses=192.168.38.153 #指定后端从slave读取数据proxy-backend-addresses=192.168.38.152 #指定后端主master写入数据proxy-lua-script=/usr/local/mysql-proxy/lua/rw-splitting.lua #指定读写分离配置文件位置admin-lua-script=/usr/local/mysql-proxy/lua/admin.lua #指定管理脚本log-file=/usr/local/mysql-proxy/logs/mysql-proxy.log #日志位置log-level=info #定义log日志级别,由高到低分别有(error|warning|info|message|debug)daemon=true    #以守护进程方式运行keepalive=true #mysql-proxy崩溃时,尝试重启admin-address=192.168.38.151:4041

plugins=admin,proxy#保存退出!chmod 660 /etc/mysql-porxy.cnf
3.4配置admin.lua 文件
在/etc/mysql-proxy.cnf 配置文件中,还差/usr/local/mysql-proxy/lua/admin.lua的管理文件没有创建。
mysql-proxy-0.8.5的这个版本,我找到了下面的lua脚本,才是有效的:

vim/usr/local/mysql-proxy/lua/admin.lua
function set_error(errmsg)
      proxy.response = {
                type = proxy.MYSQLD_PACKET_ERR,
                errmsg = errmsg or "error"
      }
end
function read_query(packet)
      if packet:byte() ~= proxy.COM_QUERY then
                set_error(" we only handle text-based queries (COM_QUERY)")
                return proxy.PROXY_SEND_RESULT
      end
      local query = packet:sub(2)
      local rows = { }
      local fields = { }
      if query:lower() == "select * from backends" then
                fields = {
                        { name = "backend_ndx",
                        type = proxy.MYSQL_TYPE_LONG },
                        { name = "address",
                        type = proxy.MYSQL_TYPE_STRING },
                        { name = "state",
                        type = proxy.MYSQL_TYPE_STRING },
{ name = "type",
                        type = proxy.MYSQL_TYPE_STRING },
                        { name = "uuid",
                        type = proxy.MYSQL_TYPE_STRING },
                        { name = "connected_clients",
                        type = proxy.MYSQL_TYPE_LONG },
                }
                for i = 1, #proxy.global.backends do
                        local states = {
                              "unknown",
                              "up",
                              "down"
                        }
                        local types = {
                              "unknown",
                              "rw",
                              "ro"
                        }
                        local b = proxy.global.backends
                        rows[#rows + 1] = {
                              i,
                              b.dst.name,          -- configured backend address
                              states, -- the C-id is pushed down starting at 0
                              types,   -- the C-id is pushed down starting at 0
                              b.uuid,            -- the MySQL Server's UUID if it is managed
                              b.connected_clients-- currently connected clients
                        }
                end
      elseif query:lower() == "select * from help" then
                fields = {
                        { name = "command",
                        type = proxy.MYSQL_TYPE_STRING },
                        { name = "description",
                        type = proxy.MYSQL_TYPE_STRING },
                }
                rows[#rows + 1] = { "SELECT * FROM help", "shows this help" }
                rows[#rows + 1] = { "SELECT * FROM backends", "lists the backends and their state" }
      else
                set_error("use 'SELECT * FROM help' to see the supported commands")
                return proxy.PROXY_SEND_RESULT
      end
      proxy.response = {
                type = proxy.MYSQLD_PACKET_OK,
                resultset = {
                        fields = fields,
                        rows = rows
                }
      }
      return proxy.PROXY_SEND_RESULT
end



3.5 修改读写分离配置文件
vim /usr/local/mysql-proxy/lua/rw-splitting.luaif not proxy.global.config.rwsplit then proxy.global.config.rwsplit = {min_idle_connections = 1, #默认超过4个连接数时,才开始读写分离,改为1max_idle_connections = 1, #默认8,改为1is_debug = false }end

4、启动mysql-proxy/usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/etc/mysql-proxy.cnfnetstat -tupln | grep 4000 #已经启动killall -9 mysql-proxy #关闭mysql-proxy使用

5. 测试读写分离
首先在从的mysql上停了slavestop;
然后,再测试,否则因为主从备份了,看不出效果。
或者,不停掉slave,可以在主从的/etc/my.cnf配置文件中,增加日志:
log = /data/mysql/mysql.log 的配置。
然后,在重启主从mysql服务器。然后,在主从分别输入:tail-F   /data/mysql/mysql.log
观察数据库的日志记录。
启动mysql-proxy 后,
登陆mysql-proxy:
mysql-uproxyuser-p123456-h192.168.38.151   -P4040
然后,use   db1;
然后,
mysql> create table user_proxy (number INT(10),name VARCHAR(255));
mysql> insert into user_proxy values(01,'zhangsan');
mysql> insert into user_proxy values(02,'lisi');
mysql>select   *from   user_proxy;



然后,查看主从的日志,发现只有在192.168.38.153这台从服务器上有select的记录,其他写入的记录在主服务器上有,
但是由于主从还有一个复制的功能,所以,在从服务器上也有写入的记录。

到这里,基本上实验读写分离也是成功了。



页: [1]
查看完整版本: 初始化mysql数据库提示缺少Data:dumper模块解决方法