27 Mar 2017
After you’ve followed the familiar Proxmox Ceph Server
manual youl’ll have the brand new Ceph clutser up and running, here I’m collecting the basic tasks
and command you’ll need to manage Ceph cluster.
Ceph structure info
Disk structure
Ceph automatically configure and creates the block device in /dev/rbd/<pool-name>/
root@node1:~# ls -la /dev/rbd/<pool-name>/
total 0
drwxr-xr-x 2 root root 560 mar 26 15:05 .
drwxr-xr-x 3 root root 60 mar 23 13:29 ..
lrwxrwxrwx 1 root root 11 mar 26 12:39 vm-101-disk-1 -> ../../rbd0
lrwxrwxrwx 1 root root 11 mar 26 13:42 vm-102-disk-1 -> ../../rbd1
lrwxrwxrwx 1 root root 11 mar 23 19:34 vm-103-disk-1 -> ../../rbd2
lrwxrwxrwx 1 root root 11 mar 24 08:31 vm-103-disk-2 -> ../../rbd3
It is a normal block device that can be mounted in a regular way
root@node1:~# fdisk -l /dev/rbd0
Disk /dev/rbd0: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4194304 bytes / 4194304 bytes
Disklabel type: dos
Disk identifier: 0x53332713
Device Boot Start End Sectors Size Id Type
/dev/rbd0p1 * 63 41110334 41110272 19,6G 83 Linux
/dev/rbd0p2 41110335 41929649 819315 400,1M 5 Extended
/dev/rbd0p5 41110398 41913584 803187 392,2M 82 Linux swap
so
root@node1:~# mount /dev/rbd0p1 /media
root@node1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/rbd0p1 20G 17G 1,4G 93% /media
root@node1:~# ls -la /media/
total 2,1G
drwxr-xr-x 24 root root 4,0K mar 23 13:43 .
drwxr-xr-x 22 root root 4,0K mar 9 18:06 ..
drwxr-xr-x 2 root root 4,0K apr 10 2012 bin
drwxr-xr-x 3 root root 4,0K ago 8 2012 boot
lrwxrwxrwx 1 root root 11 apr 9 2010 cdrom -> media/cdrom
drwxr-xr-x 2 root root 4,0K set 3 2012 dev
drwxr-xr-x 109 root root 12K mar 23 13:43 etc
drwxr-xr-x 11 root root 4,0K mag 21 2013 home
drwxr-xr-x 2 root root 4,0K ott 26 2009 initrd
...
Config files structure
Benchmarking
BLOCK WRITE 4KB
root@node1:~# /usr/bin/rados -p rbd bench -b 4096 300 write -t 32 \
--no-cleanup -m 10.0.4.1:6789 -n client.admin --keyring \
/etc/pve/priv/ceph.client.admin.keyring --auth_supported cephx df
Total time run: 300.015640
Total writes made: 614977
Write size: 4096
Object size: 4096
Bandwidth (MB/sec): 8.0071
Stddev Bandwidth: 3.35268
Max bandwidth (MB/sec): 11.9766
Min bandwidth (MB/sec): 0.03125
Average IOPS: 2049
Stddev IOPS: 858
Max IOPS: 3066
Min IOPS: 8
Average Latency(s): 0.0156087
Stddev Latency(s): 0.0442384
Max latency(s): 1.51347
Min latency(s): 0.00396259
14 Mar 2017
I’ve wrote before the small post on how to find and substitute the string in all files with sed
command in GNU/Linux.
Now I’d like to show the real use case.
You’ve bought a new SSL certificate and configured your web server.
After you fire it, you can make an unfortunate discover when you open the browser
on your brand new https://example.com
, that it says “Some parts of this page are not secure”.
So what is insecure? Simply you may have used the insecure contents
like images or external JS libraries loaded from CDN.
To help with this, Linux has a small and powerful command to find and substitute the old_phrase
with the new_phrase
in
all files and directories recursively - it is sed
command on GNU/Linux
find . -type f -print0 | xargs -0 sed -i 's/old_phrase/new_phrase/g'
Attention! The previous command finds files also in the hidden folders and if you’re working with Subversion or GIT you’d like to skip them. The following keys -not -path '*/\.*'
makes the trick
find . -not -path '*/\.*' -type f -print0 | xargs -0 sed -i 's/http:\/\//https:\/\//g'
After this command your links like
<img src="https://example.com/dot.png">
will be converted to
<img src="https://example.com/dot.png">
Happy coding!
24 May 2016
Small and powerful command to find and substitute the old_phrase
with the new_phrase
in
all files and directories recursively with sed
command on GNU/Linux
find . -type f -print0 | xargs -0 sed -i 's/old_phrase/new_phrase/g'
Attention! The previous command finds files also in the hidden folders and if you’re working with Subversion or GIT you’d like to skip them. The following keys -not -path '*/\.*'
makes the trick
find . -not -path '*/\.*' -type f -print0 | xargs -0 sed -i 's/old_phrase/new_phrase/g'
For MacOS users the command would be, note the sed -i ''
find . -not -path '*/\.*' -type f -print0 | xargs -0 sed -i '' 's/old_phrase/new_phrase/g'
Note. MacOS ships the BSD sed. In GNU/Linux you run the GNU sed
. More around it https://stackoverflow.com/questions/7573368/in-place-edits-with-sed-on-os-x.
And checkout a beautiful visual explanation of shell commands.
01 May 2016
When you’re developing the Django app based on the legacy Oracle database you’ll find this type of model
from django.db import models
class Product(models.Model):
type_product = models.CharField(max_length=3)
code_product = models.CharField(max_length=15)
price = models.DecimalField(max_digits=8, decimal_places=2)
class Meta:
unique_together = (('type_product', 'code_product'),)
where the primary key is made by the tuple ('type_product', 'code_product')
.
The field code_product
usually is filled by some characters and the rest is padded with spaces
to respect the Oracle’s CHAR(15)
type. You may wish to trim those spaces in your REST web-service, but still
wish to filter lists and to join on foreign keys.
Here is my hack of this problem, the CharFieldPadding
class register the new character field in Django that
call handy ljust
function to pad the string with spaces and respect the max_length
parameter.
from django.db import models
class CharFieldPadding(models.CharField):
def __init__(self, max_length, *args, **kwargs):
kwargs['max_length'] = max_length
super(CharFieldPadding, self).__init__(*args, **kwargs)
def get_prep_value(self, value):
return value.ljust(self.max_length, ' ')
class Product(models.Model):
type_product = models.CharField(max_length=3)
code_product = CharFieldPadding(max_length=15)
price = models.DecimalField(max_digits=8, decimal_places=2)
class Meta:
unique_together = (('type_product', 'code_product'),)
Everything works smoothly in Django Rest Framework and you have nice looking URLs.
Happy coding!
08 Dec 2015
When you install git
on your computer, you may find new variables available in the environment, it is $(__git_ps1)
.
This variable contains the branch name of the current repository. The only thing you need to edit ~/.bashrc
and add $(__git_ps1)
to the PS1
definition in this way
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1)\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1)\$ '
fi
N.B. the $(__git_ps1)
is available by default for Ubuntu >= 14.04, you may check if it works by just going to any git
repository and run echo $(__git_ps1)
~/Work/moiseevigor.github.io $ echo $(__git_ps1);
(master)
If you see an empty string, so just source it from /etc/bash_completion.d/git
, and in this case the ~/.bashrc
will look like
source /etc/bash_completion.d/git
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1)\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1)\$ '
fi
This is it, now you have a gorgeous prompt
:~/moiseevigor.github.io (master)$
Have a nice branching!