緊接手工部署Keepalived的文章http://www.linuxidc.com/Linux/2012-09/70889.htm,這次來自動部署。
建立keepalived目錄,裡面已經存放了下載並解壓的keepalived-1.2.7目錄,包括和用於作為系統服務的keepalived腳本
注意,是前面一文修改過後能用於Ubuntu的版本。
install.sh腳本內容:
- #!/bin/bash
-
- source ../common/tool.sh
-
- libssl="libssl-dev"
- openssl="openssl"
- popt="libpopt-dev"
- daemonService="daemon"
-
- installDpkg $libssl
- installDpkg $openssl
- installDpkg $popt
- installDpkg $daemonService
-
- cd keepalived-1.2.7
- ./configure --prefix=/usr
- make
- make install
-
- cd ..
-
- cp ./keepalived /etc/init.d/
- cd /etc/init.d/
-
- update-rc.d keepalived start 21 2 3 4 5 . stop 21 0 1 6 .
- #update-rc.d keepalived default
-
- createFolder "/var/lock/subsys"
- cd -
- make clean
-
- service keepalived start
裡面使用了一個新的函數installDpkg,定義在tool.sh腳本中:
- #$1 dpkg name
- function installDpkg {
- hasDpkg $1
- r=$?
-
- if [ $r -eq 1 ]
- then
- echo "$1 was installed"
- else
- echo "$1 was not installed, installing..."
- apt-get install $1
- fi
- }
keepalived的目錄結構如下:
- keepalived# tree -L 2
- .
- ├── install.sh
- ├── install.sh~
- ├── keepalived
- ├── keepalived~
- └── keepalived-1.2.7
- ├── AUTHOR
- ├── bin
- ├── ChangeLog
- ├── config.log
- ├── config.status
- ├── configure
- ├── configure.in
- ├── CONTRIBUTORS
- ├── COPYING
- ├── doc
- ├── genhash
- ├── INSTALL
- ├── install-sh
- ├── keepalived
- ├── keepalived.spec
- ├── keepalived.spec.in
- ├── lib
- ├── Makefile
- ├── Makefile.in
- ├── README
- ├── TODO
- └── VERSION
-
- 6 directories, 21 files