---
title: "笔记：使用源码安装Bacula 5.0.3"
author: "OpenNaive"
date: "2011-09-02T19:16:01Z"
tags: []
categories: ["开源软件"]
slug: "bacula-5-0-3"
draft: false
lastmod: "2011-09-09T17:19:45Z"
id: 1164614
url: "https://opennaive.iteye.com/blog/1164614"
---

![](/upload/picture/pic/98121/7ec9d08f-ba15-3704-946a-7ca890d55319.jpg)

Bacula是一个开源备份软件，用[官方网站](http://www.bacula.org/en/) 的话说是一个开源的网络备份解决方案。

官方网站 写道

Bacula is a set of Open Source, enterprise ready, computer programs that permit you (or the system administrator) to manage backup, recovery, and verification of computer data across a network of computers of different kinds. 

源码都是从官网[Current Files](http://www.bacula.org/en/?page=downloads) 下载的，除了要下载源码外，还要下载依赖包depkgs，depkgs包含了Bacula可能需要的第三方依赖包sqlite、mtx和qwt。另外[documentation](http://www.bacula.org/en/?page=documentation) 里面有几个非常详细的文档，main文档包括了安装和配置指南，我就是配合使用main文档和README的。如果之前安装过Bacula，或已配置、编译过Bacula，要先卸载和clean。

```
shell> make uninstall  
shell> make distclean  
```

这是从main文档和README整合出来的一段安装命令。

```
# To configure it  
shell> CFLAGS="-g -Wall" \  
        ./configure \  
        --sbindir=$HOME/bacula/bin \  
        --sysconfdir=$HOME/bacula/bin \  
        --with-pid-dir=$HOME/bacula/bin/working \  
        --with-subsys-dir=$HOME/bacula/bin/working \  
        --with-mysql=/usr/local/mysql \  
        --with-working-dir=$HOME/bacula/bin/working \  
        --with-dump-email=$USER  
# Build Bacula  
shell> make  
# To install  
shell> make install  
# To create the database  
shell> cd $HOME/bacula/bin  
shell> ./grant_mysql_privileges  
shell> ./create_mysql_database  
shell> ./make_mysql_tables   
# To start it  
shell> ./bacula start  
# To stop it  
shell> ./bacula stop
```

 

首先需要配置bacula，使用这种配置的好处是所有东西都会被安装在一个目录内，参数with-mysql必须是mysql的安装位置。如果这时需要修改配置，要make distclean再重新configure。然而在make的时候出错了，显然是缺少了某个库。

/usr/bin/ld: cannot find -lz

在main文档的Building Bacula from Source小节有详细的说明：

main文档 写道

"In addition, the MySQL client library mysqlclient requires the gzip compression library libz.a or libz.so. If you are using rpm packages, these libraries are in the libz-devel package. On Debian systems, you will need to load the zlib1g-dev package. If you are not using rpms or debs, you will need to find the appropriate package for your system.

 因为用的是ubuntu，只要用apt-get就好。

```
shell> sudo apt-get install zlib1g-dev  
```

 

 之后make一切正常，在make install的时候又出现了错误。

/usr/bin/install: cannot stat \`btraceback.gdb': No such file or directory

但是似乎这个错误并不重要，先忽略它。在创建数据库时，运行make\_mysql\_tables出现了以下错误。

ERROR 1064 (42000) at line 316: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MaxValue INTEGER DEFAULT 0,

CurrentValue INTEGER DEFAULT 0,

WrapCounter TI' at line 4

Creation of Bacula MySQL tables succeeded.

检查脚本，发现错误的地方是创建Counters表，检查数据库也证实Counters表没有创建成功。google了一下，发现有人遇到过同样的问题，问题的原因是MaxValue在mysql 5.5中是保留字，所以要将MaxValue用符号 \` 括起来。

```
CREATE TABLE Counters (  
    　　Counter TINYBLOB NOT NULL,  
   　　 MinValue INTEGER DEFAULT 0,  
    　　\`MaxValue\` INTEGER DEFAULT 0,  
   　　 CurrentValue INTEGER DEFAULT 0,  
   　　 WrapCounter TINYBLOB NOT NULL,  
  　　  PRIMARY KEY (Counter(128))  
    );  
```

 

修改后的脚本成功创建了所有表。当启动bacula时，又出现了以下错误。

/root/bacula

/bin/bacula-dir: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

出错的原因和解决方案在main文档的42.4 Linking Bacula with MySQL中有介绍，只需要在/etc/ld.so.conf文件的尾部添加libmysqlclient.so.18库的位置，再运行/sbin /ldconfig脚本即可。

现在再运行bacula start，就会显示：

Starting the Bacula Storage daemon

Starting the Bacula File daemon

Starting the Bacula Director daemon

bacula脚本接受四个参数start、stop、restart和status。

 

configure命令还有几个很有用的参数。

如果只想安装客户端，就使用--enable-client-only。

如果想安装或不安装Director，使用--enable-build-dird/--disable-build-dird。

如果想安装或不安装Storage，使用--enable-build-stored/--disable-build-stored。