Namenode enters in safe mode in unusual situations, for example when disk is full, also in the start-up phase. So to leave safemode,run below command.
bin/hadoop dfsadmin -safemode leave
After doing the above command, Run hadoop fsck so that any inconsistencies crept in the hdfs might be sorted out.
Use hdfs command instead of hadoop command for newer distributions:
hdfs dfsadmin -safemode leave
hadoop dfsadmin has been deprecated, all hdfs related tasks are being moved to a separate command hdfs