Change timezone on centos

Posted on Updated on

[root@sv-85185 mysql]# date
Thu Dec 7 01:34:57 EST 2017
[root@sv-85185 mysql]# date -u
Thu Dec 7 06:35:13 UTC 2017
[root@sv-85185 mysql]# ls /usr/share/zoneinfo/
Africa Brazil Egypt GB-Eire HST Japan MST7MDT posix Singapore WET
America Canada Eire GMT Iceland Kwajalein Navajo posixrules Turkey W-SU
Antarctica CET EST GMT0 Indian leapseconds NZ PRC tzdata.zi zone1970.tab
Arctic Chile EST5EDT GMT-0 Iran Libya NZ-CHAT PST8PDT UCT zone.tab
Asia CST6CDT Etc GMT+0 iso3166.tab MET Pacific right Universal Zulu
Atlantic Cuba Europe Greenwich Israel Mexico Poland ROC US
Australia EET GB Hongkong Jamaica MST Portugal ROK UTC
[root@sv-85185 mysql]# unlink /etc/localtime
[root@sv-85185 mysql]# ln -s /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
[root@sv-85185 mysql]# date
Thu Dec 7 13:37:26 +07 2017
[root@sv-85185 mysql]#


Install MySQL, Nginx, Tomcat7 on centos 6.8

Posted on Updated on

Before installing:
yum update


Install MySQL

  1. Installing MySQL and tell it which runlevels to start on:
    yum install mysql-server
    /sbin/chkconfig --levels 235 mysqld on
  2. Start the MySQL:
    service mysqld start
    MySQL will bind to localhost ( by default
  3. Harden MySQL Server
    Run the mysql_secure_installation script to address several security concerns in a default MySQL installation

Mysql Root Login:

mysql -u root -p
then type your root password

Create new user and database

create new database with name newDB, new user with name newUser and newPassword is newUser‘s password:
create database newDB;
create user 'newUser'@'localhost' identified by 'newPassword';
grant all on newDB.* to 'newUser' identified by 'newPassword';

and exit root mysql to login as newUser:

mysql -u newUser -p

and type newUser’s password and if it show mysql>, you have succeed

Reset the MySQL Root Password

If you forget your root MySQL password, it can be flushed and then reset.

  1. Stop the current MySQL server instance, then restart it with an option to not ask for a password.

    sudo /etc/init.d/mysqld stop
    sudo mysqld_safe --skip-grant-tables &
  2. Reconnect to the MySQL server with the MySQL root account.
    mysql -u root
  3. Use the following commands to reset root’s password. Replace password with a strong password.

    use mysql;
    update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
    flush privileges;
  4. Then restart MySQL.

    service mysqld restart

You’ll now be able to log in again using mysql -u root -p.

Dump and restore backup

$ mysqldump –opt -u [uname] -p[pass] [dbname] > [backupfile.sql]

$ mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]

Tomcat 7

Check java version:
java -version

If you have not installed JDK, install java 8 on centos 6.8
Download Tomcat7 

at Official download page

wget http://mirror.downloadvn.com/apache/tomcat/tomcat-7/v7.0.79/bin/apache-tomcat-7.0.79.tar.gz
tar xzf apache-tomcat-7.0.79.tar.gz
mv apache-tomcat-7.0.79 /var/lib/tomcat7

Starting Tomcat7

cd /var/lib/tomcat7
sh ./bin/startup.sh

Sample output:

[root@server1 tomcat7]# sh ./bin/startup.sh
Using CATALINA_BASE: /var/lib/tomcat7
Using CATALINA_HOME: /var/lib/tomcat7
Using CATALINA_TMPDIR: /var/lib/tomcat7/temp
Using JRE_HOME: /opt/jdk1.8.0_131/jre
Using CLASSPATH: /var/lib/tomcat7/bin/bootstrap.jar:/var/lib/tomcat7/bin/tomcat-juli.jar
Tomcat started.

Access Tomcat on browser:

Tomcat server works on port 8080 default. To access Tomcat on the web browser by connecting your server on port 8080:


Setup Users Account

Finally we need to create user accounts to secure and access admin/manager pages. Edit conf/tomcat-users.xml file in your editor and paste inside tags.

Stop Tomcat

Finally, if you feel that there are no need of Tomcat in your system, You can simply stop it using below command from tomcat home directory.
sh ./bin/shutdown.sh


Install Nginx:

yum install epel-release
yum install nginx

Starting Nginx
/etc/init.d/nginx start
Configuring Nginx and Tomcat7

server {
listen 80;
server_name aliviet.vn;
root /var/lib/tomcat7/webapps/aliviet.vn;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

source :

Install Java 8 on Centos 6.8

Posted on


Download Java SDK 8

You need to add option --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" to download

example with linux-64

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz"
tar xzf jdk-8u131-linux-x64.tar.gz
mv jdk1.8.0_131 /opt/

Install Java with Alternatives

After extracting archive file use alternatives command to install it. alternatives command is available in chkconfig package.

cd /opt/jdk1.8.0_131/
alternatives --install /usr/bin/java java /opt/jdk1.8.0_131/bin/java 2
alternatives --config java
There is 1 program that provides 'java'.

Selection Command
*+ 1 /opt/jdk1.8.0_131/bin/java

Enter to keep the current selection[+], or type selection number: 1

At this point JAVA 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives

alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_131/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_131/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_131/bin/jar
alternatives --set javac /opt/jdk1.8.0_131/bin/javac

Check Installed Java version

[root@server1 jdk1.8.0_131]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Configuring Enviroment Variables:

  • Setup JAVA_HOME: 
    export JAVA_HOME=/opt/jdk1.8.0_131
  • Setup JRE_HOME: 
    export JRE_HOME=/opt/jdk1.8.0_131/jre
  • Setup PATH: 
    export PATH=$PATH:/opt/jdk1.8.0_131/bin:/opt/jdk1.8.0_131/jre/bin

Also put all above environment variables in /etc/environment file for auto loading on system boot

source: https://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/