CentOs Server Environment Setup
tags (space delimited): Environment build CentOS
引言:本文档是在全新的CentOs系统搭建JAVA工程相关的服务器环境的指导文档,阅读本文档请使用markdown阅读器,或者在IDE开发工具中安装markdown插件
Step index:
1. Installing the JDK
2. Install Tomcat
3. Installing Nginx
4. Install MySQL
5. Installing Redis
Body Install JDK Check if CentOS has OPENJDK software installed by default, you can use any of the commands in the following command, preferably try:
#rpm -qa |grep java#rpm -qa |grep jdk#rpm -qa |grep gcj
After executing the command, if there is no output, the system does not have the JDK installed and jumps directly to step 2nd, instead, if the output resembles the following result:
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
The system already has OPENJDK installed, we need to uninstall it, and then install Sun's jdk. Uninstall command:
#rpm –e jdk相关文件名//(普通删除命令,删除特定的包,如果遇到依赖,则无法删除)#rpm -e –nodeps
Note: The JDK-related file name here refers to the file name of the JDK associated with the query command found 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 you cannot delete it, you can try the following command:
#yum -y remove java jdk相关文件名
After executing the above command, use the Find command to see if there are any remaining files:
#find / -name jdk#find / -name java#find / -name jre#find / -name gcj
The query has no effect, indicating that the JDK has been removed cleanly.
If the query out there are also participating in the directory, you can use the # RM-RF directory, the remaining directory one by one deleted.
The removal of the JDK has been completed.
Download and install Sun's JDK package
First, query the number of bits in the current system to determine what bits of JDK to download:
# uname -r
You will see output similar to the following:
2.6.32-358.el6.x86_64
We can see that the system is 64-bit, then we go to search download 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 files to the server's Usr/java directory using the FTP tool (the Java directory is new).
Latest version of JDK download link
Then, in the terminal tools switch to the Java directory, modify the file permissions:
#chmod u+x jdk-6u45-linux-x64-rpm.bin
To perform the installation:
If you can view the Java version number, the installation is successful:
#java -version
3. Configure Environment variables
#vi /etc/profile
At the end add
JAVA_HOME=/usr/java/jdk1.6.0_45 //注意版本号为你刚安装的PATH=$PATH:$JAVA_HOME/binCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport JAVA_HOMEexport PATHexport CLASSPATH
Execute: Wq save exit and update the configuration file:
#source /etc/profile
At this point, the JDK is installed successfully.
Install tomcat download Tomcat
Latest version of the Tomcat download link
Upload the downloaded file (apache-tomcat-7.0.61.tar.gz) to the server usr/local directory using the FTP tool to switch to the local directory and unzip Tomcat:
#tar -xzvf apache-tomcat-7.0.61.tar.gz
Copy the extracted files to the Usr/tomcat directory:
#cp -R apache-tomcat-7.0.61 /usr/local/tomcat
Start Tomcat
#/usr/local/tomcat/bin/startup.sh
Shutting down the firewall
#/etc/init.d/iptables stop
At this point, the Tomcat installation is configured successfully,
Turn on Apachetomcat and write Apache Tomcat to the boot run queue:
(1, Apache Tomcat start command:
#/usr/local/tomcat/bin/startup.sh
(2apache Tomcat's Stop command:
#/usr/local/tomcat/bin/shutdown.sh
(3, Apache Tomcat boot setting:
#echo "/usr/local/tomcat/bin/startup.sh" >> /etc/rc.local
3. Configuring Tomcat's environment variables
Edit
adding Tomcat Environment parameters
TOMCAT_HOME=/usr/local/tomcatexport PATH JAVA_HOME CLASSPATH TOMCAT_HOME
Save exit, and then execute
Make environment variables effective
Start the Tomcat service now:
#/usr/local/tomcat/bin/startup.sh
then enter
To listen, if you can see 8080 and 80,092, that Tomcat has started normally.
Visit the following test to see if you can access the Web page, enter: http://serverip:8080, you can see the Web page that the Tomcat has been installed successfully.
Install nginx Download Nginx installation package
The latest version of Nginx download link
Before installing Nginx, you need to ensure that the system has g++, GCC, Openssl-devel, Pcre-devel, and Zlib-devel software installed. Installation must be 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 to do the following:
[[email protected] local]# cd /usr/local[[email protected] local]# tar -zxv -f nginx-1.2.6.tar.gz[[email protected] local]# rm -rf nginx-1.2.6.tar.gz[[email protected] local]# mv nginx-1.2.6 nginx[[email protected] local]# cd /usr/local/nginx[[email protected] nginx]# ./configure --prefix=/usr/local/nginx[[email protected] nginx]# make[[email protected] nginx]# make install
Start
#方法1[[email protected] nginx-1.2.6]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf#方法2[[email protected] nginx-1.2.6]# cd /usr/local/nginx/sbin[[email protected] sbin]# ./nginx
PS: The following error may be reported at startup:
Nginx: [alert] could not open error log file:open () "/usr/local/nginx/logs/error.log" failed (2:no such file or director Y
2015/05/14 15:57:14 [Emerg] 16430#0:open () "/usr/local/nginx/logs/access.log" failed (2:no such file or directory)
Create a new Logs folder under the Nginx folder and start it again.
Test
#测试端口 #netstat –na|grep 80#浏览器中测试 http://ip:80
Install MySQL uninstall legacy MySQL
# rpm -qa | grep mysql // 这个命令就会查看该操作系统上是否已经安装了mysql数据库
If there is, we can unload it by rpm-e command or Rpm-e–nodeps command.
# rpm -e mysql // 普通删除模式# rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
After the deletion we can pass Rpm-qa | grep mysql command to see if MySQL has been uninstalled successfully!!
Install MySQL via yum
First we can enter Yum List | grep mysql command to view the downloadable version of the MySQL database available on Yum:
# yum list | grep mysql
Then we can install the MySQL mysql-server mysql-devel by entering the Yum install-y mysql-server mysql mysql-devel command (note: When we installed MySQL, we did not install the MySQL client, which is equivalent to installing the MySQL database, we also need to install the Mysql-server 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 we use MySQL database, we have to start the Mysqld service first, we can through Chkconfig–list | grep mysqld command to see if the MySQL service is booting automatically, such as:
#chkconfig --list | grep mysqld
We found that the MYSQLD service did not start automatically, and of course we can set it to boot up with the Chkconfig mysqld on command, so you don't have to start it manually every time.
#chkconfig mysqld on
After the MySQL database is installed there will only be a root administrator account, but at this time the root account has not set a password for it, so we can use the command to set the password for our root account:
# mysqladmin -u root password ‘njxuqiangmysql‘ // 通过该命令给root账号设置密码为 njxuqiangmysql
At this point we can log in to our MySQL database via the mysql-u root-p command.
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) and/or, Oracle, its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
Installing Redis
wget http://download.redis.io/redis-stable.tar.gztar xvzf redis-stable.tar.gzcd redis-stablemake
After make is successful, make test is required. An exception occurred in make test.
Exception One:
couldn‘t execute "tclsh8.5": no such file or directory
Exception reason: Tcl not installed
Solution:
#yum install -y tcl。
After make succeeds, there are some more executables in the SRC directory: Redis-server,redis-cli and so on.
During the convenient period, the CP command is copied to the USR directory for operation.
#cp redis-server /usr/local/bin/cp redis-cli /usr/local/bin/
Then create a new directory, store the configuration file
#mkdir /etc/redis#mkdir /var/redis#mkdir /var/redis/log#mkdir /var/redis/run#mkdir /var/redis/6379
Locate the profile template in the Redis solution directory and copy it to the following location.
#cp redis.conf /etc/redis/6379.conf
Modify with vim command
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
CentOs Server Environment Setup