欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CentOS6.5下安装JDK1.7+MYSQL5.5+TOMCAT7+nginx1.7.5环境安装文档

程序员文章站 2023-10-29 11:42:46
分布式拒绝服务攻击(DDoS)指的是通过多台机器向一个服务或者网站发送大量看似合法的数据包使其网络阻塞、资源耗尽从而不能为正常用户提供正常服务的攻击手段。随着互联网带宽的增加和相关工具的不断发布,这种攻击的实施难度越来越低,有大量IDC托管机房、商业站点、游戏服务商一直饱受DDoS攻击的困扰,那么如... ......

----------------centos6.5下安装jdk1.7+mysql5.5+tomcat7+nginx1.7.5环境安装文档-----------------------


【jdk1.7安装】


1)登录sun的jdk官方下载网 址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

2)下载jdk-7u67-linux-x64.rpm文件

》删除系统自带openjdk

centos6.5 默认会安装openoffice之类,需要java支持,系统默认安装了一个openjdk1.7版本

# java -version

java version "1.7.0"

openjdk runtime environment (build 1.7.0-b09)

openjdk client vm (build 1.7.0-b09, mixed mode)

备注:

无须删除原有的openjdk;否则,与之相关的openoffice等软件,也会自动随之删除;

如果直接"应用程序-添加/删除软件--基本系统--java“删除其他相关软件也会自动删除,所以删除前,最好安装配置好新的jdk环境

1) 删除原有的jdk:

# rpm -qa|grep jdk

查看安装的jdk,会显示多个java-1.7.0-openjdk-1.7.0相关的程序,在以下一一卸载。直到删完为止,如下:

# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.x86_64

# rpm -e --nodeps java-1.7.0-openjdk-devel-1.7.0.65-2.5.1.2.el6_5.x86_64

# rpm -e --nodeps java-1.7.0-openjdk-demo-1.7.0.65-2.5.1.2.el6_5.x86_64

......

# rpm -qa|grep java

查看安装的java关联程序,在以下一一卸载。直到删完为止,如下:

# rpm -e --nodeps tzdata-java-2014h-1.el6.noarch

......

》配置新的jdk环境

1)把安装文件文件保存在/usr/java/tools下 ,并切换到root用户

# mkdir /usr/java 创建/urs/java目录

# cd /usr/java/

# rpm -ivh ./tools/jdk-7u67-linux-x64.rpm

》配置jdk1.6.0_22环境变量

# vi /etc/profile

java_home=/usr/java/jdk1.7.0_79

jre_home=/usr/java/jdk1.7.0_79/jre

path=$path:$java_home/bin:$jre_home/bin

classpath=:$java_home/lib/dt.jar:$java_home/lib/tools.jar:$jre_home/lib

export java_home jre_home path classpath

》使环境变量生效:

#source /etc/profile

》测试安装

1)查看版本号

# java -version

java version "1.7.0_67"

java(tm) se runtime environment (build 1.7.0_67-b01)

java hotspot(tm) 64-bit server vm (build 24.65-b04, mixed mode)

java hotspot(tm) client vm (build 17.1-b03, mixed mode, sharing)

说明成功了。


【mysql5.5的安装】


安装方式分为rpm和源码编译安装两种,本文是采用mysql源码编译方式,编译器使用cmake。软件需要mysql-5.5.40.tar.gz和cmake-2.8.10.2.tar.gz,请自行下载。

》下载地址:

http://dev.mysql.com/get/downloads/mysql-5.5/mysql-5.5.40.tar.gz

http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz

其中mysql使用最新的稳定版本,即最新试用版的上一个版本,且非rc或者alpha的版本,cmake直接用的最新版。

》上传mysql-5.5.40.tar.gz和cmake-2.8.10.2.tar.gz到/usr/java/tools文件夹下。

》centos安装g++和ncurses-devel

# yum install gcc-c++

# yum install ncurses-devel

》cmake的安装

# mkdir -p /usr/java/make

# cd /usr/java/make

# mv ../tools/cmake-2.8.10.2.tar.gz ./

# tar -zxv -f cmake-2.8.10.2.tar.gz

# cd cmake-2.8.10.2

# ./configure

# make

# make install

》将cmake永久加入系统环境变量

》用vi在文件/etc/profile文件中增加变量,使其永久有效,

# vi /etc/profile

》在文件path中加入make_path环境变量:

java_home=/usr/java/jdk1.7.0_67

jre_home=/usr/java/jdk1.7.0_67/jre

make_path=/usr/java/cmake/cmake-2.8.10.2/bin

path=$make_path:$path:$java_home/bin:$jre_home/bin

classpath=:$java_home/lib/dt.jar:$java_home/lib/tools.jar:$jre_home/lib

export java_home jre_home path classpath

》执行以下代码使刚才的修改生效:

# source /etc/profile

》用 export 命令查看path值

# echo $path

》创建mysql的安装目录及数据库存放目录

# mkdir -p /usr/java/mysql //安装mysql

# mkdir -p /usr/java/mysql/data //存放数据库

》创建mysql用户及用户组

# groupadd mysql

# useradd -r -g mysql mysql

》编译安装mysql

# cd /usr/java/mysql

# tar zxvf ../tools/mysql-5.5.40.tar.gz

# cd mysql-5.5.40/

# cmake -dcmake_install_prefix=/usr/java/mysql
-dmysql_unix_addr=/usr/java/mysql/mysql.sock
-ddefault_charset=utf8
-ddefault_collation=utf8_general_ci
-dwith_myisam_storage_engine=1
-dwith_innobase_storage_engine=1  

-dwith_memory_storage_engine=1  

-dwith_readline=1  

-denabled_local_infile=1  

-dmysql_datadir=/usr/java/mysql/data  

-dmysql_user=mysql  

-dmysql_tcp_port=6666

# make

# make install

》检验是否安装成功

# cd /usr/java/mysql

[root@fiona mysql]# ls

bin data include lib mysql-5.5.40 mysql-test scripts sql-bench

copying docs install-binary man mysql.sock readme share support-files

有bin等以上文件的话,恭喜你已经成功安装了mysql。

》配置mysql

》设置mysql目录权限

# cd /usr/java/mysql //把当前目录中所有文件的所有者设为root,所属组为mysql

# chown -r root:mysql .

# chown -r mysql:mysql data

》将mysql的启动服务添加到系统服务中

# cp support-files/my-medium.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y

》创建系统数据库的表

# cd /usr/java/mysql

# scripts/mysql_install_db --user=mysql

》设置环境变量

# vi /root/.bash_profile

在修改path=$path:$home/bin为:

path=$path:$home/bin:/usr/java/mysql/bin:/usr/java/mysql/lib

# source /root/.bash_profile //使刚才的修改生效

》手动启动mysql

# ./bin/mysqld_safe --user=mysql & //启动mysql,但不能停止

mysqladmin -u root -p shutdown //此时root还没密码,所以为空值,提示输入密码时,直接回车即可。

》将mysql的启动服务添加到系统服务中

# cp support-files/mysql.server /etc/init.d/mysql

》启动mysql

# service mysql start

starting mysql... error! the server quit without updating pid file (/usr/java/mysql/data/localhost.localdomain.pid).

》启动失败:

》我这里是权限问题,先改变权限

# chown -r mysql:mysql /usr/java/mysql

》接着启动服务器

# /etc/init.d/mysql start

》修改mysql的root用户的密码以及打开远程连接

# mysql -u root mysql

mysql> use mysql;

mysql> desc user;

mysql> grant all privileges on . to root@"%" identified by "root"; //为root添加远程连接的能力

mysql> update user set password = password('x123456.') where user='root'; //设置root用户密码

mysql> select host,user,password from user where user='root';

mysql> flush privileges;

mysql> exit

》重新登录

# mysql -u root -p

enter password:x123456.000

》若还不能进行远程连接,关闭防火墙

[root@localhost]# /etc/rc.d/init.d/iptables stop

用远程工具连接上了表示成功了。


【tomcat7.0的安装】


》先下载apache-tomcat-7.0.56.tar.gz

》下载地下:http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.56/bin/apache-tomcat-7.0.56.tar.gz

# cd /usr/java

# tar -zxvf ./tools/apache-tomcat-7.0.56.tar.gz

# cd /etc/rc.d/init.d

# vi tomcat

#----------输入以下信息---------------------

#

# chkconfig: 345 80 15

# description: tomcat is a servlet+jsp engine.

# enter the jdk installation directory

jdk_file=/usr/java/jdk1.7.0_67

# enter the tomcat installation directory

tomcat_file=/usr/java/apache-tomcat-7.0.56

export java_home=$jdk_file

# source function library.

. /etc/rc.d/init.d/functions

start(){

if [ -z $(/sbin/pidof java) ]; then

echo "starting tomcat"

$tomcat_file/bin/startup.sh

touch /var/lock/subsys/tomcat

else

echo "tomcat allready running"

fi

}

stop(){

if [ ! -z $(/sbin/pidof java) ]; then

echo "shutting down tomcat"

$tomcat_file/bin/shutdown.sh

until [ -z $(/sbin/pidof java) ]; do :; done

rm -f /var/lock/subsys/tomcat

else

echo "tomcat not running"

fi

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

status)

$tomcat_file/bin/catalina.sh version

;;

*)

echo "usage: $0 {start|stop|restart|status}"

esac

exit 0

#----------输入以下信息---------------------

:wq! #保存退出

# chmod 755 /etc/rc.d/init.d/tomcat #添加执行权限

# chkconfig --add tomcat #添加服务

# chkconfig tomcat on #设置开机启动

# service tomcat stop #停止

# service tomcat start #启动

# service tomcat restart #重启

# service tomcat status #查看状态信息

————————————————————————————————————————————————————————————————————————————————————————————

【nginx-1.7.6.tar.gz的安装】


》先下载nginx-1.7.6.tar.gz

》下载url:http://nginx.org/download/nginx-1.7.6.tar.gz

》把nginx-1.7.6.tar.gz放到/usr/java/tools目录下

# cd /usr/local/

# tar -zxvf /usr/java/tools/nginx-1.7.5.tar.gz

# cd nginx-1.7.6/

# yum -y install pcre-devel

# yum install -y zlib-devel

# ./configure

# make && make install

# cd /usr/local/nginx

# cd sbin

# ./nginx

# /etc/rc.d/init.d/iptables stop

》配置服务器启动方式

# vi /etc/init.d/nginx

#---------输入以下信息------------------

# nginx startup script for the nginx http server

# it is v.0.0.2 version.

# chkconfig: - 85 15

# description: nginx is a high-performance web and proxy server.

# it has a lot of features, but it's not for everyone.

# processname: nginx

# pidfile: /software/nginx/logs/nginx.pid

# config: /software/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/usr/local/nginx/logs/nginx.pid

retval=0

prog="nginx"

# source function library.

. /etc/rc.d/init.d/functions

# source networking configuration.

. /etc/sysconfig/network

# check that networking is up.

[ ${networking} = "no" ] && exit 0

[ -x $nginxd ] || exit 0

# start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

echo "nginx already running...."

exit 1

fi

echo -n $"starting $prog: "

daemon $nginxd -c ${nginx_config}

retval=$?

echo

[ $retval = 0 ] && touch /var/lock/subsys/nginx

return $retval

}

# stop nginx daemons functions.

stop() {

echo -n $"stopping $prog: "

killproc $nginxd

retval=$?

echo

[ $retval = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid

}

reload() {

echo -n $"reloading $prog: "

#kill -hup cat ${nginx_pid}

killproc $nginxd -hup

retval=$?

echo

}

# see how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

stop

start

;;

status)

status $prog

retval=$?

;;

*)

echo $"usage: $prog {start|stop|restart|reload|status|help}"

exit 1

esac

exit $retval

#---------输入以下信息------------------

# chmod 755 /etc/init.d/nginx && chkconfig nginx on

# service nginx start

# service nginx stop

# service nginx restart

# ps -ef | grep nginx

# netstat -pant | grep 80

》测试在浏览器中输入广域网ip看看能不能看到欢迎界面,如果能就表示成功了。

————————————————————————————————————————————————————————————————————————————————————————————

【配置规则】


# vi /etc/sysconfig/iptables

增加如下配置:

-a input -m state --state new -m tcp -p tcp --dport 80 -j accept

-a input -m state --state new -m tcp -p tcp --dport 8888 -j accept

-a input -m state --state new -m tcp -p tcp --dport 6666 -j accept

# service iptables restart

》系统启动的方式为自启动

# chkconfig mysql on

# chkconfig nginx on

# chkconfig tomcat on

----------------------------------------------------------------------------------------------------

所有环境安装完成。欢迎使用centos6.5,祝大家一用便会。

----------------------------------------------------------------------------------------------------