Mobil Mewah

Salah satu sumber Inspirasi.

Mobil Sport terbaik

Anda pasti bisa memilikinya.

Bermain dengan pesawat

Salah satu ide yang gila, Balapan di udara.

Bermain di angkasa

Apakah ini salah satu Goals dalam hidup anda? anda pasti bisa mencapainya

Monday 23 July 2018

keepalived issue with iptables

When talking about High Availability services, we can use keepalived to do a automatic failover between 2 host.

Keepalived is working like a charm by using a virtual ip. 1 Master elected for normal operation, and others as backup.
When master have issue, backup will take over the services.

Issue arise with configuration, where there is iptables entry to drop any vrrp traffic type. This was issue with the configuration.

To mitigate this, look for the config of keepalived.conf . change entry from :

vrrp_strict 

to become :

vrrp_accept

This entry will make keepalived will not use iptables.

Keepalived version we use was V1.3.5

Monday 2 July 2018

Environment variable with ChicagoBoss

On Chicagoboss I need to have some configuration variable set in the main configuration. Just like my experience with Django framework on settings.py

In Chicagoboss, we can do it also and add our on config variable in the configuration file, which are boss.config.

These below are the part of the config we can custom :

%% APPLICATION CONFIGURATIONS

%% domains - A list of domains to serve the application on
%% static_prefix - The URL prefix of static assets
%% doc_prefix - The URL prefix for developer documentation
{ myapp, [
    {path, "../myapp"},
    {base_url, "/"},

    {dummy, true}
]}
So we can add the variable for our application with below settings :


%% APPLICATION CONFIGURATIONS

%% domains - A list of domains to serve the application on
%% static_prefix - The URL prefix of static assets
%% doc_prefix - The URL prefix for developer documentation
{ myapp, [
    {path, "../myapp"},
    {base_url, "/"},

    {dummy, true}.
    {mail_from, "justme@mydomain.com"},
    {api_key, "324298nvUYSCN298snk92442ps"}

]}
Now how we can use it on the application. We can use :

application:get_env(myapp, api_key).

If we want to print out on console :

io:fwrite("~p", [application:get_env(myapp, api_key)]).

And if we want to assign the variable to our local variable in the app we can use :

{ok, apikey} = application:get_env(myapp, api_key).

With this we can add as many as variable we need on the config.


Monday 18 June 2018

Generate a list from atom and string

On Erlang, there is no string data type, but its a list of strings. So different with other language.
Also some function return an atom, which usually we need to combine it with our string. For example was the need to generate an sql query from an input parameter and our hard coded string.

Let say we generate a year from erlang fun, then from that year, we generate the month and data.
To do this properly are :

{{Year,_,_},_} = calendar:universal_time(),
Y1 = io_lib:format("~p-01-01",[Year]),
Y2 = lists:flatten(Y1),

Y2 result will be  "2018-06-18"


Hope this helps, as i look all around the google for this.

Wednesday 13 June 2018

Posgresql reporting query

With PostgreSQL when doing with datetime for reporting, it realy help if the DB can aggregate your needed data rather than process it yourself.

I found this interesting and useful as i start needed query for reporting from my dataset.

For example i want to have a list of records which user register per month. With postgresql here is the query :

SELECT date_trunc('month', created_at),
       count(*)
FROM users
GROUP BY 1
ORDER BY 1 DESC;


With date_trunc PostgreqSQL do its magic and return you the needed data without doing a query per month. really not so effective query. To get per week activity :

with months as (
  select month
  from generate_series('2018-01-01'::date, now()::date, '1 month'::interval) month
)

SELECT months.month,
       count(pmactivitylogs.id)
FROM months,
left join pmactivitylogs on date_trunc('month', pmactivitylogs.created_at) = months.month

GROUP BY 1
ORDER BY 1 DESC;


We will get all the monthly count of records for our reporting.

For more details get the docs on postgresql web site.

Sunday 29 April 2018

Using Centos 5.x repo after EOL

We know Centos 5.x already EOL , and no update given.
But we sometimes still use the version as upgrade will be broke our application usage.

So problem arise when we need to install application package in that version. The repo is moved from main url of the release, and moved to vault.centos.org . To able to install from your yum package manager , we need to update the yum base url.

Here are some command to fix it.

sed -i 's/enabled=1/enabled=0/' /etc/yum/pluginconf.d/fastestmirror.conf
sed -i 's/mirrorlist/#mirrorlist/' /etc/yum.repos.d/*.repo
sed -i 's|#baseurl=http://mirror.centos.org/centos/$releasever|baseurl=http://vault.centos.org/5.11|' /etc/yum.repos.d/*.repo

With above command, yum config updated and you will be able to install package from yum repo and download all the dependencies.

Beware as the app no longer supported and might introduce security issue.



Thursday 29 March 2018

To add a Vlan in a VMware cluster in 1 line of command

One task as a Vmware admin was to add a network Vlan on the ESXi server you manage.

How are you going to update a cluster with more than 10 server ? Simple way was access the Vcenter and do it 1 by 1 on network config. Really ?

Can we do like a linux machine, update on 1 command and then enter ?

Get friend with the Vsphere CLI , you can do a batch update on a cluster.

Here are command to add a vlan in a Vmware cluster using Vsphere CLI.

Connect-VIServer vcenter01.localnetwork.local
get-cluster -name datacenter01 | Get-VMHost | Get-VirtualSwitch -name “vSwitch1” | New-VirtualPortGroup -Name “Srv.SecureServers” -VLanId “1337”

You will be thankfull with these command.

Yes thank you .

I am a lazy system admin.

Tuesday 6 March 2018

Docker the new best friend of developer

Docker Logo
Recently i had review some Docker talks in youtube, and curious what it's value for me to learn it. So Docker is some package manager like vagrant, which ships code easily, or like to say same with puppet / chef out there.

And this time , seems docker differentiate it with Virtualization and claim more better and efficient. Like Git which only updates the changes part, so its efficient on storage and speed.

Also Docker based on Go, and foundation is running lxc (Linux container). so if compare to virtualization, of course docker is faster, as it is native on the os.

So the promise of Docker was when you build and run on your machine, it will run in any machine. Sounds good for developer. And for me this one of my problem with development, as i have move several times on my computer which have issue, i have to build my development environment, not to mention different OS and also updated library make it worse and some times not compatible anymore.

I problem i hit was my app using CakePHP 1.1 and PHP 5.1, yeah so old. I try to run it but cannot on newer OS, but install old OS version neither an options as many provider not support old OS also. Try tinkering with Docker and have fun, but still PHP5.1 still not available in Docker.

Thats the end of my journey with Docker, and then some days ago also hit issue with Erlang.
I need my Erlang code run with OTP 17.5 but on newest OS debian stretch , cannot compile perfectly with crypto support.

Tired with this, try Docker again, and i see some light with the development using Docker, Docker-compose.

Let see next step, i will blog more on my Docker journey.

Twitter Delicious Facebook Digg Stumbleupon Favorites More