2

I have installed the keepalived latest Version 1.2.16 using

tar -xzvf keepalive.tar.gz

and

./configure

after installation I can not run it from terminal

sudo service keepalived start 

or any other command it give me this

keepalived: unrecognized service

or incase of keepalived

The program 'keepalived' is currently not installed. You can install it by typing:sudo apt-get install keepalived

how do I make it available system wide?

Thanks,

12
  • 1
    ./configure does not make a binary. Did you run make after you ran configure? May 13, 2015 at 7:52
  • i used it after you said it but still its doing the same thing
    – Waqas
    May 13, 2015 at 7:56
  • Please provide more information about what is not working. After you run make && make install the binary usually goes into /usr/local/bin/keepalived Is this the case? Update your answer and add some more details of what's failing. May 13, 2015 at 7:58
  • @val0x00ff there is nothing in /usr/local/bin/keepalived and i thought I have installed the keepalived using the ./configure but it doesnt work
    – Waqas
    May 13, 2015 at 8:05
  • 1
    @Waqas how are you running keepalived? Does keepalived --help tell you something? May 13, 2015 at 8:15

2 Answers 2

3

Download the keepalived version you like

tar -xzvf keepalived.gz.tar 
cd keepalived
sudo make clean
./configure
make
sudo make install

Open a terminal and execute the following commands:

sudo nano /etc/init.d/keepalived

Now, copy and paste the contents of the following into the terminal:

#! /bin/sh
#
# keepalived   LVS cluster monitor daemon.
#
#              Written by Andres Salomon <[email protected]>
#
### BEGIN INIT INFO
# Provides:          keepalived
# Required-Start:    $syslog $network $remote_fs
# Required-Stop:     $syslog $network $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts keepalived
# Description:       Starts keepalived lvs loadbalancer
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
DAEMON=/usr/local/sbin/keepalived
NAME=keepalived
DESC=keepalived
TMPFILES="/tmp/.vrrp /tmp/.healthcheckers"

#includes lsb functions 
. /lib/lsb/init-functions

test -f $CONFIG || exit 0 
test -f $DAEMON || exit 0


# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

case "$1" in
  start)
        log_daemon_msg "Starting $DESC" "$NAME"
    for file in $TMPFILES
    do 
            test -e $file && test ! -L $file && rm $file
    done
    if start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
               --exec $DAEMON -- $DAEMON_ARGS; then
        log_end_msg 0
    else
        log_end_msg 1
    fi
       ;;
  stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    if start-stop-daemon --oknodo --stop --quiet --pidfile /var/run/$NAME.pid \
            --exec $DAEMON; then
        log_end_msg 0
    else
        log_end_msg 1
    fi
       ;;
  reload|force-reload)
    log_action_begin_msg "Reloading $DESC configuration..."
        if start-stop-daemon --stop --quiet --signal 1 --pidfile \
               /var/run/$NAME.pid --exec $DAEMON; then
           log_end_msg 0
    else
        log_action_end_msg 1
    fi
       ;;
  restart)
    log_action_begin_msg "Restarting $DESC" "$NAME"

        start-stop-daemon --stop --quiet --pidfile \
        /var/run/$NAME.pid --exec $DAEMON || true 
       sleep 1
       if start-stop-daemon --start --quiet --pidfile \
               /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_ARGS; then
           log_end_msg 0
    else
        log_end_msg 1
    fi
       ;;
  *)
       echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload|force-reload}" >&2
       exit 1
       ;;
esac

exit 0

Press CTRL + o to save the file and press CTRL + x to exit nano. Then, execute the following commands:

sudo chmod +x /etc/init.d/keepalived
sudo /etc/init.d/keepalived start
sudo update-rc.d keepalived defaults
8
  • I edited the script and changed /usr/sbin/keepalived to /usr/local/sbin/keepalived and included /usr/local/sbin and /usr/local/bin in the PATH
    – mchid
    May 13, 2015 at 10:16
  • and removed CONFIG=/etc/keepalived/keepalived.conf
    – mchid
    May 13, 2015 at 10:31
  • but still that doesnt work like if I install the keepalived using ubuntu repository sudo apt-get install keepalived when I sudo /etc/init.d/keepalived start it doesnt show me if it has started or not
    – Waqas
    May 13, 2015 at 10:33
  • @Waqas If you did run sudo apt-get install keepalived you can run sudo apt-get remove keepalived to get rid of it. The other version you build should remain installed.
    – mchid
    May 13, 2015 at 10:40
  • 1
    @Waqas It didn't show it had started for me also and so I edited the script posted and it works for me now. You should go ahead and run the commands again (sudo nano ...) and copy/paste what is posted now into that file and it should now output [ ok ] Starting keepalived: keepalived. when you start the service. Don't forget to update-rc.d!
    – mchid
    May 13, 2015 at 10:47
3

Read the manual!

The keepalived User Guide has had instructions for doing this since 2001. Follow them. The User Guide is considered out of date, but in fact only part 2 of the instructions are outdated. Part 1 (./configure && make && make install as the superuser) is still valid.

Part 2 is outdated because it addresses an old System 5 rc way of creating a keepalived dæmon service, and that for Fedora-style System 5 rc no less. You're using Ubuntu Linux. You've had upstart for years and you have systemd nowadays.

systemd

For systemd, write your own local service unit and place it (because it is a non-system non-packaged local-administrator unit) in /etc/systemd/system/keepalived.service. Here's one of mine, incorporating two bugfixes:

#
# keepalived control files for systemd
#
# Incorporates fixes from RedHat bug #769726.

[Unit]
Description=LVS and VRRP High Availability monitor
After=network.target
ConditionFileNotEmpty=/etc/keepalived/keepalived.conf

[Service]
Type=simple
# Ubuntu/Debian convention:
EnvironmentFile=-/etc/default/keepalived
ExecStart=/usr/sbin/keepalived --dont-fork
ExecReload=/bin/kill -s HUP $MAINPID
# keepalived needs to be in charge of killing its own children.
KillMode=process

[Install]
WantedBy=multi-user.target

You'll have to adjust this unit for the fact that you've installed into /usr/local rather than /usr. After that, the normal systemd controls apply:

  • systemctl preset keepalived.service to have the service automatically start at bootstrap.
  • systemctl start keepalived.service to start the service manually.
  • systemctl status keepalived.service to view the service status.

And so forth.

upstart

Your package hasn't come with an upstart job file. Having never had need of keepalived under upstart myself, this is just a skeleton /etc/init/keepalived.conf that you will have to work on.

description "LVS and VRRP High Availability monitor"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

exec /usr/sbin/keepalived --dont-fork

Further reading

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .