centos 69 – install wkhtmltopdf

# get source with wget
wget https://bitbucket.org/wkhtmltopdf/wkhtmltopdf/downloads/wkhtmltox-0.13.0-alpha-7b36694_linux-centos6-amd64.rpm
# install with yum to get dependecy
yum install wkhtmltox-0.13.0-alpha-7b36694_linux-centos6-amd64.rpm -y

# if error need xvfb
yum search xvfb
yum install xorg-x11-server-Xvfb
echo "export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb" >> /etc/profile
source /etc/profile
xvfb-run wkhtmltopdf https://g3n1k.wordpress.com g3n1k.pdf

# if the fonts become reactangle
# copy all your font to /usr/share/fonts
ls /usr/share/fonts/
fc-cache
yum install -y ghostscript
Advertisements

mysql – master to master replication

https://www.digitalocean.com/community/tutorials/how-to-set-up-mysql-master-master-replication

“MySQL replication is the process by which a single data set, stored in a MySQL database, will be live-copied to a second server. This configuration, called “master-slave” replication, is a typical setup. Our setup will be better than that, because master-master replication allows data to be copied from either server to the other one. This subtle but important difference allows us to perform mysql read or writes from either server. This configuration adds redundancy and increases efficiency when dealing with accessing the data.”

mysql01: 192.168.2.36

$ echo "192.168.2.36	mysql01" >> /etc/hosts
$ echo "192.168.2.37	mysql02" >> /etc/hosts
$ sudo apt-get install mysql-server mysql-client -y
$ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

#bind-address = mysql01
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
binlog_do_db = example
#binlog_ignore_db = include_database_name

$ mysql -u root -p

mysql> create user 'replicator'@'%' identified by 'password';
Query OK, 0 rows affected (0.01 sec)

mysql> grant replication slave on *.* to 'replicator'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 |      154 | example      |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

# get the log file and log post in server2

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host='mysql02', master_user='replicator', master_password='password', master_log_file='mysql-bin.000003',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql02: 192.168.2.37

$ echo "192.168.2.36	mysql01" >> /etc/hosts
$ echo "192.168.2.37	mysql02" >> /etc/hosts
$ sudo apt-get install mysql-server mysql-client -y
$ sudo nano /etc/mysql/mysql.conf.d/mysql02.cnf

bind-address = mysql02
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
binlog_do_db = example
#binlog_ignore_db = include_database_name

$ sudo service mysql restart

mysql> create user 'replicator'@'%' identified by 'password'; 
Query OK, 0 rows affected (0.01 sec)

mysql> grant replication slave on *.* to 'replicator'@'%'; 
Query OK, 0 rows affected (0.00 sec)

mysql> create database example; 
Query OK, 1 row affected (0.01 sec)

mysql> change master to master_host = "192.168.0.104", master_user = "replicator", master_password = "password", master_log_file = "mysql-bin.000001", master_log_pos = 607;
Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host='mysql01', master_user='replicator', master_password='password', master_log_file='mysql-bin.000003',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 |      154 | example      |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host='mysql01', master_user='replicator', master_password='password', master_log_file='mysql-bin.000003',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

Doing test write from mysql01

mysql > use example;

mysql> create table example.testuser(id int, name varchar(20));

mysql > INSERT INTO `testuser` (`id`, `name`) VALUES (1, 'indra sadik');

mysql > INSERT INTO `testuser` (`id`, `name`) VALUES (2, 'indradhi');

mysql > select * from `testuser`;

mysql> select * from example.testuser;
+------+-------------+
| id   | name        |
+------+-------------+
|    1 | indra sadik |
|    2 | indradhi    |
+------+-------------+
2 rows in set (0.00 sec)

mysql>

Doing test write from mysql02

mysql > use example;

mysql> select * from example.testuser;
+------+-------------+
| id   | name        |
+------+-------------+
|    1 | indra sadik |
|    2 | indradhi    |
+------+-------------+
2 rows in set (0.00 sec)

mysql > INSERT INTO `testuser` (`id`, `name`) VALUES (3, 'denly');

mysql> select * from example.testuser;
+------+-------------+
| id   | name        |
+------+-------------+
|    1 | indra sadik |
|    2 | indradhi    |
|    3 | denly       |
+------+-------------+
3 rows in set (0.00 sec)

Doing test read from mysql01

mysql> select * from example.testuser;
+------+-------------+
| id   | name        |
+------+-------------+
|    1 | indra sadik |
|    2 | indradhi    |
|    3 | denly       |
+------+-------------+
3 rows in set (0.00 sec)

postgresql – pointing postgresql data to new location

Database grow over time, it out growing the space on their partition located.
in redhat 6.7, the default partition for “/” its 50GB and the rest going to “/home” partition.
when you default install postgresql-9.5 it would located in “/opt” which include in “/” partition.
for database production 50GB it’s so small. so i want change the data folder to “/home” which have TB space.

#status postgres
$ /etc/init.d/postgresql-9.5 status
pg_ctl: server is running (PID: 6309)
/opt/PostgreSQL/9.5/bin/postgres "-D" "/opt/PostgreSQL/9.5/data"

# stop postgres
$ service postgresql-9.5 stop
$ /etc/init.d/postgresql-9.5 status
pg_ctl: no server running

# change variable
$ nano /opt/PostgreSQL/9.5/pg_env.sh

export PGDATA=/opt/PostgreSQL/9.5/data
change to
export PGDATA=/home/pg_data

# create dir
$ mkdir -p /home/pg_data

# doing rsync
$ rsync -azP /opt/PostgreSQL/9.5/data/ /home/pg_data/

# just make sure
$ mv /opt/PostgreSQL/9.5/data /opt/PostgreSQL/9.5/data_bak

# backup service script
$ mkdir -p ~/backup/ && mv /etc/rc.d/init.d/postgresql-9.5 ~/backup/

# download postgresql-9.5 file
$ wget https://raw.githubusercontent.com/g3n1k/exsys/master/postgresql-9.5

# move postgresql-9.5 to /etc/rc.d/init.d/
$ mv postgresql-9.5 /etc/rc.d/init.d/

# start postgresql
$ service postgresql-9.5 start

# status postgresql
$ service postgresql-9.5 status
pg_ctl: server is running (PID: 13282)
/opt/PostgreSQL/9.5/bin/postgres "-D" "/home/pg_data"

node.js – express_generator from jade to pug

when using express generator default will using jade as template generator, the problem is jade is renamed with pug. when it running will out warn deprecated message

npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, ...

this how I set up express, express_generator and using it to generate folder for project

# install express and express_generator
$ npm install -g express
$ npm install -g express_generator

# set using express to generate our project
$ mkdir -p ~/projects && cd ~/projects
$ express web_rest && cd web_rest

# open package.json file
$ nano package.json
# change jade to pug (line 14)
# "jade": "1.11.0",
# to
# "pug": "^2.0.0-rc.2",

# open app.js
$ nano app.js
# change view engine to pug (line 15)
# app.set('view engine', 'jade');
# to 
# app.set('view engine', 'pug');

# rename all jade extention to pug in views folder
$ cd views
$ mv error.jade error.pug
$ mv index.jade index.pug
$ mv layput.jade layout.pug

# back to main dir
$ cd ..

# install node_module
$ npm install
# install start, start will using to for running the server
# check file package.json for script
$ npm install -g start

# start the project
$ npm start

# test with curl
$ curl http://localhost:3000

 

sshfs mount remote folder linux and samba shared windows

using sshfs to mount another space linux and shared it to other windows os with samba

background problem
==================
we have big storage computer with linux debian os, lets say 192.168.0.77
and we have another ubuntu linux for manage service like ftp, samba etc, let say 192.168.0.81
the other computer have windows os, which will need the share storage

solution
==================

using sshfs for mounting storage from 192.168.1.77,
and using samba for shared it from 192.168.1.81

+- – -+                     +- – -+
| 77|                    | 81|                       +- – -+ +- – -+
|      |— sshfs —|      |— samba —| win win|
|      |                    |      |                       |  7   8  10 |
+- – -+                     +- – -+                       +- – -+ +- – -+
/mnt/backup        /home/user/backup    \\192.168.1.81\u2backup

how to

# user@ubuntu81:
# ==============
# create keygen for less password

ssh-keygen -t rsa

# root@debian77:
# ==============
# create new user ub for access folder for shared

useradd ub
passwd ub
su ub
mkdir ~/.ssh && cd ~/.ssh
scp user@ubuntu81:/home/user/.ssh/id_rsa.pub .
mv id_rsa.pub authorized_keys
exit

# create folder to shared
mkdir /mnt/backup
chown ub.ub /mnt/backup

# user@ubuntu81:
# ==============

# install sshfs
sudo apt-get install sshfs
sudo modprobe fuse
sudo adduser $USER fuse
sudo chown root:fuse /dev/fuse

# enable non root for mounting sshfs
sudo nano /etc/fuse.conf
# change
#user_allow_other
# to
user_allow_other
# save

# create folder to mount
mkdir ~/backup

# mounting remote folder
sshfs ub@debian77:/mnt/backup /home/user/backup -o allow_other

# check with write file and folder 
mkdir test-dir && touch test-file
ls -al

# do ls -al in root@debian77:/mnt/backup

# install samba
sudo apt-get install samba -y

# set password user for samba,
# you can set diferent password to login shell linux
sudo pdbedit -a user

# add new share in samba config
sudo nano /etc/samba/smb.conf
# add lines
[u2backup]
path = /home/user/backup
available = yes
valid users = user
read only = no
browseable = yes
public = yes
writable = yes

#save and restart samba
sudo /etc/init.d/samba restart

# now check from windows computer
# open explorer and type \\192.168.0.81\u2backup
# input user name and password samba
# and add some test file

sshfs-samba

linux – mount ssh remote directory

# install module
sudo apt-get install sshfs

# load into kernel
sudo modprobe fuse

# setting permission
sudo adduser $USER fuse
sudo chown root:fuse /dev/fuse

# create folder
mkdir ~/remoteDir

# mount remote folder with command
sshfs user@remote.ip.add.res:/home/user/mountedRemote ~/remoteDir

# now test
cd ~/remoteDir
ls -l

http://askubuntu.com/questions/412477/mount-remote-directory-using-ssh