Linux builds Java Web server

Source: Internet
Author: User
Tags download redis gz file openssl library unique id nginx reverse proxy

without permission, no reprint 1, JDK download and configuration 1.1 downloads

sudo wget http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz? Authparam=1432864690_d8334d64fa2a7f2048c38f7dd3180fe0

1.2 Decompression

Decompression--TAR-ZXVF jdk-8u45-linux-x64.tar.gz

1.3 Configuration

1.

Open a hidden file under home vim ~/.bash_profile

On the last side of the document, add:

Export java_home=/opt/jdk1.8.0_45

Export path= $JAVA _home/bin: $PATH

Export class_path=: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

For 192.168.118.60 this server, the original JDK is 1.7, now I replaced 1.8, changed Java_home=export java_home=/opt/jdk1.8.0_45

2.

Vi/etc/profile

Add the following content to the inside

Click ( here ) collapse or Open

Java_home=/usr/local/java/jdk1.6.0_01

Path= $JAVA _home/bin: $PATH

Classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

Export Java_home

Export PATH

Export CLASSPATH

Variable to be effective and login again

5. Enter the/usr/bin/directory

Cd/usr/bin

Ln-s-f/usr/java/jdk1.6.0_01/jre/bin/java

Ln-s-f/usr/java/jdk1.6.0_01/bin/javac

1.4 Testing

Test--Java-version

2. Tomcat includes port modification and startup memory how to modify (TOMCAT7) 2.1 Tomcat Port modification

Tomcat Launcher--sh startup.sh; ./bin/startup.sh after return

Modify Port--cd/opt/apache-tomcat-7.0.57/conf path below vim server.xml/8080 find the default port and modify it;

2.2 Modifying Startup Parameters

To add the catalina.sh under Tomcat's bin, position cygwin=false before.

Adjusted the startup parameters in the catalina.sh--cd/opt/apache-tomcat-7.0.57/bin/catalina.sh

--java_opts= "-xms256m-xmx512m-xss1024k-xx:permsize=128m-xx:maxpermsize=256m"

2.3 Installing Tomcat

Find Tomcat and unzip the tar.gz file.

3, MySQL How to install on CentOS, and how to configure users after installation, how to assign permissions, how to build a library, how to import libraries, how to back up the library, how to turn on automatic backup. (5.6 version) 3.1 Installation

Download the tar type of MySQL package, extracted to the usr/local/mysql below;

Unzip (TAR-XVF MySQL ... ), compile (i downloaded the 5.6, compile requires

Using the CMake directive, the lower version is used./configure; make;make install);

Create groups and users: Groupadd MySQL (create Group); useradd-r-G MySQL MySQL (create user)

Go to the MySQL folder and change the group and users that belong to: cd mysql-chown-r MySQL. --chgrp-r MySQL. (There is a point behind MySQL that indicates the current directory,-r means recursive current directory and subdirectories)

Install MySQL, execute the mysql_install_db script, initialize the data directory in MySQL, and create some tables: root scripts/mysql_install_db--user=mysql\

All files under the mysql/directory except the data/directory are returned to the root user, and the MySQL user only needs to be the owner of all files in the mysql/data/directory.

Chown-r Root.

Chown-r MySQL Data

Copying a configuration file

CP Support-files/mysql.server/etc/init.d/mysql.server

Test start Service:

①./support-files/mysql.server start

②service MySQL Start

3.2 Configuring users, assigning permissions, building libraries, importing libraries, backing up libraries

Before the configuration, first enter the database, mysql-uroot-p enter the password, and then select the database, if you do not know which databases can be viewed using show databases.

3.2.1 Configuring users

L Create user ' username ' @ ' host ' identified by ' password ';

L Insert into user (Host,user,password) values (' localhost ', ' username ', ' userpwd ');

3.2.3 Creating a Database

Create database TestDB;

3.2.3 Assigning permissions

Grant all privileges the TestDB to [e-mail protected] identified by ' UserPassword ';

3.2.4 Import and Export library

MySQL Database export
/usr/local/mysql/bin/mysqldump-u root-p test> Test.sql
Where: root is the database user name
Test is the name of the database that needs to be exported.
Test.sql is the path to the MySQL database default export database file SQL.


MySQL Database import
/usr/local/mysql/bin/mysql-u root-p test< Test.sql

3.3 Turn on automatic backup

Write a shell script implementation.

3.4 MySQL configuration for server 3.4.1mysql package with associated file address

The MySQL tar package and the associated RPM package are placed under the/opt path, and MySQL decompression is placed under the/usr/share/mysql,my.cnf file under the/usr path.

3.4.2 start the MySQL service and enter the database

In general, direct access:

When the initial installation of MySQL, direct decompression due to MySQL, start MySQL can enter MySQL, unable to perform database operations, will be an error similar to

ERROR 1820 (HY000): Must SET PASSWORD before executing this statement

Or

ERROR 1046 (3d000): No Database selected

Change Password directly:

It is also possible that the root user does not have a password and cannot access it directly.

At this point, you can use the following method-enter as a password change:

You can also use the following methods:

After modifying the password, you can enter MySQL directly:

3.4.3 Configuring the server

Character Set configuration is divided into two ways: directly into the MySQL database modification, the other is in the MY.CNF configuration. First configure the character set in MySQL. First look at the settings for the character set:

Then view the character set sort settings:

Configure the character Set column level, table level, database level.

Column-level character Set configuration:

L ALTER TABLE ' products ' change ' Products_model ' VARCHAR (CHARACTER) SET UTF8 COLLATE utf8_general_ci nulldefault NULL;

Table-level character set configuration is divided into two scenarios:

L Direct constraint when table is created, DEFAULT Charset=utf8

L Table >alter table Table_namedefault CHARSET UTF8 after creation of tables;

Database-level, divided into temporary and permanent:

L SET GLOBAL Character_set_database=utf8; (temporary)

L permanently modify the character set by modifying the MySQL configuration file, open/etc/mysql/my.cnf, and add Default-character-set=utf8 after [client]. This method is not implemented, mainly the file is not found.

3.4.4 Master-slave replication

MySQL version of the server must be consistent, or from the server than the main server version of the high;

Two nodes: a master server

B from the server

To modify the master server master:
#vi/etc/my.cnf
[Mysqld]
Log-bin=mysql-bin//[must] enable binary logging
server-id=222//[must be] server unique ID, default is 1, usually take IP last paragraph

Modify the slave from the server:
#vi/etc/my.cnf
[Mysqld]
Log-bin=mysql-bin//[must] enable binary logging
server-id=226//[must be] server unique ID, default is 1, usually take IP last paragraph

Restart two servers

Service MySQL Restart

Configuring the primary server

Establish an account on the primary server and authorize slave:
#/usr/local/mysql/bin/mysql–uroot Password
Mysql>grant replication Slave on * * to ' root ' @ ' xx.xx.xx.xx ' identified by ' password1 ';

Log on to the master server for MySQL and query the status of master
Mysql>show Masterstatus;

Configure the slave server Slave :

Configure the connection parameters from the server to the primary server, refresh, and then start from the server. Connection parameters refer to the status of the master server.

Check the status from server:

The above operation process, the master and slave server configuration is complete. Master-Slave Server testing:

master server creation Data

Viewing modified data from the server

4, Nginx installation method, and how to configure the reverse proxy, virtual host How to configure 4.1 Nginx and related package installation

--First Yum install GCC

--yum installgcc-c++

--Download Pcre, zlib, OpenSSL, Nginx

--Decompression, TAR-ZXVF

--Install Pcre Library,./configure--Make--make install

--Install ZILB Library,./configure--Make--make install

--Install the OpenSSL library,./config--Make--make install

4.2 Nginx Reverse proxy configuration, virtual host configuration

--cd/usr/local/nginx/conf

--vimnginx.conf

--insert

Upstream tomcat{

Server 192.168.118.60:9804; #tomcat

}

server{

.....

location/{

......

Proxy_pass Http://tomcat;

Proxy_redirect off;

Proxy_set_header Host $host;

Proxy_set_header x-forwarded-for

$proxy _add_x_forwarded_for;

Proxy_set_headerx-real-ip $remote _addr;

client_max_body_size50m;

client_body_buffer_size256k;

Proxy_connect_timeout 10;

Proxy_send_timeout 15;

Proxy_read_timeout 15;

Proxy_buffer_size 4k;

Proxy_buffers 432k;

proxy_busy_buffers_size64k;

proxy_temp_file_write_size64k;

}

5. Redis Related Installation method

--Download Redis--sudo wget URL

--Get a tar type of file, unzip--TAR-ZXVF redis-3.0.1.tar.gz

--Execute make, make install

--[[email protected] redis-3.0.1] #src/redis-server start Redis

--Open another terminal, [[Email protected]redis-3.0.1]# src/redis-cli

6. How to use Yum related tools

Yum's philosophy is to use a central repository (repository) to manage a subset of even a distribution of application interactions, and to perform related upgrades, installations, deletions, etc. based on the calculated software dependencies, reducing the Linux The user has always had a headache dependencies problem.

Linux builds Java Web server

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.