Automate /var/log/mysql from filling up with logs?

So I logged into my website today and noticed that my storage space of 60GB was like 45% full. This seemed odd because I only have three websites only there and the biggest one is 2 or 3GB while the other two take up 1GB or less.

After doing some research, I noticed that the /var/log/mysql folder was filled with 100MB files that were eating up like 15GB of my storage. I continued doing research here and was lead to this thread

Which suggested I could just wipe out the whole folder because itā€™s just logs and unless Iā€™m troubleshooting something immediately, thereā€™s no need to have them stored for so long


So my question is, how can I automate this server so I donā€™t have to do this manually? It seems like it would be smart to keep some recent log files in the folder (Iā€™m okay with storing 1GB of logs, or a few hundred MB or whatever).

But unless I notice something wrong, I shouldnā€™t need any of the older log files in this folder. Is there a recommended way of keeping this folder in check with EasyEngine?

If not, what would be the best Linux style way of keeping this folder clean? Maybe setting up a cronjob to wipe it clean once a month? Or is there something built into MariaDB, like a setting or something, that prevents the logs folder from reaching a certain size?

I donā€™t know any EE special way.

Butā€¦ I am not an expert but you can try and setup a cron to clean up the folder every now and then.

If I were you I would worry about how the chunks got there. You should check if any of your websites got hacked: sitecheck.sucuri.net

Then you should be aware that it is possible for apps (WordPress or w/e) write enormous amounts of data. Even if you do something, such as deleting, cleaning, updating tables or w/e, everything will be in a log. And the logs will consume a lot of space. Idk how often these logs get cleaned up automatically or at all, but a cron should help.

Also, if you set a plugin to keep logs for 1 year, it will consume a big amount of database space. So try to set your plugins not to keep logs older that a month or w/e.

Try to check the dates when the logs got written and start from there.

These are all just suggestions, just trying to help. Cheers

1 Like

No, none of my sites got hacked, but I did notice that AMP for WP did just get taken down for a security flaw. Still, I use Wordfence and all sites on this server are safe.

I will be keeping an eye on that folder to see how quickly it grows and will setup a cronjob if there isnā€™t some sort of MariaDB option to limit the size of the logs it collects or something.

Thanks

[General note: Cron is already being used to trigger log rotation for log files (which is why you see files such as syslog, syslog.1, syslog.2.gz etc, which are also deleted beyond a certain age).]

Does it sound right that there would be a lot of database updating going on for this server (not reads, only stuff that changes data is logged)? If not, you might want to look into that.

Otherwise, it does sound like a good solution here is (as virtubox recommended in the link you posted), to disable binary logging for MySQL (explained here) if you donā€™t use db replication (which you probably donā€™t).

1 Like

I have three websites on this server. One website is tutorial blog that I use to write a single tutorial once a day on. A second website on the server hasnā€™t been updated in a year or two.

The other website though, is a Woocommerce external link website that I use to post application sales for Android. I schedule about 10-12 per day (some of these just get re-used as I keep expired sales in a category that people canā€™t see).

I canā€™t say how many new posts I put up on that one each day and how many get rescheduled, but it does currently have 6,943 ā€œproductsā€ setup in Woocommerce (again, as external links).

Iā€™m not sure what db replication is, so I definitely donā€™t use it. I will, again, be keeping my eye on it to see how it goes. If it fills up quickly then Iā€™ll download a log file or two and see if I can see any patterns of what is going on.

But if there isnā€™t, then you suggest I just disable binary logging altogether instead of using a cronjob to clear it out every X days? There wouldnā€™t be any need to view these logs for troubleshooting purposes in the future at all?

Maybe I am wrong but I think your WooCommerce site is to be blamed. 7k of products, uhhh. A small change that can affect all of them can be a huge database impact. Which is normal, I think. A good reason to upgrade your storage space.
Disabling binary logs is not suggested in some configurations, like master-slave. If it doesnā€™t hold anything important then you might want to disable it. If I were you I would just upgrade my storage, because it is the safest way in my opinion. Disabling binary logs looks safe in your situations, but I am not an expert which is why Iā€™d go with storage upgrade.
As I said in my first post:

If the files gets too big too fast, then think about a cron that deletes the log files more often than automatic cleanup. PS. I really suggest inspecting those logs.

1 Like

Yea, something looks to be strange as Iā€™m filling up a 100MB mariadb-bin.000001, mariadb-bin.000002, mariadb-bin.000003, etc log file every two hours

I just downloaded and renamed one mariadb-bin.000001.conf (as it defaults to opening it up in Wordpad), and Iā€™m seeing a ton of activity from the one site that doesnā€™t get anything added to it.

Iā€™m seeing a lot of jibberish like. . .

ƋĀ¬ĖœĆ™[Ā£ ā€™ ā€™CD ƙ[Ā” ) I mariadb-bin.000156ƙ[Ā¢ & o ā€œCD ƙ[ Ɣ

But then I see stuff like. . .

ā€œappstoreapps_com INSERT INTO wp_wfconfig (name, val, autoload) values (ā€˜scanFileProcessingā€™, ā€˜a:2:{i:0;s:82:ā€œwp-content/themes/applay/inc/option-tree/assets/images/colorpicker/color_wheel.pngā€;i:1;i:1540948243;}ā€™, ā€˜yesā€™) ON DUPLICATE KEY UPDATE val = ā€˜a:2:{i:0;s:82:ā€œwp-content/themes/applay/inc/option-tree/assets/images/colorpicker/color_wheel.pngā€;i:1;i:1540948243;}ā€™, autoloadā€

ā€œappstoreapps_com INSERT INTO wp_wfconfig (name, val, autoload) values (ā€˜scanFileProcessingā€™, ā€˜a:2:{i:0;s:86:ā€œwp-content/plugins/oiopub-direct/uploads/nBRQNS_iTunesIcon.no_transparency.125x125.pngā€;i:1;i:1540948507;}ā€™, ā€˜yesā€™) ON DUPLICATE KEY UPDATE val = ā€˜a:2:{i:0;s:86:ā€œwp-content/plugins/oiopub-direct/uploads/nBRQNS_iTunesIcon.no_transparency.125x125.pngā€;i:1;i:1540948507;}ā€™, autoloadā€

I would say 90% of this 100MB file is stuff like that. wp_wfconfig is Wordfence, so Iā€™m guessing thatā€™s a scan. . .but itā€™s as if the scans arenā€™t stopping or something.

I have since disabled Wordfence on that website, cleared out the logs folder again, and created a thread in the Wordfence WordPress plugin page.

Maybe they will be able to help me figure out what is going on there.

There you go. I donā€™t know if you remember but I told you in another topic:

I can say that I had incompatibility problems with Wordfence on more than one occasion, and I really felt its weight impact on my website. You should try other options, like bruiser or cerber security (I never tried cerber but I inspect how it works and I am satisfied) WordPress has excellent security guides and you can start from here if you like: https://codex.wordpress.org/Brute_Force_Attacks

Iā€™ll be switching to Ninja Firewall before I I try Bruiser

But those errors were happening on two different websites. . .so the two issues are unrelated in the first place

Ninja Firewall, looks good. But, seems like it works above WP, meaning that if it gets stuck, wp will not load. Pass. Maybe Iā€™m wrong.

What I do is: I am on google cloud so I have a fw working on top of everything. Only http and https ports free. Got sftp working for the sake of filezilla. Using WPS hide login - which grants me to completely avoid brute force attacks on wp-admin or wp-login page. Bruiser to do this:

and and

  • with some function php codes to disable and remove lost password fields and sending emails. block long requests and bad requests like eval, base64, etc etc. I also use extra security question on login instead of captcha.

All this without impact on my site with intrusive security plugins.

I have multiple levels of security on my login page which never even got touched because of wps hide login. The only hole is a ddos attack, but this can be mitigated if using cloudflare or similar. or you simply use ssh keys.

Hello,

if you do not use MySQL or MariaDB replication, you can safely comments all lines related to binlog in /etc/mysql/my.cnf and delete binlog files in /var/log/mysql/

1 Like

I donā€™t think this is true. I asked about this over on /r/WordPress and they said it was only good against certain scripts/bots

Hey, thank you for the suggestion in that thread long ago. That is what I ended up doing. I still donā€™t know what DB replication is or how it can be beneficial, so since I doubt I use it, I just stopped collecting those logs altogether.

Thereā€™s a completely different command (I believe) I can use. . .

  • tail -f /var/log/syslog | grep mysql

. . .to troubleshoot current database errors. So the ones that were filling up that log/mysql folder are useless to me.

Thanks again (and again). I see you all over this board helping so many people. I know that I, personally, have learned so much about EE and how it works from you and hope you continue as I know I have much more to learn.

Yes, errors related to MySQL will be displayed in the syslog (/var/log/syslog). You can use :

tail -n 500/var/log/syslog | grep mysql

To look for mysql logs in the last 500 lines of /var/log/syslog.

About DB replication, itā€™s only related to all architecture where a database is replicated accross multiple MySQL servers. Database replication require to enable binlog, because it use it to sync data accross MySQL nodes.

Maybe true, but,statistics talks for itself. I used to have at least 2k (sometimes up to 10k) attacks on my login, every day. Since I started using wps hide, I only receive user enumeration attacks and comment attacks (0 to 30 attempts daily) which Bruiser successfully blocks :slight_smile:

This can only mean that bots, scripts or w/e have no clue where my login page is. I do have limit login attempts too. So itā€™s wps as first level, bruiser as 2nd, limit login attempts 3rd, security question 4th. With 2 factor auth it would be complete. But I donā€™t want to use 2auth.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.