Set up the CentOs Server environment and centosserver

Source: Internet
Author: User
Tags centos server install redis

Set up the CentOs Server environment and centosserver
CentOs Server environment construction

Tags (separated by spaces): Environment build centos

Introduction: This document provides guidance on how to build a JAVA project-related server environment in the new CentOs system. Read this document and use the markdown reader or install the markdown plug-in IDE development tools.
Step index:

1. Install JDK
2. install Tomcat
3. Install Nginx
4. Install mysql
5. Install redis

Install JDK in the main text to check whether the openjdk software is installed by default in CentOs. You can use any of the following commands. It is best to give it a try:
#rpm -qa |grep java#rpm -qa |grep jdk#rpm -qa |grep gcj

After the command is executed, if no output is displayed, it indicates that jdk is not installed on the system and the system jumps directly to Step 1. On the contrary, if the output is similar to the following:

java-1.6.0-openjdk-1.6.0.35-1.13.7.1.el6_6.x86_64java-1.6.0-openjdk-1.7.0.35-2.3.7.1.el6_6.x86_64

It indicates that the system has installed openjdk. We need to uninstall it, And then install the jdk. Uninstall command of sun:

# Rpm-e jdk-related file name // (General DELETE command: delete a specific package. In case of dependency, it cannot be deleted) # rpm-e-nodeps jdk-related file name // (Force DELETE command, ignore dependency, delete a specific package. If the preceding command is used to delete other dependent files, you can use this command to forcibly delete them)

Note: jdk-related file names refer to the names of jdk-related files found by the query command in the previous step.

For example:

 #rpm -e java-1.6.0-openjdk-1.6.0.35-1.13.7.1.el6_6.x86_64

If it cannot be deleted, try the following command:

# Yum-y remove java jdk file name

After running the preceding command, run the find command to check whether there are any file residues:

#find / -name jdk#find / -name java#find / -name jre#find / -name gcj

The query fails, indicating that jdk has been deleted.

If any of the directories involved are found, you can use the # rm-rf directory to delete the residual directories one by one.

So far, jdk deletion has been completed.

Download and install sun's jdk package

First, query the number of digits of the current system to determine the number of digits of the jdk to download:

# uname -r

The following output is displayed:

2.6.32-358.el6.x86_64

We can see that the system is 64-bit. Then we will search and download the 64-bit jdk. Here we choose to download version 1.6. The downloaded file name is:

Jdk-6u45-linux-x64.bin

We upload the downloaded file to the usr/java directory on the server using the ftp tool (the java directory is newly created ).

Download link for the latest jdk version

Switch the terminal tool to the java directory and modify the file permissions:

#chmod u+x jdk-6u45-linux-x64-rpm.bin

Install:

#./jdk-6u45-linux-x64-rpm.bin 

If you can see the java version number, it indicates that the installation is successful:

#java -version

3. Configure Environment Variables

#vi /etc/profile

Add

JAVA_HOME =/usr/java/jdk1.6.0 _ 45 // note that the version number is the PATH you just installed = $ PATH: $ JAVA_HOME/binCLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jarexport JAVA_HOMEexport PATHexport CLASSPATH

Run: wq to save and exit, and update the configuration file:

#source /etc/profile

So far, jdk is successfully installed.

Install Tomcat and download tomcat

Download the latest tomcat version

Upload the downloaded file (apache-tomcat-7.0.61.tar.gz) to the terminal in the usr/local directory of the server by using ftp, and decompress tomcat:
#tar -xzvf apache-tomcat-7.0.61.tar.gz
Copy the decompressed file to the usr/tomcat directory:
#cp -R apache-tomcat-7.0.61 /usr/local/tomcat
Start tomcat
#/usr/local/tomcat/bin/startup.sh
Disable Firewall
#/etc/init.d/iptables stop

So far, tomcat is successfully installed and configured,

Enable apachetomcat and write apache tomcat to the startup queue:

(1. apache tomcat startup command:

#/usr/local/tomcat/bin/startup.sh

(2 command for stopping apache tomcat:

#/usr/local/tomcat/bin/shutdown.sh

(3. apache tomcat startup settings:

#echo "/usr/local/tomcat/bin/startup.sh" >> /etc/rc.local

3. Configure TOMCAT Environment Variables
Edit

#vi ~/.bash_profile 

Add tomcat Environment Parameters

TOMCAT_HOME=/usr/local/tomcatexport PATH JAVA_HOME CLASSPATH TOMCAT_HOME

Save and exit, and then execute

#source ~/.bash_profile 

Make environment variables take effect

Start the TOMCAT service now:

#/usr/local/tomcat/bin/startup.sh

Then enter

#netstat –tnl 

Listen. If you can see 8080 and 8009, tomcat has started properly.

The following is an access test to see if you can access the webpage. Enter http: // serverip: 8080. If you can see the webpage, it indicates that tomcat has been installed successfully.

Install Nginx download Nginx installation package

Download link for the latest Nginx version

Before installing nginx, make sure that the system has installed g ++, gcc, openssl-devel, pcre-devel, and zlib-devel. Install required software:
#yum install gcc-c++#yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
Upload the installation package file to/usr/local and perform the following operations:
[root@admin local]# cd /usr/local[root@admin local]# tar -zxv -f nginx-1.2.6.tar.gz[root@admin local]# rm -rf nginx-1.2.6.tar.gz[root@admin local]# mv nginx-1.2.6 nginx[root@admin local]# cd /usr/local/nginx[root@admin nginx]# ./configure --prefix=/usr/local/nginx[root@admin nginx]# make[root@admin nginx]# make install
Start
# Method 1 [root @ admin nginx-1.2.6] #/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx. conf # method 2 [root @ admin nginx-1.2.6] # cd/usr/local/nginx/sbin [root @ admin sbin] #. /nginx

PS: the following error may be reported during startup:

Nginx: [alert] cocould not open error log file: open () "/usr/local/nginx/logs/error. log" failed (2: No such file or directory)
15:57:14 [emerg] 16430 #0: open () "/usr/local/nginx/logs/access. log" failed (2: No such file or directory)

Create a logs folder in the nginx folder and start it again.

Test
# Test port # netstat-na | grep 80 # test http: // ip: 80 in the browser
Install Mysql to uninstall the original mysql
# Rpm-qa | grep mysql // This command will check whether the mysql database has been installed on the Operating System

If yes, run the rpm-e command or the rpm-e-nodeps command to uninstall it.

# Rpm-e mysql // normal deletion mode # rpm-e -- nodeps mysql // strong deletion mode. If you use the preceding command to delete a file, the system prompts that there are other dependent files, you can use this command to forcibly delete it.

After deletion, run the rpm-qa | grep mysql command to check whether mysql has been uninstalled successfully !!

Install mysql through Yum

First, you can enter the yum list | grep mysql command to view the available mysql database versions on yum:

# yum list | grep mysql

Then, run the yum install-y mysql-server mysql-devel command to install mysql-server mysql-devel (note: when installing mysql, We have installed the mysql database instead of the mysql client. We also need to install the mysql-server)

# yum install -y mysql-server mysql mysql-devel
Mysql database initialization and related configuration

We can start our mysql service by entering the service mysqld start command.

# service mysqld start

When using the mysql database, we have to start the mysqld service first. We can run the chkconfig-list | grep mysqld command to check whether the mysql service is automatically started upon startup, for example:

#chkconfig --list | grep mysqld

We found that the mysqld service is not automatically started when it is started. Of course, you can use the chkconfig mysqld on command to set it to boot, so that you do not need to start it manually every time.

#chkconfig mysqld on

After the mysql database is installed, there will be only one root administrator account, but the root account has not set a password for it at this time, so we can use the command to set a password for our root Account:

# Mysqladmin-u root password 'njxuqiangmy' // Use this command to set the password for the root account to njxuqiangmysql

Now we can log on to our mysql database using the mysql-u root-p command.

#mysql -u root -p 

Enter password:
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 5
Server version: 5.1.73 Source distribution
Copyright (c) 2000,201 3, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.
Mysql>

Install redis
wget http://download.redis.io/redis-stable.tar.gztar xvzf redis-stable.tar.gzcd redis-stablemake

Make test is required after make is successful. An exception occurred in make test.

Exception 1:

couldn't execute "tclsh8.5": no such file or directory

Cause of exception: tcl is not installed

Solution:

#yum install -y tcl。

After make is successful, some executable files will be added to the src directory: redis-server, redis-cli, and so on.

During this period, copy the cp command to the usr directory and run it.

#cp redis-server /usr/local/bin/cp redis-cli /usr/local/bin/      

Create a directory to store the configuration file.

#mkdir /etc/redis#mkdir /var/redis#mkdir /var/redis/log#mkdir /var/redis/run#mkdir /var/redis/6379

Find the configuration file template in the redis root directory and copy it to the following location.

#cp redis.conf /etc/redis/6379.conf

Use the vim command to modify

daemonize yespidfile /var/redis/run/redis_6379.pidlogfile /var/redis/log/redis_6379.logdir /var/redis/6379

Finally run redis:

 #redis-server /etc/redis/6379.conf

Related Article

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.