Monday, December 26, 2016

mysql short commands

login to mysql as root with password
mysql -u root -p
list users
SELECT User FROM mysql.user;

nohup to Import osm planet into postgres

To keep the process running after closing the ssh connection, specially when using that in a very long process, Using this command the program will run in background and you can close your terminal, also it will not log anything to disk
must be from osm account
  
nohup osm2pgsql --slim -d gis -C 16000 --hstore -S openstreetmap-carto-2.45.1/openstreetmap-carto.style planet-latest.osm.pbf > /dev/null 2>&1&

If you prefer to save nodes to file :
  
nohup osm2pgsql --slim -d gis -C 16000 --hstore --flat-nodes ~/flat_nodes/flatnodes -S openstreetmap-carto-2.45.1/openstreetmap-carto.style planet-latest.osm.pbf > /dev/null 2>&1&

Thursday, December 22, 2016

Prepare Ubuntu FireWall

Prepare Ubuntu FireWall


if you want a good reference that will take you in step by step way check this link


 
    sudo apt-get update

    sudo apt-get install iptables-persistent



Keep established connections allowed

    iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT



Accept all packets destined to port 22 or 80


    iptables -A INPUT -p tcp --dport 22 -j ACCEPT

    iptables -A INPUT -p tcp --dport 80 -j ACCEPT




Accept all loopback communications and put the first rule

    sudo iptables -I INPUT 1 -i lo -j ACCEPT

 

  Let Mysql Server accept connections from private network

    iptables -A INPUT -p tcp --dport 3306 -s 192.168.0.0/24 -j ACCEPT    



Drop any other Packets not matching our rules.

    iptables -A INPUT -j DROP

OR for better resoaning
    iptables -A INPUT -j REJECT

check this Drop vs Reject
Note : the last rule must be the last rule to be added.

If you ever update your firewall and want to preserve the changes, you must save your iptables rules for them to be persistent.

Save your firewall rules with this command:

    sudo service netfilter-persistent save

sudo iptables -I INPUT 1 -i lo -j ACCEPT

insert this rule on the first row to accept ll packets coming from interface lo
to list line numbers in iptables use this command
sudo iptables -L --line-numbers

to insert the new rul on specific line do the following
sudo iptables -I INPUT 4 new_rule_here

To delete rule by line Number
sudo iptables -D INPUT 3

To export firewall rules use :
sudo iptables-save > iptables-export

To accept on a range of ports :
sudo iptables -A INPUT -p tcp --match multiport --dports 1024:3000 -j ACCEPT

To import firewall rules use :
sudo iptables-restore < iptables-export 

To Block all connections on port 111, prefer to the end of the list
 iptables -I INPUT -p udp  --dport 111 -j REJECT 

To allow all communication on the private network on interface ens19
iptables -A INPUT -i ens19 -s 192.168.100.0/24 -j ACCEPT

So, the minimum required rules in nutshell

 sudo iptables -I INPUT 1 -i lo -j ACCEPT
 sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
 sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
 sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
 sudo iptables -A INPUT -i ens19 -s 192.168.100.0/24 -j ACCEPT
 sudo  iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
 sudo iptables -A INPUT -j REJECT

Tuesday, December 13, 2016

mount exist hard disk in debian

check if the drive is exist or not :
fdisk -l
if the disk is there
check if the partition is mounted or not
df -h
if the disk exist and not partitioned yet , then you have to do so using :

fdisk /dev/sdb1

mkdir /newstorage
chmod 755 /newstorage

mkfs.ext4 /dev/sdb1

mount /dev/sdb1  /newstorage 

Add this line to /etc/fstab
/dev/sdb1  /newstorage ext4 defaults 0 10
 
mount /newstorage 
 OR
mount -t ext4 /dev/sda1 /newstorage


Friday, October 7, 2016

Using Winscp as Sudo User to edit files remotely - Ubuntu 16.04

On the new version of Ubuntu Server 16.04 , you cannot have a root user account but you can create a user account with root privileges only when strat your command with sudo, And that made it very difficult for people who are using Winscp as their daily tool to interact with a headless server to edit files and save them , you will get an error  message  saying "Permission Denied".

After Searching google for a suitable solution for this problem, I didn't find anything related directly to Ubuntu 16.04.
The direct dirty trick is to give the ubuntu user the full  root privileges by editing sudoers file "/etc/sudoers", then add the following line at the end of the file :

username ALL=NOPASSWD: ALL

Change username by the account name you are using to login to the system through Winscp.
On the client side choose advanced and sftp and insert the location of sftp server
sudo /usr/lib/openssh/sftp-server in case of ubuntu 16.04


Reference credits goes to chilcano

Wednesday, May 11, 2016

Cannot load modules/mod_ssl.so into server: The operating system cannot run The Apache service named. .

in Windows, If you have Event 3299 error in the event viewer::
The Apache service named  reported the following error:
>>> httpd.exe: Syntax error on line 167 
Cannot load modules/mod_ssl.so into server: The operating system cannot run The Apache service named.

Then check the VC compatibility , I had this error when I tried to run Apache 2.4.20  VC14 ( C++ Redistributable Visual Studio), with php 5.6 which compiled using VC11, which is not compatible, So to solve this issue there are two methods:
The first is upgrade PHP by downloading the  PHP version compiled with VC14, Or to downgrade Apache server and download the VC11 version.
Apache Versions can be downloaded from http://www.apachelounge.com.
Php versions can be downloaded from http://windows.php.net/download/

Tuesday, April 26, 2016

opengts Error reading Account - "Install the JDBC jar file in one of the "

After Finishing installation process on Ubuntu for Opengts 2.6.1 , I cannot login to the syatem and the message "Error reading Account" keep showing every time , to solve this problem you cannot find a lot of solutions on google . unless you have a long time to search inside blogs and forums for any hint.

there is a file in tmp/log folder called "TrackWar.log", this is the place you start search in , and looking for messages . I found the error messages in my case caused by missing to install JDBC jar file into Tomcat folder.

So, the solution is to copy this file to tomcat bin folder:

sudo cp mysql-connector-java-5.1.38-bin.jar $CATALINA_HOME/lib 

Friday, April 22, 2016

Traccar not working after install on ubuntu

always  I did this mistake and go back to google asking for a solution for this problem , the main issue is that java jre is not installed , so execute the following command:

sudo apt-get install default-jre
 
Then start traccar.

Wednesday, April 20, 2016

Traccar windows service start then stop ,The Traccar service terminated with service-specific error Incorrect function..

This problem happened when I changed from H2 database to mysql didn't remove the old database the had been created by an old version of traccar.
to solve it : just remove the old database of traccar and create a new one.
Another Problem is when you have a no password database , and made a space in the password place in the configuration file traccar.xml
 
<entry key='database.user'>root</entry> 
<entry key='database.password'> </entry>

to solve it: remove the space in this field and start traccar service again.
 
<entry key='database.user'>root</entry> 
<entry key='database.password'></entry>

Monday, April 4, 2016

Using Postgres pgsql database without password

For developing reason you may need to install PostgreSQL database without password , this is useful when developing locally, but you have to change it for a production server:
 this when you install your server for the first time

initdb -U postgres -A password -E utf8 -W -D POSTGRESQL_ROOT\data

Now if you want the server to conncected to without paswword then  write it like this

initdb -U postgres   -E utf8  -D POSTGRESQL_ROOT\data

That's it

Sunday, January 24, 2016

blogger blogspot "view blog" not loading

After creating a new blogger, I tryied to view the blog through clicking "view blog" from inside the  blogger dashboard or through direct navigation to url address link , but unfortunately there is no post , all I got is the settings icon in the center of the blog.
The  error was in the template , some templates is not working properly . So I changed the template then the blog showed with all posts.