美文网首页
CentOS 6.5 搭建Java Web运行环境

CentOS 6.5 搭建Java Web运行环境

作者: zxk175 | 来源:发表于2017-03-30 16:16 被阅读82次

    1 安装JDK

    1.1 下载JDK1.8

    [root@localhost~]# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz

    [bogon:Desktop zxk175$ wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-macosx-x64.dmg

    1.2 解压JDK1.8

    [root@localhost~]# tar -zxvf jdk-8u112-linux-x64.tar.gz

    1.3 设置环境变量

    [root@localhost~]# vi /etc/profile

    在profile中添加如下内容:

    set java environment
    export JAVA_HOME=/zxk175/jdk/8/jdk1.8.0_112
    export JRE_HOME=${JAVA_HOME}/jre  
    export PATH=${JAVA_HOME}/bin:$PATH  
    export CLASSPATH=.:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib  
    

    1.4 让配置生效

    [root@localhost ~]# source /etc/profile

    1.5 测试是否成功

    [root@localhost ~]# java -version

    输出以下内容则配置成功
    java version "1.8.0_112"
    Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
    

    2 安装Tomcat

    2.1 下载Tomcat8

    [root@localhost ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.13/bin/apache-tomcat-8.5.13.tar.gz

    2.2 解压Tomcat8

    [root@localhost ~]# tar -xzvf apache-tomcat-8.5.12.tar.gz

    2.3 启动Tomcat8

    [root@localhost ~]# ./startup.sh

    输出以下内容则启动成功
    Using CATALINA_BASE:   /zxk175/tomcats/tomcat8
    Using CATALINA_HOME:   /zxk175/tomcats/tomcat8
    Using CATALINA_TMPDIR: /zxk175/tomcats/tomcat8/temp
    Using JRE_HOME:        /zxk175/jdk/1.8/jdk1.8.0_112/jre
    Using CLASSPATH:       /zxk175/tomcats/tomcat8/bin/bootstrap.jar:/zxk175/tomcats/tomcat8/bin/tomcat-juli.jar
    Tomcat started.
    

    3 安装Nginx

    3.1 下载Nginx

    [root@localhost ~]# wget http://mirrors.sohu.com/nginx/nginx-1.10.3.tar.gz
    [root@localhost ~]# wget https://github.com/openresty/headers-more-nginx-module/archive/v0.32.tar.gz

    3.2 编译Nginx

    3.2.1 安装编译软件

    [root@localhost ~]# yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

    3.2.2 添加用户

    [root@localhost src]# groupadd -r nginx
    [root@localhost src]# useradd -r -g nginx nginx

    3.2.3 编译Nginx

    [root@localhost ~]# cd nginx-1.10.3
    [root@localhost ~]#./configure
    --prefix=/zxk175/nginx/nginx
    --user=nginx
    --group=nginx
    --with-http_ssl_module
    --with-http_flv_module
    --with-http_gzip_static_module
    --with-http_stub_status_module \

    --add-module=/zxk175/nginx/headers-more-nginx-module-0.32

    [root@localhost ~]# make

    3.2.4 安装Nginx

    [root@localhost ~]# make install

    3.2.5 配置Nginx

    3.2.5.1 查看Nginx信息

    [root@localhost ~]# /zxk175/nginx/nginx/sbin/nginx -V

    3.2.5.2 修改nginx.conf

    nginx.conf
    proxy.conf
    zxk175.conf
    weixin.conf

    4 安装MySQL

    4.0 准备工作

    4.0.1 卸载自带的MySQL

    [root@localhost src]# yum remove mysql mysql-server mysql-libs compat-mysql51
    [root@localhost src]# rm -rf /var/lib/mysql
    [root@localhost src]# rm -rf /etc/my.cnf

    4.0.2 c++: internal compiler error: Killed (program cc1plus)

    原因:内存不足, 在Linux下增加临时swap空间
    step 1:
    [root@localhost src]# dd if=/dev/zero of=/home/swap bs=1024 count=500000
    注释:of放置swap的空间; count增加的大小,bs是块的大小,总共空间是bs*count=500M
    step 2:
    [root@localhost src]# mkswap /home/swap
    注释:把刚才空间格式化成swap格式
    step 3:
    [root@localhost src]# swapon /home/swap
    注释:使用刚才创建的swap空间

    如果想关闭刚开辟的swap空间,只需命令:[root@localhost src]# swapoff

    4.1 下载MySQL

    [root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35.tar.gz

    4.2 解压MySQL

    [root@localhost ~]# tar -xzvf mysql-5.6.35.tar.gz

    4.3 编译MySQL

    4.3.0 添加用户

    [root@localhost ~]# groupadd mysql
    [root@localhost ~]# useradd -r -g mysql mysql
    [root@localhost ~]# id mysql

    4.3.1 安装编译软件

    [root@localhost ~]# yum install -y gcc-c++ gdb cmake pcre ncurses-devel bison bison-devel

    4.3.2 编译MySQL

    [root@localhost ~]# cd mysql-5.6.35
    [root@localhost ~]# cmake
    --DCMAKE_INSTALL_PREFIX=/zxk175/mysql
    --DMYSQL_DATADIR=/zxk175/mysql/data
    --DSYSCONFDIR=/zxk175/mysql
    --DWITH_INNOBASE_STORAGE_ENGINE=1
    --DWITH_PARTITION_STORAGE_ENGINE=1
    --DMYSQL_UNIX_ADDR=/zxk175/mysql/sock/mysql.sock
    --DMYSQL_TCP_PORT=3306
    --DDEFAULT_CHARSET=utf8
    --DDEFAULT_COLLATION=utf8_general_ci
    [root@localhost ~]# make -j 4

    4.3.3 安装MySQL

    [root@localhost ~]# make install

    4.3.4 改变目录所有者

    [root@localhost ~]# chown -R mysql.mysql /zxk175/mysql

    4.3.5 加入PATH路径

    [root@localhost ~]# vi /etc/profile

    文件尾部插入以下内容
    PATH=/zxk175/mysql/bin:/zxk175/mysql/lib:$PATH
    export PATH  
    

    [root@localhost ~]# source /etc/profile

    4.3.6 执行初始化配置脚本,创建系统自带的数据库和表

    [root@localhost ~]# cd /zxk175/mysql
    [root@localhost ~]# scripts/mysql_install_db --basedir=/zxk175/mysql --datadir=/zxk175/mysql/data --user=mysql

    4.3.7 添加服务,拷贝服务脚本到init.d目录,并设置开机启动

    [root@localhost ~]# cp support-files/mysql.server /etc/init.d/mysqld
    [root@localhost ~]# chkconfig mysqld on
    [root@localhost ~]# service mysqld start

    4.3.8 修改MySQL用户root的密码

    [root@localhost ~]# mysqladmin -u root password '123456'

    4.3.9 MySQL开启远程连接

    4.3.9.1 登录MySQL并切换到mysql数据库修改表数据

    [root@localhost ~]# mysql -uroot -p
    mysql> use mysql;
    mysql> update user set host = '%' where user = 'root';
    mysql> select host, user from user;

    4.3.9.1 赋予任何主机访问数据的权限并刷新权限

    mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
    mysql> flush privileges;
    mysql> exit;

    退出MySQL服务器,就可以在其它任何主机上以root身份登录

    相关文章

      网友评论

          本文标题:CentOS 6.5 搭建Java Web运行环境

          本文链接:https://www.haomeiwen.com/subject/oakpottx.html