Install and configure JDK + TOMCAT + MYSQL in centos

Source: Internet
Author: User
Tags localhost mysql mysql host unix domain socket

In the company's testing environment, you need to install and configure JDK + TOMCAT + MYSQL under CENTOS6.4. Below is an installation note for backup.

I. System Environment and software packages

[Root @ localhost/] # uname-r

2.6.32-358. el6.x86 _ 64

[Root @ localhost/] # cat/etc/centos-release

CentOS release 6.4 (Final)

Software Package

Jdk-6u43-linux-x64-rpm.bin

Apache-tomcat-6.0.36.tar.gz

Mysql-5.5.23.tar.gz


Ii. installation and configuration

1. JDK

First, check whether the built-in JDK of centos is installed. Run the java-version command. If the following information is displayed:

Java version "1.6.0 ″
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)

It indicates that openjdk1.6 has been installed. This package has limited functions. You 'd better uninstall openjdk first and then install sun's jdk.

The uninstall process is simple.

# Rpm-e -- nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
# Rpm-e -- nodeps java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

Or

# Yum-y remove java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
# Yum-y remove java java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5


Install SUN's JDK

# Chmod a + x jdk-6u43-linux-x64-rpm.bin

#./Jdk-6u43-linux-x64-rpm.bin (Path in/usr/java by default)

# Java-version

Java version "1.6.0 _ 43"

Java (TM) SE Runtime Environment (build 1.6.0 _ 43-b01)

Java HotSpot (TM) 64-Bit Server VM (build pipeline 14-b01, mixed mode)


2. install TOMCAT

Put the TOMCAT package under/usr/tomcat

# Tar-zxvf apache-tomcat-6.0.36.tar.gz

# Mv apache-tomcat-6.0.36.tar.gz tomcat

After installation, set the environment variable.

# Add the following statement to vi/etc/profile:

JAVA_HOME =/usr/java/jdk1.6.0 _ 43

CLASSPATH =.: $ JAVA_HOME/jre/lib/rt. jar: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar

PATH = $ PATH: $ JAVA_HOME/bin

Export path classpath JAVA_HOME

Export CATALINA_BASE =/usr/tomcat

Export CATALINA_HOME =/usr/tomcat


# Source/etc/profile (for environment variables to take effect)

Start TOMCAT

# Cd bin

#./Startup. sh

Using CATALINA_BASE:/usr/tomcat

Using CATALINA_HOME:/usr/tomcat

Using CATALINA_TMPDIR:/usr/tomcat/temp

Using JRE_HOME:/usr/java/jdk1.6.0 _ 43

Using CLASSPATH:/usr/tomcat/bin/bootstrap. jar

[Root @ localhost bin] # netstat-an | grep: 8080

Tcp 0 0: 8080: * LISTEN


3. mysql

The new version of mysql 5.x usually requires cmake compilation and installation. Here we install mysql 5.5.23. Here we record the installation steps and procedures of CMAKE for future reference.

If a missing toolkit is found during compilation and installation, use yum install to download and install it separately and then continue.

The following installation involves several issues that need to be explained in advance:

Mysql will be installed in the/usr/local/mysql/directory

Mysql uses the utf8 character set by default.

Mysql Data and log files are stored in the/var/mysql/directory.

The mysql configuration file is saved in/etc/my. cnf


Configure and install

# Useradd mysql

# Passwd mysql

# Groupadd mysql

# Useradd-g mysql

# Mkdir-p/usr/local/mysql

# Mkdir-p/var/mysql/data

# Chown-R mysql: mysql/usr/local/mysql

# Chmod-R 755/usr/local/mysql

# Chown-R mysql: mysql/var/mysql

# Chmod-R 755/var/mysql


# Yum-y install cmake bison ncurses-devel gcc-c ++ libstdc ++

(Local YUM source or external image source can be configured)

# Tar zxvf mysql-5.5.23.tar.gz
# Cd mysql-5.5.23

# Cmake-DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_UNIX_ADDR =/tmp/mysql. sock-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-DWITH_EXTRA_CHARSETS: STRING = utf8, gbk-DWITH_MYISAM_STORAGE_ENGINE = 1-DWITH_INNOBASE_STORAGE_ENGINE = 1-DWITH_READLINE = 1-DENABLED_LOCAL_INFILE = 1-DMYSQL_DATADIR =/var/mysql/data

If an error occurs during installation

Clear cache:
Make clean
Rm CMakeCache.txt

Continue

# Make & make install


# Ln-s/usr/local/mysql/lib/libmysqlclient. so.16/usr/lib/libmysqlclient. so.16


# Cd/usr/local/mysql/support-files/


# Cp my-large.cnf/etc/my. cnf (Note: The my-large.cnf is suitable for servers around 1g memory, can be selected according to their own configuration of my-large.cnf or my-huge.cnf and other different configurations)

Then vi/etc/my. cnf

Edit the configuration file and add it in the [mysqld] section.

Datadir =/var/mysql/data # Add the MySQL database path


Go to the scripts directory and run

#./Mysql_install_db -- defaults-file =/etc/my. cnf -- basedir =/usr/local/mysql -- datadir =/var/mysql/data -- user = mysql

Installing MySQL system tables...

OK

Filling help tables...

OK

In this way, the mysql System database is generated.


Then set the MYSQL Service

Cp./support-files/mysql. server/etc/init. d/mysqld # Add Mysql to the system to start

Chmod a + x/etc/init. d/mysqld # Add execution permission

Chkconfig -- add mysqld

Chkconfig -- level 345 mysqld on

Vi/etc/init. d/mysqld # Edit

Basedir =/usr/local/mysql # MySQL installation path

Datadir =/var/mysql/data # MySQl database storage directory


[Root @ localhost data] # service mysqld start

Starting MySQL... SUCCESS!

[Root @ localhost data] # net stat-an | grep 3306

Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN


At this point, mysql installation is complete!


Add the mysql service to the system environment variable in/etc/profile, and add the following line at the end.

Export PATH = $ PATH:/usr/local/mysql/bin

The following two lines link the myslq library file to the default system location, so that you do not need to specify the mysql library file address when compiling software such as PHP.

Ln-s/usr/local/mysql/lib/mysql/usr/lib/mysql

Ln-s/usr/local/mysql/include/mysql/usr/include/mysql

Shutdown-r now # restart the system. Wait until the system is restarted and continue to perform the following operations on the terminal command line.

Mysql_secure_installation # Set the Mysql password

Press Y to enter the password twice as prompted.

Or directly change the password/usr/local/mysql/bin/mysqladmin-u root-p password "mysql" # change the password

Service mysqld restart # restart


Enter current password for root (enter for none) appears when you set a password or connect to MYSQL ):

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql. sock' (2)

You can execute this sentence to solve the problem.

[Root @ localhost data] # rm-rf/tmp/mysql. sock

After MYSQL is started, the mysql. sock file is available under/var/lib/mysql.

[Root @ localhost data] # ln-s/var/lib/mysql. sock/tmp/mysql. sock (use the absolute path)

If an error persists, use

[Root @ localhost/] # mysql-u root-p-S/var/lib/mysql. sock

Skip password verification Login

Mysql> update mysql. user set password = password ("mysql") where user = 'root ';

Mysql> flush privileges;

Mysql> quit

That is, you can.


In addition, MYSQL can only be accessed locally by default.

Create a user: testuser and authorize Remote Access

Connect to mysql as root
# Mysql-u root-p
Enter the password and mysql
Create a testuser account
Mysql> create user "testuser" identified by "test123456 ";
Grant testuser Permissions
Mysql> grantall privileges on *. * TO "testuser" @ "%" identified by "testuser password ";
Refresh permission takes effect
Mysql> FLUSHPRIVILEGES;

Mysql> quit


Iii. Summary

During MYSQL installation, you may encounter this MYSQL. SOCK problem.

In fact, this mysql. sock uses unix domain socket as a carrier of the communication protocol when the mysql host and client are on the same host.

Mysql usually has two Connection Methods:
(1) TCP/IP
(2) socket
For mysql. sock, the function is that the program is on the same machine as mysqlserver and SOCKET is available when a local connection is initiated.

You can also specify an IP address and use TCP connection instead of local SOCK.

[Root @ localhost mysql] # mysql-h 127.0.0.1-u root-p mysql

You can also log on directly.


Mysql. sock is generated with every mysql server startup. If you restart mysql after changing my. cnf, it will be generated again and the information has been changed. For external connections, you can also change the port connection.


When installing mysql connections in linux, you are often prompted that the mysql. sock file cannot be found. The solution is also simple:

If the newly installed mysql file is not found, search for it and specify the correct location in/etc/my. cnf and set the soft link in the system.

If the mysql. sock file is deleted by mistake, you need to restart the mysql service. If the restart is successful, mysql. sock will be generated under the datadir directory, and then specified.

If the connection fails, you can use the TCP connection mode. In windows, the MPs queue connection mode is also supported.

This article from the "Drop water stone" blog, please be sure to keep this source http://xjsunjie.blog.51cto.com/999372/1324549

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.