[email protected]

learn – code – share

How to setup SVN in Synology NAS drive

Apr
10

1) To access a terminal server from Synology, you’ll need to have either SSH or Telnet running. If you haven’t done this already, go to the control panel and click the “Terminal” icon. Check Enable SSH service.

2) Go to your old repository and run:
svnadmin dump /path/to/repository > repository-name.dmp
(repository-name should be replaced with whatever you called your repository)
For example:
svnadmin dump C:\Repositories\source > source.dmp

3) The previous step will create a .dmp file. Copy it to your NAS (for example, I copied it to \\155.148.0.54\Shared ).

2) Use putty, Bitvise SSH client, etc. and connect to your NAS on port 22. Log in using “root” and the same password that you use when loggin into the page at http://155.148.0.54:5000/webman/index.cgi . It is important to login as root and not admin so that the proper owner of the database is setup.

3) Now that you’re logged in via SSH type:
cd volume1/svn
svnadmin create repository-name
svnadmin load repository-name< repository-name.dmp

It should start importing the dump, which will take a long time so go get some coffee.

4) Now if you do an ls -la you’ll see a new folder with the name of your repository. The config files are in that folder! At this point I thought I was done – I could checkout and view files, but the problem is that I couldn’t commit – I still didn’t have write permissions! You can at least verify at this point that your database dump was successfully loaded by opening up the SVN app in the web GUI (the svn packaged app on your Synology NAS)

5) You will need to edit the config file. Busybox has vi and some type of elvis editor I never heard of. I used VI. If you’ve forgotten most of the commands for VI, just google VI commands and use the cheat-sheet. Type:
vi repository-name/conf/svnserve.conf

6) Uncomment these lines:
auth-access = write
password-db = passwd
At the bottom I found the following:
anon-access=none
(If it’s not at the bottom of your file, uncomment it above)

7) Save the file. You may have to restart svn – I’m not sure. I just rebooted the whole NAS to be safe.



How to install config SVN in centos

Feb
19

Using Subversion

yum install -y subversion

yum install -y mod_dav_svn

mkdir /data/svn

svnadmin create /data/svn/repo1

chown -R apache:apache /data/svn/repo1

cd /data/svn/repo1/conf/

vi svnserve.conf

htpasswd -c /data/svn/repo1/conf/passwd jay

vi authz

[repo1:/]
farid = r
fikri = rw
* = #not access

 

vi /etc/httpd/conf/httpd.conf

 

[.....]
Include conf.d/*.conf
[.....]

cd /etc/httpd/conf.d/

vi subversion.conf

LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

<Location /repo1>
DAV svn
SVNPath /data/svn/repo1
Authtype Basic
AuthName "My Repository"
AuthzSVNAccessFile /data/svn/repo1/conf/authz
AuthUserFile /data/svn/repo1/conf/passwd
Require valid-user
</Location>
service httpd restart

 



If and If else Shorthand conditions in PHP

Dec
31

Basic True / False Declaration

$is_admin = ($user['permissions'] == 'admin') ? true : false;

Conditional Welcome Message

echo 'Welcome '.($user['is_logged_in'] ? $user['first_name'] : 'Guest').'!';

Conditional Items Message

echo 'Your cart contains '.$num_items.' item'.($num_items != 1 ? 's' : '').'.';

Conditional Error Reporting Level

error_reporting($WEBSITE_IS_LIVE ? 0 : E_STRICT);

Conditional Basepath

echo ”;

Nested PHP Shorthand

echo 'Your score is: '.($score > 10 ? ($age > 10 ? 'Average' : 'Exceptional') : ($age > 10 ? 'Horrible' : 'Average') );

Leap Year Check

$is_leap_year = ((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));

Conditional PHP Redirect

header('Location: '.($valid_login ? '/members/index.php' : 'login.php?errors=1')); exit();

 

source: https://davidwalsh.name/php-ternary-examples



Install free SSL Certificates

Dec
11

Installing SSL over Shell Access

we use Certbot ACME client to automate certificate issuance and installation with no downtime.

In Certbot choose the OS you are using and you will see Installation instrustions

or

 wget https://dl.eff.org/certbot-auto

when the package is downloaded type this command as a root or use sudo

Note: you need to enable port 443 to install SSL – check how to enable ports in centos

./certbot-auto

it will ask your email address and show you all the list of domains in your Virtural host, select the domain by number and it will install the certificate in your sites-available directory or in /etc/letsencrypt folder.

To config the SSL certificates manually if it is not done.

open ssl-conf file which is in /etc/http/conf.d/ – in centos

and find this section

and enable or type as below

SSLEngine on 
SSLCertificateFile /etc/letsencrypt/live/domainname.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domainname.com/privkey.pem

 Note: replace domainame.com with your domainame, you will find this cert.pem & privkey.pem in letsencrypt in live folder

save the file and restart your apache server.

open the browser and type your website with https://domainname.com

you have succesfully installted ssl now its time to renew your certificate every three months.
just add a cronjob to renew automatically every three months

run

./certbot-auto renew --dry-run

this will do test and show you results that every this command will work.

and add this command in crontab to run every three months

./certbot-auto renew

make sure the path of your certbot-auto is correct.



Mysql replication – Master to Master

Dec
11

Master1 server configuration:

we are going to setup master to master replication, for instance we are using master1 and master2 servers.

open my.cnf location in etc/

and add this lines

[mysqld]
server-id=1
log-bin=mysql-bin

now restart mysql server

and dump the databases which one you want to replicate and copy to slave server

to dump all databases use

shell> mysqldump --all-databases > dump.sql

to dump only specified databases use

shell> mysqldump --databases db1 db2 db3 > dump.sql

once done we now create a user and grant permissions to replicate the db.

connect to mysql

and grant the access using.

mysql> grant replication slave on *.* to 'master2username'@'180.xxx.xxx.xxx' identified by 'master2password';

once its done, to see the master status type

mysql> show master status;


+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 |      120 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

you will see the output like this save this file and position id for next steps.

now flush the tables and set the lock to read;

mysql > flush tables with read lock;

[incase if you want to unlock use this command ] mysql > unlock tables;

mysql > change master to master_host = '170.xxx.xxx.xxx',    #this is your master2 host ip
master_user='master2username',
master_password='master2_password',  
master_log_file='mysql-bin.000002',   
master_log_pos=606; # this is the position we get when we did master2 status

 

Master2 configuration:

open my.cnf located in /etc/

and add this line

[mysqld] 
server-id=2
log-bin=mysql-bin

save this file and restart your mysql server

and grant the master user to access master1 db

mysql> grant replication slave on *.* to 'master1username'@'180.xxx.xxx.xxx' identified by 'master1password';

once its done, to see the master status type

mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000002 |      606 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

and restart mysql server, once its restarted login to mysql and change the master using this query.

mysql > change master to
master_host = '170.xxx.xxx.xxx',    #this is your master1 host ip
master_user='master1username',   
master_password='master1_password', 
master_log_file='mysql-bin.000002',  # this the file we get when we did master status 
master_log_pos=120; # this is the position we get when we did master status

now all set, dump the databases we copied in master1 to master2, using mysqldump

shell> mysqldump test.sql < testdb
mysql> show processlist;

mysql> show slave status\G;

to see status of the db replication.

 

 

 



Mysql db replication process – Master to Slave

Dec
11

Master to Slave Replication:

Master server configuration:

open my.cnf location in etc/

and add this lines

[mysqld]
server-id=1
log-bin=mysql-bin

now restart mysql server

and dump the databases which one you want to replicate and copy to slave server

to dump all databases use

shell> mysqldump --all-databases > dump.sql

to dump only specified databases use

shell> mysqldump --databases db1 db2 db3 > dump.sql

once done we now create a user and grant permissions to replicate the db.

connect to mysql

and grant the access using.

mysql> grant replication slave on *.* to 'slaveusername'@'180.xxx.xxx.xxx' identified by 'slaveuserpassword';

once its done, to see the master status type

mysql> show master status;


+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000001 |      120 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

you will see the output like this save this file and position id for next steps.

now flush the tables and set the lock to read;

mysql > flush tables with read lock;

[incase if you want to unlock use this command ]

mysql > unlock tables;

 

Now, Slave configuration:

open my.cnf located in /etc/

and add this line

serverid = 2 

#this id needs to be higher than what we setup in master.

replicate-wild-do-table=mytestdb.%

# this line will replicate database mytestdb and all its tables.

save this file and restart your mysql server

once its restarted login to mysql and change the master using this query.

mysql > change master to

master_host = '170.xxx.xxx.xxx',    #this is your master host ip

master_user='slaveusername',  #this is the slave username we used in master

master_password='slaveusername_password', 

master_log_file='mysql-bin.000001',  # this the file we get when we did master status 

master_log_pos=120; # this is the position we get when we did master status

now all set, dump the databases we copied in master to slave, using mysqldump

shell> mysqldump test.sql < testdb

now start the slave

mysql > start slave;

all done, try changing some records in master and you will see immeditely changes in slave database.

 

 

 

 



Using rsync to backup files from one server to other

Dec
08

Rsync is command mostly used in linux to backup files to backup server or if you want files to be copies to another server.

Create a key using

ssh-keygen
copy the key from main server to backup server.
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 400 [email protected]

once its copies try login into back machine.

ssh -p '400' '[email protected]'

now you can login without entering the password, if all working then you can test rsync commandtry this command to copy files from main server to test server.

rsync -arvz -e "ssh -p 400 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /var/www/html/myfiles/* [email protected]:/home/username/backup/*

In the above setup we are doing rsync using some options and custom port 400 to the backup folder in home directory in backup server.

to run this rsync add it to crontab to run the time whenever you want..

 

 



How to install Mysql secure server on Centos 7

Dec
07

Download mysql rpm from mysql website.

https://dev.mysql.com/downloads/repo/yum/

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

and compare the md5 sum

md5sum mysql57-community-release-el7-9.noarch.rpm
Output
1a29601dc380ef2c7bc25e2a0e25d31e  mysql57-community-release-el7-9.noarch.rpm

which should match the rpm you downloaded from mysql website.

Now install the package

sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm
sudo yum install mysql-server

once all installed restart the mysql server

sudo systemctl start mysqld

check mysql status

sudo systemctl status mysqld

if it is active and running then all good.

get the temporary password created which mysql installed using.

sudo grep 'temporary password' /var/log/mysqld.log

copy the password and put a side to use in next package installation.

Now its time to install mysql secure server.

sudo mysql_secure_installation

this will ask you root password, enter the temporary password we copied before and press enter

read all the statements and proceed installation and set the new password for mysql, once all done connect to mysql

mysql -u root -p

and enter the new we set in the mysql secure installation.

any issues comment below…

 



Create sftp user in linux

Dec
05

How to create sftp users in linux.

1) open ssh_config in /etc/ssh/
find and comment this line by adding #
#Subsystem      sftp    /usr/libexec/openssh/sftp-server
and add this line.
Subsystem sftp internal-sftp

2) and add this lines at the end of the file.

Match Group sftponly
ChrootDirectory %h
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no

and save this file and restart the sshd.

3) Create the user and assign to the directory you want to access from sftp.

create a user geekuser and assign to folder geekatlab in /var/www/html
useradd -d /var/www/html/geekatlab -s /bin/false -G sftponly geekuser
and set the password for user geekuser
passwd geekuser
create a directory folder in geekatlab
mkdir /var/www/html/geekatlab/folder
set the root access to this folder geekatlab
chown root /var/www/html/geekatlab
and change permission to this folder geekatlab
chmod 755 /var/www/html/geekatlab
set the user geekuser to access this folder 'folder'
chown ansargeek /var/www/html/geekatlab/folder
change the permisson to this folder 'folder' to read and write
chmod 755 /var/www/html/geekatlab/folder

all done now, try accessing this folder from any sftp client using user geekuser.

any issues comment below…