Later Ctrl + ↑

How to set up server monitoring with the Munin project

If you want to have monitoring by the Munin project, you have to install munin server on one server and munin node per every server which you want to have monitoring. For example:

First server have munin server and munin node together;
Second server have only munin-node;
Third server have only munin-node too, etc.

Munin server will collect states from nodes every some minutes and show them in useful web interface as graphics.
Munin nodes only collects states of servers which they installed.

Installing

If you want to install munin server:

sudo apt install munin

Or if you want to install munin-node:

sudo apt install munin-node

Common commands which you have to enter anyway:

sudo apt install munin-plugins-extra

And:

sudo apt isntall libwww-perl

Or if you got fail above:

sudo apt install libio-all-lwp-perl

Configuring munin nodes

For the next step you need to allow access for munin server to munin nodes. Open munin node configure file on every monitoring server:

sudo mcedit /etc/munin/munin-node.conf

And find this line:

allow ^127\.0\.0\.1$

Append munin server IP address in new line. It need only for nodes, installed on other servers where munin server didn’t install.

Check the node port:

...
# And which port
port 4949

You can change port and/or open in the server firewall if blocked one.

For apply changes restart node:

sudo service munin-node restart

Configuring munin server

Now, you need to open munin server configuration file:

mcedit /etc/munin/munin.conf

And append all nodes including local node in this file. For example:

[ratchet]
    address 127.0.0.1
    use_node_name yes
    port 4949

[serverN]
    address 255.255.255.255
    use_node_name yes
    port 4949

[serverN+1]
    address 255.255.255.255
    use_node_name yes
    port 4949
...

Perhaps you already have local node in this file, so check what you didn’t add several local nodes.

Configuring web interface

Apache2

If you use Apache as a front web server, then:

sudo apt install apache2-utils libapache2-mod-fcgid libcgi-fast-perl
sudo a2enmod rewrite
sudo a2enmod fcgid
sudo service apache2 reload

And create admin account for web interface:

htpasswd -c /etc/munin/munin-htpasswd admin

You can change username “admin” to what you want.

After this steps open for edit munin host configuration file:

mcedit /etc/apache2/conf-enabled/munin.conf

You can use my typical configuration:

# Enable this for template generation
Alias /munin /var/cache/munin/www

# Enable this for cgi-based templates
#Alias /munin-cgi/static /var/cache/munin/www/static
#ScriptAlias /munin-cgi /usr/lib/munin/cgi/munin-cgi-html
#<Location /munin-cgi>
#       Order allow,deny
#       Allow from localhost 127.0.0.0/8 ::1
#       AuthUserFile /etc/munin/munin-htpasswd
#       AuthName "Munin"
#       AuthType Basic
#       require valid-user
#</Location>

<Directory /var/cache/munin/www>
        Order allow,deny
        Allow from all #localhost 127.0.0.0/8 ::1
        Options None

        # This file can be used as a .htaccess file, or a part of your apache
        # config file.
        #
        # For the .htaccess file option to work the munin www directory
        # (/var/cache/munin/www) must have "AllowOverride all" or something 
        # close to that set.
        #

        AuthUserFile /etc/munin/munin-htpasswd
        AuthName "Munin"
        AuthType Basic
        require valid-user

        # This next part requires mod_expires to be enabled.
        #

        # Set the default expiration time for files to 5 minutes 10 seconds from
        # their creation (modification) time.  There are probably new files by
        # that time. 
        #

    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault M310
    </IfModule>

</Directory> 

# Enables fastcgi for munin-cgi-html if present
#<Location /munin-cgi>
#    <IfModule mod_fastcgi.c>
#        SetHandler fastcgi-script
#    </IfModule>
#</Location>

#<Location /munin-cgi/static>
#       SetHandler None
#</Location>

# Enables fastcgi for munin-cgi-graph if present
ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
<Location /munin-cgi/munin-cgi-graph>
        Order allow,deny
        Allow from all #localhost 127.0.0.0/8 ::1
        AuthUserFile /etc/munin/munin-htpasswd
        AuthName "Munin"
        AuthType Basic
        require valid-user
        <IfModule mod_fcgid.c>
            SetHandler fcgid-script
        </IfModule>
        <IfModule !mod_fcgid.c>
            SetHandler cgi-script
        </IfModule>
</Location>

ScriptAlias /munin-cgi/munin-cgi-html /usr/lib/munin/cgi/munin-cgi-html
<Location /munin-cgi/munin-cgi-html>
        Order allow,deny
        Allow from all #localhost 127.0.0.0/8 ::1
        AuthUserFile /etc/munin/munin-htpasswd
        AuthName "Munin"
        AuthType Basic
        require valid-user
        <IfModule mod_fcgid.c>
            SetHandler fcgid-script
        </IfModule>
        <IfModule !mod_fcgid.c>
            SetHandler cgi-script
        </IfModule>
</Location>

Reload web server:

sudo service apache2 reload

nginx

If you using nginx web server, then open config file:

sudo mcedit /etc/nginx/sites-available/localhost.conf

And add next lines:

location ^~ /munin {
    alias /var/cache/munin/www;
    auth_basic "Admin Zone";
    auth_basic_user_file /etc/munin/munin-htpasswd;
}

Reload web server:

sudo service nginx reload

Plugins

Apache monitoring

For activate Apache monitoring enter this on node servers:

ln -s /usr/share/munin/plugins/apache_accesses /etc/munin/plugins/apache_accesses
ln -s /usr/share/munin/plugins/apache_processes /etc/munin/plugins/apache_processes
ln -s /usr/share/munin/plugins/apache_volume /etc/munin/plugins/apache_volume
mcedit /etc/munin/plugin-conf.d/munin-node

Find/add apache configuration:

[apache_*]
env.url http://127.0.0.1:%d/server-status?auto
env.ports 80

Reload node:

sudo service munin-node restart

Check what it works:

sudo apt install lynx
lynx http://127.0.0.1:8070/server-status?auto
munin-node-configure --suggest | grep apache

It have to be only “yes | yes”.

nginx monitoring

ln -s /usr/share/munin/plugins/nginx_request /etc/munin/plugins/nginx_request
ln -s /usr/share/munin/plugins/nginx_status /etc/munin/plugins/nginx_status
mcedit /etc/munin/plugin-conf.d/munin-node

Find/add next lines:

[nginx*] 
env.url http://localhost/nginx-status

Reload node:

sudo service munin-node restart

And check what it works:

sudo apt install lynx
lynx http://127.0.0.1/nginx-status
munin-node-configure --suggest | grep nginx

MySQL monitoring

ln -s /usr/share/munin/plugins/mysql_innodb /etc/munin/plugins/mysql_innodb
ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/mysql_queries
ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/mysql_slowqueries
ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/mysql_threads
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_
ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/mysql_bytes
sudo apt install libdbi-perl libdbd-mysql-perl libcache-cache-perl
sudo service munin-node restart
munin-node-configure --suggest | grep mysql
 52   1 mon  
 22   1 mon  
 12   1 mon  
 20   1 mon  
 25   1 mon  
 53   2 mon  
 37   2 mon  

How to turn off monitoring and saving CHMOD in Git

Main command:

git config --global core.fileMode false

Unfortunately, it will be working for new cloned repositories only. Why? Because, when you cloned repositories earlier, Git placed the choice “fileMode = true” in their files of a configuration. And now you need to use this command in every cloned repository for fully fixing CHMOD issue:

cd your_first_repository/
git config --unset core.fileMode
cd your_second_repository/
git config --unset core.fileMode
... and next

Now, earlier cloned repositories will use the global configuration at the beginning of this instruction.

 34   2 mon  

How to set the MySQL root password in the Debian 9 (or MySQL 5.7+, MariaDB 10.1+)

You can think that there is no problem to set the root password in installation time. It’s true until 5.7 version of MySQL (or MariaDB 10.1). Now you can be authorized under root (and without password), but only through the auth_socket. For example, authorization under root in mysql-client:

mysql -u root

It means that the phpMyAdmin or other scripts will not be able to use root access more.

Now the next methods do not work:

mysqladmin -u root password
SET PASSWORD FOR root@localhost=PASSWORD, UPDATE user SET Password=PASSWORD

What can we make to use root privileges as earlier? We can create new user with root privileges and use it. Let’s do that.

First step:

mysql -u root

Create new a user with root privileges:

CREATE USER 'root2'@'localhost' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'root2'@'localhost';
FLUSH PRIVILEGES;

Where root2 and PASSWORD change to what you want.

Unfortunately, the user created by such method will not be able to give privileges to other users through the same phpMyAdmin. Therefore the following command can be useful to you for giving privileges to users through mysql-client:

GRANT ALL PRIVILEGES ON `DB_NAME`.* TO 'DB_USER'@'localhost' WITH GRANT OPTION;

Where DB_NAME and DB_USER change to what you want again.

 48   2 mon  

How to import big MySQL dump quickly

Warning: This trick is only for InnoDB storage engine.

Open MySQL config file “/etc/mysql/my.cnf”:

mcedit /etc/mysql/my.cnf

Write into [mysqld] section:

[mysqld]
...
innodb_flush_log_at_trx_commit = 2

What does that mean? Now, data will be recorded not more often than once per second! It will very unload file system and increase speed of import.

But you need check that you haven’t this option:

...
general_log = 1
...

Because everything will be worthless with that option! Every SQL query will be written on the disk and import will be worked slowly.

You need to disable “slow_query_log” if it enabled too.

Well, if you don’t have that options or you have deactivated it, for the next step you need to restart the database server:

service mysql restart

I have to notice you, if your dump archived in gzip, you need to unpack it and import only raw dump! Because unpacking on the fly and importing at the same time works slowly.

So, let’s import:

mysql -u username -p db_name < dump.sql

After all don’t forget to delete or restore “innodb_flush_log_at_trx_commit” option from config “/etc/mysql/my.cnf” and reload mysql server!

Sources: ruhighload and mysql.com.

 46   2 mon  
Earlier Ctrl + ↓