Tuesday, 3 May 2016

rotating pm2 logs using ansible playbook

Using Ansible to rotate pm2 logs

An example of rotating pm2 logs using Ansible is shown below. 


- hosts: "tag_role_webserver:&tag_env_{{env}}"
  become: true
  vars:
    user: jenkins
    logrotate_applications:
      - name: pm2
        definitions:
          - logs:
              - /home/{{ user }}/.pm2/logs/*.log
            options:
              - su {{ user }} {{ user }}
              - daily
              - rotate 3
              - compress
              - sharedscripts
              - missingok
              - notifempty
              - create 0600 {{ user }} {{ user }}
            postrotate:
              - su -c 'pm2 reloadLogs' {{ user }}


  roles:
    - logrotate

Wednesday, 17 September 2014

Quickly navigate your filesystem from the command-line

I have been interested to the topic Data Science for a while. Today, I was looking for any book on this topic and I came across this one Data Science at the Command Line. The book is not published yet and I can read it through Safari Books Online. I then came across the writer's blog. Among many things, I found this page http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html very very interesting. Since I found it so useful, I felt mentioning it here. All credit goes to Jereon Janssens. 

avoid strange characters for FTP password

I recently created a ftp server on Amazon created strong password (LAl)#oT!qjyQT!:@*)for a user's login.  Though I could login using that credential using FileZilla, the user was not having success. He was seeing the following error:

Status:                  Resolving address of ftp.***.com
Status:                  Connecting to *.*.*.*:21...
Status:                  Connection established, waiting for welcome message...
Response:            220 (vsFTPd 2.2.2)
Command:          AUTH TLS
Response:            530 Please login with USER and PASS.
Command:          AUTH SSL
Response:            530 Please login with USER and PASS.

Error:       Critical error: Could not connect to server

It had turned to be encoding issue. I found this good explanation here which made things clear for me. 

The lesson for is, keep ftp passwords simpler in future.

Friday, 2 May 2014

Solving MySQL error 1062

While MySQL replication is running, it might throw errors like below:

140502  1:56:38 [ERROR] Slave SQL: Could not execute Write_rows event on table DB_name.table_name; Duplicate entry '138114741' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000054, end_log_pos 880389787, Error_code: 1062
Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000054' position 880388660

Sometimes it happens that the MySQL replication stops because some statements received from the master fail when replayed on a slave. Luckily, however, this isn’t always the case as sometimes the failing statements don’t affect the data or might only affect data that isn’t important or is removed frequently (for example tables containing temporary data); in such cases then you may not need to rebuild the slave or re-sync with the Percona tools (which perform a time consuming comparison operation -especially on large tables- and might cause high load on both master and slave, up to causing locks and various issues depending on the usage of the servers at the time and the resources available); you can instead get the slave up and running again very quickly by simply skipping the failing statements, provided that these statements can be safely ignored as well as any data they might affect.
This can be done by temporarily stopping the slave, then instructing MySQL to skip one or more statements received from the master, and eventually starting the slave again.

mysql> stop slave;
Query OK, 0 rows affected (0.10 sec)
 
mysql> set global SQL_SLAVE_SKIP_COUNTER = 1;
Query OK, 0 rows affected (0.00 sec)
 
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

But the ultimate fix would be to replicate the faulty table from other DB server
Mysqldump:
mysqldump -u user -p DB_name table_name > table_name.sql
Restore:
mysql -u user -p db_name < /path/to/table_name.sql

Wednesday, 23 April 2014

Use of ProxyPassMatch


So, what to do if you need make use of Regular Expression instead of simple prefix matching.

ProxyPassMatch ^(/.*\.phtml)$ http://lt-legacy-1171567772.eu-west-1.elb.amazonaws.com$1

As you see here, any match for .phtml file will be passed to another backend server.


Tuesday, 22 April 2014

Forwarding Requests to Another Server in Apache

I have a server on AWS which runs php5. Client requests are sent to this server as it sits behind the ELB.  I also have another server which runs on php4 and isn't accessible publicly.  So, in this case, Client requests for contents written in php4 can only be accessible via the php5 server. To solve this issue, I used ProxyPass and ProxyPassReverse in apache configuration.


ProxyPreserveHost On
ProxyPass /maps/ http://lt-legacy-1171567772.eu-west-1.elb.amazonaws.com/maps/
ProxyPassReverse /maps/  http://lt-legacy-1171567772.eu-west-1.elb.amazonaws.com/maps/

So, requests to URLs starting with /maps/ to be forward to the server http://lt-legacy-1171567772.eu-west-1.elb.amazonaws.com/maps/.

The ProxyPassReverse directive ensures that any redirect headers sent from the php4 server (in this case lt-legacy-1171567772.eu-west-1.elb.amazonaws.com) wil be modified so that they appear to come from the php5 main server.

As you can see, the php4 server isn't actually the aws server itself. It's the AWS ELB which forwards requests to the backend php4 server.

If your backend servers sit behind a firewall/Security Group, you would have to open ports (http in this case) for the frontend servers (php5 server in this case).



Friday, 12 July 2013

Use hotelmap for London

http://www.hotelmap.com/ is a unique way to find the available hotels of your choice. I came across this through http://www.londontown.com/ and wanted to share with you all.

Hotelmap uses a referral system http://www.hotelmap.com/Refer. So you can also earn money by referring it to your friends and colleagues who are coming to London.

Thursday, 4 July 2013

Port forwarding issue


Someone on ServerFault asked the following question for which I gave the answer. It was later accepted by the questioner. 
=====================================================================
So, the question was:
I have a Router and four computer connected as the local network.
IPs:
Router(192.168.8.1)(internet ip:125.119.203.127)
      server1(192.168.8.3)
      my computer(192.168.8.8)
      ......
The server1 runs on the RedHat Linux which is set to use the port-redirect, to redirect port 80 to 8081. While the tomcat in this server use the port 8081.
[root@server1 bin]# iptables -t nat -vnL
Chain PREROUTING (policy ACCEPT 3169 packets, 274K bytes)
 pkts bytes target     prot opt in     out     source               destination
    4   208 REDIRECT   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:222 redir ports 22
  221 14971 REDIRECT   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:80 redir ports 8081

Chain POSTROUTING (policy ACCEPT 2253 packets, 141K bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 2252 packets, 140K bytes)
 pkts bytes target     prot opt in     out     source               destination
Now in my computer, I can access the site in the local network use browser:
http://192.168.8.3
http://192.168.8.3:8081
The Router is configurated to redirect the port 80 to port 80 on 192.168.8.3
But I can not access the site using the internet address:
http://125.119.203.127
Normally, this request should be dispatched to server1 192.168.8.3:80, then server1 will redirect to port 8081.
Then I change the configuration of the Router, to redirect the port 80 to port 80 on my computer.
Then I can access: http://125.119.203.127
So what is the problem?
=====================================================================
For which, my answer was:
From outside the network use namp to check whether port 8081 is available externally
$ nmap -PN external_ip
This command will show all listening services externally. Since you can access the site using internally http://<internal_ip>:8081, the issue is with the router.
As you have mentioned that "The Router is configurated to redirect the port 80 to port 80 on ", what configuration is done to forward port 8081 from the router to the internal server?
I think you need to forward port 8081 from the router to port 80 to the internal server.



Monday, 1 July 2013

Finsbury Circus

Peace and tranquility at Finsbury Circus

I have found this location today just behind the Moorgate station while waiting for a later train back home. With all chaos behind me, this is quite wonderful location to chill out when I need to think about anything. 

My geeky stuff is ongoing. I have managed to score a few more reputation, which was good. 

I have been waiting on some good news, so fingers crossed. 

Sunday, 30 June 2013

Celebrating 100 Reputation at http://unix.stackexchange.com/ today

I have just crossed 100 reputation mark at http://unix.stackexchange.com/. I have started being more active lately by giving answers and reading other people comments. Now my target is to achieve 1000 marks in next two months. It's proper geeky stuff but a real test of someone's Unix skills. There are some proper gurus out there. I don't now whether I can achieve that level of expertise. However, this learning experience is quite exciting.

Good Night.

Wednesday, 26 June 2013

Weight Loss - My Way

Over the last few years, I have had lots of complains about my weight gain from my near ones. I haven't listened much to those complains but in fact, they were right. I had gained quite a few pounds around my waist. It wasn't pretty while I tried to wear some stylish shirts as these come in slim style. I had been thinking lately how I can tackle this issue. I was more concerned about my looks rather than health impacts.


So, what did I do?

A colleague of mine told me that he goes to bed at 9 pm. It surprised me a lot. For a person like who doesn't go to bed before 12am, it was a shock. But what he also me also made me think. I find him as a person who is always so happy at work and I always wondered how he manages that. It's not that I am unhappy but he is in a different level. In his opinion, it was partly down to his sleep pattern. He told me, "Go to bed very early once or twice a week. It will change your life".

So, I tried this. I started going bed by 11pm and some nights I went to bed really early. I am not sure whether it made me happier or not but I started seeing some real change in my physique. I started loosing weight. Within three weeks, I lost 3~4 kg weight. It made me realise, all these years of late sleep had surely contributed to my weight gain as I always knew that I am not a heavy eater.

I continued this new regime. Today, it's nearly three months since I had changed my sleep pattern. I now try to make sure that I have minimum 7 hours of sleep every night.

So, who wants to know how much weight I have lost?

The answer is, 8.5 kg so far.

Yes, I also had less amounts of junk food, such as Chicken & chips or kebab.  I also did some walking after evening meal but not so regularly.

It was a simple procedure which most of us might know of. But I have tried and tested it on myself and it worked.



serverfault.com

Lately, I have become a keen follower of the http://serverfault.com/ site. Those who don't what it is, serverfault is part of Stack Exchange Network which is a network of question-and-answer websites. It is incredible to see how many SysAdmins are engaged though it by asking questions and giving answers. Once you a question, you have a good chance of getting a reply fairly quickly if your topic is curious enough. I have asked questions and been given a reply within a day. I myself have given answers to several questions so far. You get voted up or down on your answers based on whether others like yours or not. It is a good way test your knowledge. You can also learn more about a topic. I now find that it is better to read these questions and answers to enhance my knowledge on a certain topic.

One thing to be careful about. Always try to elaborate your answers rather than giving a short and quick answers. Don't just post links. You must make sure that your answer is relevant. If you don't follow these, others will vote you down.


Sunday, 20 January 2013

What To Do When Your Website Goes Down?


What to do when a Website has gone down?

  • Check that it has actually gone down
Is it just me or everyone else? Don't take client's word for granted.
  • Figure out what has gone down?
A website can appear to have gone down mainly for one of the reasons. 
  1. A programming error on the website
  2. A DNS problem, or an expired domain
  3. A networking problem
  4. Something on the server have crashed
  5. The whole server have crashed
http://coding.smashingmagazine.com/2010/12/13/what-to-do-when-your-website-goes-down/#more-75513


Wednesday, 16 May 2012

Chuck's Blog: MySQL Utilities and Global Transaction Identifiers...

Chuck's Blog: MySQL Utilities and Global Transaction Identifiers...: The new MySQL 5.6 Development Milestone Release (DMR) includes many new enhancements. One of the most impressive is the use of Global Transa...

Wednesday, 9 May 2012

Saturday, 5 May 2012

Don't Sweat the Aubergine

I have a keen interest for cookery books. Occasionally, I buy one or two. Though, I do loose interest soon.

Anyway, yesterday I went to the Daunt Books at Cheapside, near the St Pauls. It was Friday evening, I left office a bit earlier than usual. As I was looking around and hoping I would find a book I would truly buy today, I saw this book Don't Sweat The Aubergine. Who says you shouldn't buy a book by its cover, I do.

On my way back to home in the train, I started flicking through the pages and stopped at the section Eggs.  Boiled eggs had always been a mystery to me. I always had hit and miss. I went though the section on how to make boiled eggs. The writer started off saying he does not the readers patronized. I wasn't. Like me, most people do not know this simple trick. Now I know it.

  1. Bring the water to the boil, then the heat on your hob right down before lowering in the egg or eggs. I guess, you have taken the eggs out of the fridge sometime ago. I prefer to boil water using a cattle and then pour it in the saucepan.
  2. You are less likely to crack the shells if the water is at a gentle simmer and the eggs will benefit from slow cooking. 
  3. Keep the heat at a low level below simmering or boiling point, just let it show a few rising bubbles.
  4. It's very difficult to give exact timings. I would suggest 5 minutes for a medium boiled egg with a runny yolk: after 7 minutes, the yolk will be partly runny. At 10@12 minutes, it will be hard-boiled, but still moist.
  5. If you prefer hard-boiled eggs, put them into cold water for a while when they're ready; otherwise, their residual heat will carry on cooking them. You don't want that to happen.
So, this is the simplest method to make boiled eggs. Enjoy!



Who am I?

Dear Readers,

My name is Mezbaur Rahman. I am an Systems Administrator by profession. Those who do not know what a System Administrator do, can think of an IT person looks after the Servers, Operating Systems, Networks etc. I live in North London.

My passion is Linux and so dislike Windows. I am creating this first blog post using my Ubuntu laptop.

My political views are very much liberal. I believe in free speech, open conversation and tolerance. Though people say, I am very arrogant at times.  I don't disagree. I stick to my opinion when I am sure of it.

Occasionally, I do some photography. I publish my photos through Flickr, great stuff!

Like the billion others in this world, I also have my Facebook account. You can get introduced to me though Linkedin.

For those who thinks Twitter is the daddy, can find me here. Simply tweet me on @mezbaur.

So, there you. This is my first proper blog and this time, I am prepared to be consistent.