Skip to content

Commit

Permalink
1.1.1 -> 1.1.2 update + restore.sh, upgrade.sh scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
scline committed Apr 4, 2017
1 parent cd7b2f2 commit 98ee566
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 231 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Mac Files
.DS_Store

# Testing deployments
docker-compose.yml
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN \

yum install -y \
rrdtool net-snmp net-snmp-utils cronie php-ldap php-devel mysql php \
ntp bison php-cli php-mysql php-common php-mbstring php-snmp \
ntp bison php-cli php-mysql php-common php-mbstring php-snmp curl \
php-gd openssl openldap mod_ssl php-pear net-snmp-libs php-pdo && \

tar -xf /tmp/cacti-1*.tar.gz -C /tmp && \
Expand All @@ -29,7 +29,7 @@ RUN \
chmod +s /spine/bin/spine && \

## --- CLEANUP ---
yum remove -y gcc net-snmp-devel && \
# yum remove -y gcc net-snmp-devel && \
rm -rf /tmp/* && \
yum clean all

Expand All @@ -40,16 +40,25 @@ RUN chmod 0600 /var/spool/cron/*
COPY configs/spine.conf /spine/etc
COPY configs/cacti.conf /etc/httpd/conf.d
COPY configs/config.php /cacti/include
COPY configs /template_configs

## --- SETTINGS/EXTRAS ---
COPY plugins /cacti/plugins
COPY templates /templates
COPY settings /settings

## --- SCRIPTS ---
COPY upgrade.sh /upgrade.sh
RUN chmod +x /upgrade.sh

COPY restore.sh /restore.sh
RUN chmod +x /restore.sh

COPY backup.sh /backup.sh
RUN chmod +x /backup.sh

RUN mkdir /backup

## --- ENV ---
ENV \
DB_NAME=cacti \
Expand Down
256 changes: 37 additions & 219 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,238 +105,48 @@ The folks at Cacti.net recommend the following settings for its MySQL based data
Included is a backup script that will backup cacti (including settings/plugins), rrd files, and spine. This is accomplished by taking a complete copy of the root spine and cacti directory and performing a MySQL dump of the cacti database which stores all the settings and device information. To manually perform a backup, run the following exec commands:

```
docker exec -it <docker image ID or name> ./backup.sh
docker exec <docker image ID or name> ./backup.sh
```

This will store compressed backups in a tar.gz format within the cacti docker container under /backups directory. Its recommended to map this directory using volumes so data is persistent. By default it only stores 7 most recent backups and will automatically delete older ones, to change this value update `BACKUP_RETENTION` environmental variable with the number of backups you wish to store.

##### Automatic backups - !!!Not Working!!!
The environment variable `BACKUP_TIME` can be altered to have the container automatically backup cacti. The value is in days and will kick off at midnight by default. By default this is disabled with a value of 0, if you want to further customize backup times edit `configs/crontab.apache` in this repo and rebuild the docker image.


## Docker Cacti Architecture
-----------------------------------------------------------------------------
With the recent update to version 1+, Cacti has introduced the ability to have remote polling servers. This allows us to have one centrally located UI and information system while scaling out multiple datacenters or locations. Each instance, master or remote poller, requires its own MySQL based database. The pollers also have an addition requirement to access the Cacti master's database with read/write access.


### Single Instance - cacti_single_install.yml
This is likely the most common example to deploy a cacti instance. This is not using any external pollers and is self-contained on one server. There are two separate docker containers, one for the cacti service and another for the MySQL based database. The example docker-compose file will have cacti setup a new database during the initial installation. This takes about 5-10 minutes on first boot before the web UI would be available, after the initial setup the service is up within 15 seconds.

![Alt text](https://github.com/scline/docker-cacti/blob/master/document_images/single_host.png?raw=true "Single Host")

*docker-compose.yml*
### Restore Backup
To restore from an existing backup, run the following docker exec command with the backup file location as an argument.
```
version: '2'
services:
cacti:
image: "smcline06/cacti"
ports:
- "80:80"
- "443:443"
environment:
- DB_NAME=cacti_master
- DB_USER=cactiuser
- DB_PASS=cactipassword
- DB_HOST=db
- DB_PORT=3306
- DB_ROOT_PASS=rootpassword
- INITIALIZE_DB=1
- TZ=America/Los_Angeles
links:
- db
db:
image: "percona:5.7.14"
ports:
- "3306:3306"
command:
- mysqld
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --max_connections=200
- --max_heap_table_size=128M
- --max_allowed_packet=32M
- --tmp_table_size=128M
- --join_buffer_size=128M
- --innodb_buffer_pool_size=1G
- --innodb_doublewrite=OFF
- --innodb_flush_log_at_timeout=3
- --innodb_read_io_threads=32
- --innodb_write_io_threads=16
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- TZ=America/Los_Angeles
docker exec <docker image ID or name> ./restore.sh /backup/<filename>
```

### Single DB, Multi Node - cacti_multi_shared.yml
This instance would most likely be used if multiple servers are in close (same network/cluster) and uptime is not an issue. One or more remote pollers hang off a beefy master-cacti instance. All cacti databases need to be named differently for this to work, also note that due to how spine + boost work the database instance will utilize a bit of ram (~1-4GB per remote poller) and settings should be tweaked in this example to reflect this. This setup would be favorable if CPU becomes a bottleneck on one or many servers. Adding remote pollers can offset the load greatly. RDD files don't appear to be stored on remote systems.

![Alt text](https://github.com/scline/docker-cacti/blob/master/document_images/single_db.png?raw=true "Single DB, Multiple Hosts")

*docker-compose.yml (Server 01)*
To get a list of backups, the following command should display them:
```
version: '2'
services:
cacti-master:
image: "smcline06/cacti"
ports:
- "80:80"
- "443:443"
environment:
- DB_NAME=cacti_master
- DB_USER=cactiuser
- DB_PASS=cactipassword
- DB_HOST=db-master
- DB_PORT=3306
- DB_ROOT_PASS=rootpassword
- INITIALIZE_DB=1
- TZ=UTC
links:
- db
db:
image: "percona:5.7.14"
ports:
- "3306:3306"
command:
- mysqld
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --max_connections=200
- --max_heap_table_size=128M
- --max_allowed_packet=32M
- --tmp_table_size=128M
- --join_buffer_size=128M
- --innodb_buffer_pool_size=1G
- --innodb_doublewrite=OFF
- --innodb_flush_log_at_timeout=3
- --innodb_read_io_threads=32
- --innodb_write_io_threads=16
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- TZ=UTC
docker exec <docker image ID or name> ls /backup
```

*docker-compose.yml (Server 02)*
### Updating Cacti
You can now update the Cacti/Spine version of this container using the included script. By default this will update to the *latest* version.
```
cacti-poller:
image: "smcline06/cacti"
ports:
- "8080:80"
- "8443:443"
environment:
- DB_NAME=cacti_poller
- DB_USER=cactiuser
- DB_PASS=cactipassword
- DB_HOST=10.1.2.3
- DB_PORT=3306
- RDB_NAME=cacti_master
- RDB_USER=cactiuser
- RDB_PASS=cactipassword
- RDB_HOST=10.1.2.3
- RDB_PORT=3306
- DB_ROOT_PASS=rootpassword
- REMOTE_POLLER=1
- INITIALIZE_DB=1
- TZ=UTC
docker exec <docker image ID or name> ./upgrade.sh
```

### Multi DB, Multi Node - cacti_multi.yml
Likely used for large deployments or where multiple locations/datacenters are at play. One master server for settings and a single window into all monitoring while pollers in remote locations gather information and feed it back home. The limiting factor will be latency or disk IO on the master database since pollers will write data directly to it when gathering SNMP/scripts. RDD files don't appear to be stored on remote systems.
If you want to specify a specific version please update the `/upgrade.sh` values.
* [Cacti Version Links][cacti_download]
* [Spine Version Links][spine_download]
```
#!/bin/bash
![Alt text](https://github.com/scline/docker-cacti/blob/master/document_images/multi_host.png?raw=true "Multiple Hosts and DB")
# script to upgrade a cacti instance to latest, if you want a specific version please update the following download links
cacti_download_url=http://www.cacti.net/downloads/cacti-latest.tar.gz
spine_download_url=http://www.cacti.net/downloads/spine/cacti-spine-latest.tar.gz
*docker-compose.yml (Server 01)*
```
version: '2'
services:
cacti-master:
image: "smcline06/cacti"
ports:
- "80:80"
- "443:443"
environment:
- DB_NAME=cacti_master
- DB_USER=cactiuser
- DB_PASS=cactipassword
- DB_HOST=db-master
- DB_PORT=3306
- DB_ROOT_PASS=rootpassword
- INITIALIZE_DB=1
- TZ=UTC
links:
- db-master
db-master:
image: "percona:5.7.14"
ports:
- "3306:3306"
command:
- mysqld
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --max_connections=200
- --max_heap_table_size=128M
- --max_allowed_packet=32M
- --tmp_table_size=128M
- --join_buffer_size=128M
- --innodb_buffer_pool_size=1G
- --innodb_doublewrite=OFF
- --innodb_flush_log_at_timeout=3
- --innodb_read_io_threads=32
- --innodb_write_io_threads=16
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- TZ=UTC
```
```

*docker-compose.yml (Server 02)*
```
cacti-poller:
image: "smcline06/cacti"
ports:
- "8080:80"
- "8443:443"
environment:
- DB_NAME=cacti_poller
- DB_USER=cactiuser
- DB_PASS=cactipassword
- DB_HOST=db-poller
- DB_PORT=3306
- RDB_NAME=cacti_master
- RDB_USER=cactiuser
- RDB_PASS=cactipassword
- RDB_HOST=10.1.2.3
- RDB_PORT=3306
- DB_ROOT_PASS=rootpassword
- REMOTE_POLLER=1
- INITIALIZE_DB=1
- TZ=UTC
links:
- db-poller
db-poller:
image: "percona:5.7.14"
command:
- mysqld
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --max_connections=200
- --max_heap_table_size=128M
- --max_allowed_packet=32M
- --tmp_table_size=128M
- --join_buffer_size=128M
- --innodb_buffer_pool_size=1G
- --innodb_doublewrite=OFF
- --innodb_flush_log_at_timeout=3
- --innodb_read_io_threads=32
- --innodb_write_io_threads=16
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- TZ=UTC
```
## Docker Cacti Architecture
-----------------------------------------------------------------------------
With the recent update to version 1+, Cacti has introduced the ability to have remote polling servers. This allows us to have one centrally located UI and information system while scaling out multiple datacenters or locations. Each instance, master or remote poller, requires its own MySQL based database. The pollers also have an addition requirement to access the Cacti master's database with read/write access.

Some docker-compose examples can be found in the following [readme][arch]

## Container Customization
There are a few customizations you can do if you are building the container locally. During the build process Plugins and Device Templates can be added to folders where at startup, scripts will import and install.
Expand Down Expand Up @@ -381,11 +191,17 @@ REPLACE INTO `%DB_NAME%`.`settings` (`name`, `value`) VALUES('poller_type', '2')
```

# Change Log
##### 1.1.1 - 03/27/2017
#### 1.1.2 - 04/02/2017
* Update Cacti and Spine from 1.1.1 to 1.1.2 - [changelog link][CL1.1.2]
* Restore from a cacti backup is now working via `restore.sh <backupfile>` command
* Minor cleanup of `backup.sh` script
* Upgrade cacti script created and tested using `upgrade.sh` script

#### 1.1.1 - 03/27/2017
* Update Cacti and Spine from 1.1.0 to 1.1.1 - [changelog link][CL1.1.1]
* GitHub ReadMe organization

##### 1.1.0 - 03/25/2017
#### 1.1.0 - 03/25/2017
* Initial push

# Known Issues/Fixes
Expand All @@ -394,13 +210,15 @@ REPLACE INTO `%DB_NAME%`.`settings` (`name`, `value`) VALUES('poller_type', '2')
* HTTPS is not setup to work, it may work just understand no testing has been done.

# ToDo
* Restore command + script to restore cacti from a backup.
* Cacti version upgrades w/o data loss, currently you will need to manually upgrade versions.
* Enable container SNMP for monitoring, import/create local container template for use.
* Auto import remote pollers, currently you need to navigate to there GUI for a few clicks.
* Documentation cleanup.

[CL1.1.2]: http://www.cacti.net/release_notes_1_1_2.php
[CL1.1.1]: http://www.cacti.net/release_notes_1_1_1.php
[docker_volume_help]: https://docs.docker.com/engine/tutorials/dockervolumes/
[cacti_forums]: http://forums.cacti.net/
[cws]: http://cacti.net/
[cacti_download]: http://www.cacti.net/downloads
[spine_download]: http://www.cacti.net/downloads/spine
[arch]: https://github.com/scline/docker-cacti/tree/master/docker-compose
[docker_volume_help]: https://docs.docker.com/engine/tutorials/dockervolumes
[cacti_forums]: http://forums.cacti.net
[cws]: http://cacti.net
Loading

0 comments on commit 98ee566

Please sign in to comment.