scline / docker-cacti

Cacti version 1+ under Docker
113 stars 56 forks source link

Changind DB credentials fails #80

Open CampbellBruce opened 3 years ago

CampbellBruce commented 3 years ago

Can you explain the proper way to change our db credentials but keep the data already collected? I tested the default docker compose succesfuly,collected data and then after backing up with your script the data i deployed a new docker-compose file with different creds to a new VM and restored.It didnt start.

Then i copied the volumes and it starts correctly,thing is although the env vars are different i found its still using the default creds from your example and thats why its getting data.

The common error is Access denied for user 'cactiuser'@'172.21.0.3' (using password: YES)

Also i tried to change from inside the cacti docker manually the creds for the root and cactiuser users in the DB.I then noticed config.php kept the old creds so i changed it there too.Ofcourse im doing docker-compose down and up -d for my changes.

Still it keeps throwing the error and wont update the spine poller results. SPINE: Poller[Main Poller] PID[1286] FATAL: Connection Failed, Error:'1045', Message:'Access denied for user 'cactiuser'@'172.21.0.3' (using password: YES)' (Spine parent)

I made combinations with initialize_db values but no luck.

Im missing something here,maybe another file that needs changing?Could you please reproduce and present the correct order of actions we need to do to change the DB credentials but keep the data?

scline commented 3 years ago

I may have to attempt to replicate this when I get time. At the top of my head, I want to say those database env variables are only used when installing a new instance of cacti.

To change an existing password you would need to edit the cacti configuration file manually, take a look at cacti/include/config.php the credentials are stored and used there post-install.

It will look something like:

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cacti";
scline commented 3 years ago

If you can share your compose file (passwords and what not removed) I can also use that as a base to replicate :)

CampbellBruce commented 3 years ago

Here is the docker-compose file:

version: '3.5' services:

cacti: image: "smcline06/cacti" container_name: cacti restart: unless-stopped ports:

volumes: cacti-db: cacti-data: cacti-spine: cacti-backups:

cacti.env file:

DB_NAME=cacti_master DB_USER=cactiuser DB_PASS=my2ndpass DB_HOST=cacti_db DB_PORT=3306 DB_ROOT_PASS=my2ndpass INITIALIZE_DB=0 TZ=Europe/Athens

cacti_db.env file:

MYSQL_ROOT_PASSWORD=my2ndpass TZ=Europe/Athens

Although you can simply put them all in the compose file no need to split it.

If you run the compose file initially with my1stpass,then copy volumes or backup elsewhere and rerun with my2ndpass in the compose file i believe it will work but will have in fact keep the first pass.

thx for your efforts!

CampbellBruce commented 3 years ago

Also its impossible to keep the identation correct in the post, sorry about that.