Oct 16 2018

Technical issues

Category: TechnicalIuliana @ 15:07

A few days ago the blog started having hiccups again. And since I’ve lost most of my morning trying out Apache settings and then monitoring it and making sure it stays up. I’ve read the documentation, I’ve consulted stackoverflow and it makes sense why my configurations were wrong, but I cannot understand for the life of me why had the blog been working like this for almost 2 years.

To keep it short, my Apache was configured like this:
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>

<IfModule worker.c>
StartServers 8
MaxClients 256
MinSpareThreads 10
MaxSpareThreads 50
ThreadsPerChild 10
MaxRequestsPerChild 4000
</IfModule>

Not sure if these settings are default, or where have I got them from, but apparently these settings are a little too generous for an AWS micro machine. Because, yes, this is the machine this blog is being hosted on.This means, in case you had doubts: 10 GB HDD and 1 GB or RAM, that MySQL and Apache are fighting over. And apaprently lately Apache is winning.
Anyway, I’ve toned down the following values.
<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 14
MaxClients 14
MaxRequestsPerChild 500
</IfModule>

<IfModule worker.c>
StartServers 5
MaxClients 14
MinSpareThreads 10
MaxSpareThreads 50
ThreadsPerChild 10
MaxRequestsPerChild 500
</IfModule>

And the blog has been up all morning. Let’s hope I’ve fixed it, otherwise, I might be forced to upgrade. And I really do not want to do that. I mean, this blog is just a personal project that allows me to practice typing and expressing my ideas in a way other people (maybe!?) can understand. It does not make money, so I’m reluctant to spend too much on keeping it up.  I’ll get into details in a future post, about the costs, advantages, and disadvantages of hosting a site on a virtual machine.

I don’t have many readers, but to the ones that read me, I am really sorry for the blog being down and please bear with it being a little bit slow until I find a solution.

Tags: , ,


Oct 03 2016

WordPress & MySql…

Category: English posts,TechnicalIuliana @ 23:28

… is a recipe for disaster. Once every few weeks I get this:

Error establishing a database connection.

Today I tried another two tricks:
1. Adding the following configurations to the Apache httpd.conf file.

StartServers 3
MinSpareServers 3
MaxSpareServers 5
MaxRequestWorkers 25
MaxConnectionsPerChild 0

2. Configurating MySQL like this in /etc/my.cnf
[mysqld]
innodb_buffer_pool_size=10M
performance_schema=offM
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Set internal buffers, caches and stacks very low
key_buffer = 16K
max_allowed_packet = 16K
table_cache = 1
sort_buffer_size = 16K
read_buffer_size = 16K
read_rnd_buffer_size = 1K
net_buffer_length = 1K
thread_stack = 16K
# Don't listen on a TCP/IP port at all.
# Will still work provided all access is done via localhost
skip-networking
server-id = 1
# Set the query cache low
query_cache_limit = 1048576
query_cache_size = 1048576
query_cache_type = 1
# Set various memory limits very low, disable memory-hogging extras
[mysqldump]
quick
max_allowed_packet = 16K
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 16K
sort_buffer_size = 16K
[myisamchk]
key_buffer = 16K
sort_buffer_size = 16K
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

I’ll come back here with an update, in case I managed to make the bloody damn thing stop from crashing.

[Update]: Well, the database no longer crashed, but the ec2 instance did. So I had to terminate it and create a new one. And of course I did not remember anything I did to keep it working so I cam back to this post. And I just found out that the innodb_buffer_pool_size property value depends on the machine you are on. If it is too big, the connection pool will require too much memory and if you do not have that memory, Mysql will still crash. So I just switched to the smallest value that I think it could be necessary for my blog to be accessed by my 50 readers per day: 10MB. And aside from this I modified my instance to add some swap. You can find a really useful tutorial here, I used the first option to create the file in the current file system.

 

Tags: , ,


May 16 2010

Configuring BIND with Dynamic Loading Zones and MySQL

Category: English posts,TechnicalRpx @ 2:29

One of the most annoying things about BIND is the way zones are managed. They’re kept in files which sometimes get very clogged and hard to maintain, and it needs a restart/reload every time you need to modify something.

However, there is a solution to this issue, and it’s quite easy to implement on Gentoo. BIND can be compiled with DLZ and MySQL support. What does this mean? This means that the backend for BIND will be a MySQL database, and the zones will be dynamically loaded from that database, and any modification will be taken into consideration immediately.

In order to do this, you need to set some USE flags:

# echo net-dns/bind dlz mysql -threads >> /etc/portage/package.use

This enables DLZ and MySQL support, and it disabled pthreads support since it doesn’t seem to get along well with DLZ (don’t worry, BIND will still be multithreaded).

Emerge and configure the package in the chroot. Never run BIND outside a chroot!

Time to create the database. Log on to mysql with a privileged user.

> create database named;
> grant all privileges on named.* to named@’localhost’ identified by ‘password’;
> flush privileges;
> use named;
> CREATE TABLE `records` ( `id` int(10) unsigned NOT NULL auto_increment, `zone` varchar(255) NOT NULL, `ttl` int(11) NOT NULL default ‘14400’, `type` varchar(255) NOT NULL, `host` varchar(255) NOT NULL default ‘@’, `mx_priority` int(11) default NULL, `data` text, `primary_ns` varchar(255) default NULL, `resp_contact` varchar(255) default NULL, `serial` bigint(20) default NULL, `refresh` int(11) default NULL, `retry` int(11) default NULL, `expire` int(11) default NULL, `minimum` int(11) default NULL, PRIMARY KEY (`id`), KEY `type` (`type`), KEY `host` (`host`), KEY `zone` (`zone`) );
> CREATE TABLE `xfr` ( `zone` varchar(255) NOT NULL, `client` varchar(255) NOT NULL, KEY `zone` (`zone`), KEY `client` (`client`) );

This will create 2 tables. In the records table you will keep all the records regarding all the zones. The xfr table keeps track of zone transfers.

 

id zone ttl type host mx_priority data primary_ns resp_contact serial refresh retry expire minimum
100 foo.ro 86400 SOA @ NULL NULL ns1.foo.ro. NULL 123456 10800 7200 604800 86400
101 foo.ro 1800 NS @ NULL ns.foo.ro. NULL NULL NULL NULL NULL NULL NULL
102 foo.ro 1800 MX @ 10 mail.foo.ro. NULL NULL NULL NULL NULL NULL NULL
103 foo.ro 1800 IN ns1 NULL 10.0.0.1 NULL NULL NULL NULL NULL NULL NULL
104 foo.ro 1800 IN mail NULL 10.0.0.40 NULL NULL NULL NULL NULL NULL NULL
105 foo.ro 1800 IN www NULL 10.0.0.16 NULL NULL NULL NULL NULL NULL NULL
110 bar.ro 86400 SOA @ NULL NULL ns1.bar.ro. NULL 987654 10800 7200 604800 86400
111 bar.ro 1800 NS @ NULL ns.bar.ro. NULL NULL NULL NULL NULL NULL NULL
112 bar.ro 1800 MX @ 10 mail.bar.ro. NULL NULL NULL NULL NULL NULL NULL
113 bar.ro 1800 IN ns1 NULL 172.18.0.10 NULL NULL NULL NULL NULL NULL NULL
114 bar.ro 1800 IN mail NULL 172.18.0.20 NULL NULL NULL NULL NULL NULL NULL
115 bar.ro 1800 IN www NULL 172.18.0.15 NULL NULL NULL NULL NULL NULL NULL

As you can see from above, the records table contains all the fields which can be used in a normal zone file too. Just use an SQL browser (phpMyAdmin works great) and edit them. Obviously, the fields which do not apply to a type of record must remain NULL.

Now modify ${CHROOT}/etc/bind/named.conf

dlz "Mysql zone" { database "mysql
{host=127.0.0.1 port=3306 dbname=named user=named pass=YeOldePassworde}
{SELECT zone FROM records WHERE zone = ‘%zone%’}

{SELECT ttl, type, mx_priority, IF(type = ‘TXT’, CONCAT(‘\"’,data,’\"’), data) AS data FROM records
WHERE zone = ‘%zone%’ AND host = ‘%record%’ AND type <> ‘SOA’ AND type <> ‘NS’}

{SELECT ttl, type, data, primary_ns, resp_contact, serial, refresh, retry, expire, minimum FROM records
WHERE zone = ‘%zone%’ AND (type = ‘SOA’ OR type=’NS’)}

{SELECT ttl, type, host, mx_priority, IF(type = ‘TXT’, CONCAT(‘\"’,data,’\"’), data)
AS data, resp_contact, serial, refresh, retry, expire, minimum FROM records
WHERE zone = ‘%zone%’ AND type <> ‘SOA’ AND type <> ‘NS’}

{SELECT zone FROM xfr where zone=’%zone%’ AND client = ‘%client%’}"; };

 

Restart bind and you’re done. Now Microsoft fanboys can’t brag about BIND’s lack of “on-the-fly” record modification anymore :)

Tags: , ,


Jan 23 2010

Kill mySQL! Kill it with fire!!!

Category: English posts,TechnicalRpx @ 12:21

I hated mySQL from day one I had to work with it. It’s most possibily the worst DBMS out there and for some reason I cannot seem to grasp, it’s the most popular. WHY?! WordPress offers support only for mySQL… Silverstripe offers support only for mySQL… WHY?! It’s a shitty DBMS which lacks even the most primitive features (foreign keys anyone?) and has next to ZERO reliability. Every time… every motherfuckin’ time there’s a power outage, all the tables go amok and mySQL refuses to work. It’s curteous enough to spam the logs with “table integrity problem blah blah fuckin’ blah” but it’s stupid enough to not do a god damn thing about it!

I hope Oracle throws this cursed piece of shit that dares to call itself “DBMS” into oblivion. Maybe then, all these platforms like WordPress will have a reason to switch to a better DBMS as backend.

Meh… fortunately, there are already some hacks on the net, done most probably by people who are as “impressed” with mySQL as I am, which allow WordPress to run on MSSQL. That’s what I’m going to use when the new server arrives on site.

R.I.P. mySQL

Tags: ,


Jan 21 2010

The Sun shines over the Oracle

Category: English posts,TechnicalRpx @ 16:59

The European Comitee has decided to let the Oracle-Sun deal go through. And it was about time they did!

Basically, the EC has come to the (obvious) conclusion that should Oracle decide to kill mySQL, there are enough open-source alternatives (like PostgreSQL) to keep the market happy.  

Given the open source nature of MySQL, the Commission also assessed Oracle’s ability and incentive to remove the constraint exerted by MySQL after the merger and the extent to which this constraint could, if necessary, be replaced by other actors on the database market.

Let’s see how it evolves.

Tags: , ,