Ad Widget

Collapse

Running multiple zabbix proxies on the same host

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jakk
    Junior Member
    • Aug 2022
    • 5

    #1

    Running multiple zabbix proxies on the same host

    Hello,

    I'm trying to run two proxies on the same host. I usually have them running each one on its own host, but if a host fails, I'd like the proxy to keep running on the other host .
    Each proxy listens only on its IP address (virtual ips are managed with pacemaker).
    I created two zabbix proxy configs and an instantiable systemd unit file, but when I start the second one, it fails with the error log:
    cannot initialize runtime control service: "rtc" service is already running.
    Am I missing something here?

    I'm running zabbix 6.0 on Rocky 9 using the packages from the zabbix official repo: zabbix-proxy-mysql-6.0.7-1.el9.x86_64

    /etc/zabbix/zabbix_proxy-1.conf
    Code:
    Server=10.0.0.10
    Hostname=Zabbix Proxy 1
    SourceIP=10.0.0.11
    ListenIP=10.0.0.11
    DBHost=localhost
    DBName=zproxy1
    DBUser=zproxy1
    DBPassword=zproxy1
    LogFile=/var/log/zabbix/zabbix_proxy-1.log
    PidFile=/run/zabbix/zabbix_proxy-1.pid
    /etc/zabbix/zabbix_proxy-2.conf
    Code:
    Server=10.0.0.10
    Hostname=Zabbix Proxy 2
    SourceIP=10.0.0.12
    ListenIP=10.0.0.12
    DBHost=localhost
    DBName=zproxy2
    DBUser=zproxy2
    DBPassword=zproxy2
    LogFile=/var/log/zabbix/zabbix_proxy-2.log
    PidFile=/run/zabbix/zabbix_proxy-2.pid
    /usr/lib/systemd/system/[email protected]
    Code:
    [Unit]
    Description=Zabbix Proxy %i
    After=syslog.target
    After=network.target
    After=mysql.service
    After=mysqld.service
    After=mariadb.service
    
    [Service]
    Environment="CONFFILE=/etc/zabbix/zabbix_proxy-%i.conf"
    EnvironmentFile=-/etc/sysconfig/zabbix-proxy
    Type=forking
    Restart=on-failure
    PIDFile=/run/zabbix/zabbix_proxy-%i.pid
    KillMode=control-group
    ExecStart=/usr/sbin/zabbix_proxy -c $CONFFILE
    ExecStop=/bin/kill -SIGTERM $MAINPID
    RestartSec=10s
    TimeoutSec=0
    
    [Install]
    WantedBy=multi-user.target
  • jakk
    Junior Member
    • Aug 2022
    • 5

    #2
    Found it.

    You also need to have a different SocketDir for each proxy.

    So, the config files go like this:

    /etc/zabbix/zabbix_proxy-1.conf
    Code:
    Server=10.0.0.10
    Hostname=Zabbix Proxy 1
    SourceIP=10.0.0.11
    ListenIP=10.0.0.11
    DBHost=localhost
    DBName=zproxy1
    DBUser=zproxy1
    DBPassword=zproxy1
    LogFile=/var/log/zabbix/zabbix_proxy-1.log
    PidFile=/run/zabbix_proxy-1/zabbix_proxy.pid
    SocketDir=/run/zabbix_proxy-1
    /etc/zabbix/zabbix_proxy-2.conf
    Code:
    Server=10.0.0.10
    Hostname=Zabbix Proxy 2
    SourceIP=10.0.0.12
    ListenIP=10.0.0.12
    DBHost=localhost
    DBName=zproxy2
    DBUser=zproxy2
    DBPassword=zproxy2
    LogFile=/var/log/zabbix/zabbix_proxy-2.log
    PidFile=/run/zabbix_proxy-2/zabbix_proxy.pid
    SocketDir=/run/zabbix_proxy-2
    /usr/lib/systemd/system/[email protected]
    Code:
    [Unit]
    Description=Zabbix Proxy %i
    After=syslog.target
    After=network.target
    After=mysql.service
    After=mysqld.service
    After=mariadb.service
    
    [Service]
    Environment="CONFFILE=/etc/zabbix/zabbix_proxy-%i.conf"
    EnvironmentFile=-/etc/sysconfig/zabbix-proxy
    Type=forking
    Restart=on-failure
    PIDFile=/run/zabbix_proxy-%i/zabbix_proxy.pid
    KillMode=control-group
    ExecStart=/usr/sbin/zabbix_proxy -c $CONFFILE
    ExecStop=/bin/kill -SIGTERM $MAINPID
    RestartSec=10s
    TimeoutSec=0
    
    [Install]
    WantedBy=multi-user.target
    /usr/lib/tmpfiles.d/zabbix-proxies.conf
    Code:
    d /run/zabbix_proxy-1 0755 zabbix zabbix - -
    d /run/zabbix_proxy-2 0755 zabbix zabbix - -

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #3
      I guess that sockerDir is needed for DB... I have similar setup 8 nodes for 6 proxies... as I am using sqlite, then I have no mention of socketdir anywhere...
      EDIT couple of days later... : geesh, it must have been heat or something.. I completely misinterpreted everything..:P Just forget this comment..:P
      Last edited by cyber; 22-08-2022, 08:28.

      Comment

      • jakk
        Junior Member
        • Aug 2022
        • 5

        #4
        You're probably thinking about DBSocket. SocketDir is used for IPC, it contains zabbix_proxy_availability.sock, zabbix_proxy_preprocessing.sock and zabbix_proxy_rtc.sock

        I figured this problem out when I was trying to find other ways to isolate the proxy processes, so I tried running each proxy under its own user and when I ran the second proxy it complained about /run/zabbix/zabbix_proxy_rtc.sock had a different user/group

        Comment

        • markfree
          Senior Member
          • Apr 2019
          • 868

          #5
          Originally posted by jakk
          You also need to have a different SocketDir for each proxy.
          Do you really need different SocketDir's or just different PIDFiles?

          Comment

          • jakk
            Junior Member
            • Aug 2022
            • 5

            #6
            Originally posted by markfree
            Do you really need different SocketDir's or just different PIDFiles?
            Hi,

            You need different PIDFiles AND different SocketDirs

            Comment

            • markfree
              Senior Member
              • Apr 2019
              • 868

              #7
              Originally posted by jakk
              You need different PIDFiles AND different SocketDirs
              I mean... If you were to set your proxy PID files with the same socketdir and different PID names, something like this:

              /etc/zabbix/zabbix_proxy-1.conf
              Code:
              PidFile=/run/zabbix_proxy/zabbix_proxy-1.pid
              SocketDir=/run/zabbix_proxy
              and
              /etc/zabbix/zabbix_proxy-2.conf
              Code:
              PidFile=/run/zabbix_proxy/zabbix_proxy-2.pid
              SocketDir=/run/zabbix_proxy
              Would that work out?
              Did you test it like that?

              Comment

              • pepek
                Junior Member
                • Nov 2022
                • 9

                #8
                hello all,

                I have one question to this topic.
                it's possible to run 2 proxy with different version on one host ? i'm planing to transfer old zabbix 4.2 enviroment with loot of mess and unwonted thinks to new zabbix 6
                During this process i would like to migrate proxys with hosts step by step and for safety run monitor enviroment on both zabbix server for some time simultaneously.

                thank you for answer os suggestion.

                Comment

                • Lone Wolf
                  Member
                  • Mar 2010
                  • 34

                  #9
                  Hello everyone!
                  I suppose nobody is expecting an answer anymore, but I will leave it here for anyone who might be wondering, and for my own reference.
                  So, recently I was faced with the same task: I needed to run 2 proxy instances of different versions on the same host and do the migration. I decided to manually install and run the second (temporary) copy so as not to confuse the system package manager. The easiest way is to use the sqlite version of the proxy: it means less trouble with database maintenance and we can be sure that the new installation won't interfere with the main proxy database. The internet says that using sqlite is fine if a proxy processes up to 1000 values per second. If your proxy is under heavy load, you may need to use a more powerful database engine. I don't think this is a problem; just follow the official proxy installation instructions for the database configuration, but use a different database name or database engine from the one used by the main proxy process. I will stick with sqlite for now.
                  First, we need to download a package containing proxy files. My proxy runs at Ubuntu, so I'll be looking for the packages at https://repo.zabbix.com/zabbix/6.4/u...main/z/zabbix/
                  As of now, the latest package corresponding to my server version is zabbix-proxy-sqlite3_6.4.6-1+ubuntu20.04_amd64.deb. I downloaded and unpacked it manually (ar x zabbix-proxy-sqlite3_6.4.6-1+ubuntu20.04_amd64.deb && tar -xvf data.tar). We need just 3 files: zabbix_proxy.conf, zabbix-proxy.service, and zabbix_proxy itself.
                  Prepare a location for the temporary proxy:
                  Code:
                  mkdir -p /opt/zbxproxy/bin /opt/zbxproxy/etc /opt/zbxproxy/run /opt/zbxproxy/db /opt/zbxproxy/log
                  cd /opt/zbxproxy
                  chown zabbix:zabbix db run log
                  Move zabbix_proxy to /opt/zbxproxy/bin, and zabbix_proxy.conf to /opt/zbxproxy/etc.
                  Edit zabbix_proxy.conf:
                  Code:
                  ListenPort=10151
                  #It has to be different from main proxy; you may also have to reconfigure Agents and Senders for the duration of the migration, if they are used
                  
                  LogFile=/opt/zbxproxy/log/zabbix_proxy.log
                  LogFileSize=10
                  PidFile=/opt/zbxproxy/run/zabbix_proxy.pid
                  SocketDir=/opt/zbxproxy/run
                  DBName=/opt/zbxproxy/db/zabbix_proxy
                  #And other options as needed
                  Edit zabbix-proxy.service:
                  Code:
                  [Unit]
                  Description=Zabbix Temporary Proxy
                  After=syslog.target
                  After=network.target
                  
                  [Service]
                  Environment="CONFFILE=/opt/zbxproxy/etc/zabbix_proxy.conf"
                  EnvironmentFile=-/etc/default/zabbix-proxy
                  Type=forking
                  Restart=on-failure
                  PIDFile=/opt/zbxproxy/run/zabbix_proxy.pid
                  KillMode=control-group
                  ExecStart=/opt/zbxproxy/bin/zabbix_proxy -c $CONFFILE
                  ExecStop=/bin/sh -c '[ -n "$1" ] && kill -s TERM "$1"' -- "$MAINPID"
                  RestartSec=10s
                  TimeoutSec=1m
                  User=zabbix
                  Group=zabbix
                  
                  [Install]
                  WantedBy=multi-user.target
                  Move/rename this file to /lib/systemd/system/zabbix-proxy-temp.service.
                  At this point, the second proxy should be operational. Add this proxy at the server, run it and watch the log:
                  Code:
                  systemctl daemon-reload
                  systemctl enable zabbix-proxy-temp.service
                  systemctl start zabbix-proxy-temp.service
                  tail -F /opt/zbxproxy/log/zabbix_proxy.log
                  Check the availability of the new proxy using the server logs and interface. If everything works fine, you can start the migration process. When it is finished, upgrade/reinstall the "main" proxy using the system package manager, configure it (using the same Hostname as the temporary proxy does, but with the "proper" other options like ListenPort, LogFile, etc.), stop the temporary proxy and run the main one. When you're sure that you won't be needing the temporary proxy anymore, just delete the /opt/zbxproxy directory and the zabbix-proxy-temp.service file. That's it!
                  BTW, I wrote this from memory, so I may have missed or got some details wrong. But I hope you get the idea.​

                  Comment

                  Working...