• 搭建JavaWeb服务器


    1、安装jdk7

    //检查jdk是否已经安装
    [root@iZwz9catu2mrq92b07d1d0Z ~]# yum list installed | grep java
    java-1.7.0-openjdk.x86_64
    java-1.7.0-openjdk-demo.x86_64
    java-1.7.0-openjdk-devel.x86_64
    java-1.7.0-openjdk-javadoc.noarch
    java-1.7.0-openjdk-src.x86_64
    tzdata-java.noarch     2017c-1.el6      @updates                                
    
    //卸载现有的jdk
    [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y remove java-1.7.0*
    
    //查看yum库中的Java安装包
    [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -C list java*
    
    ...
    java-1.7.0-openjdk.x86_64                                          1:1.7.0.151-2.6.11.0.el6_9                            updates
    java-1.7.0-openjdk-demo.x86_64                                     1:1.7.0.151-2.6.11.0.el6_9                            updates
    java-1.7.0-openjdk-devel.x86_64                                    1:1.7.0.151-2.6.11.0.el6_9                            updates
    java-1.7.0-openjdk-javadoc.noarch                                  1:1.7.0.151-2.6.11.0.el6_9                            updates
    ...
    
    //安装jdk7
    [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y install java-1.7.0*
    
    //安装成功
    [root@iZwz9catu2mrq92b07d1d0Z ~]# java -version
    java version "1.7.0_151"
    OpenJDK Runtime Environment (rhel-2.6.11.0.el6_9-x86_64 u151-b00)
    OpenJDK 64-Bit Server VM (build 24.151-b00, mixed mode)

    2、安装tomcat7

    //从官网下载tomcat7
    [cjh@iZwz9catu2mrq92b07d1d0Z ~]$ wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz
    
    //检查压缩包文件
    [cjh@iZwz9catu2mrq92b07d1d0Z ~]$ tar -ztvf apache-tomcat-7.0.82.tar.gz
    
    //解压
    [cjh@iZwz9catu2mrq92b07d1d0Z ~]$ tar -zxvf apache-tomcat-7.0.82.tar.gz
    
    [cjh@iZwz9catu2mrq92b07d1d0Z ~]$ ls
    apache-tomcat-7.0.82  apache-tomcat-7.0.82.tar.gz

    注:当我们尝试启动tomcat时可能会遇到启动非常慢的情况,并且在启动日志中会看到类似以下的信息

    <DATE> org.apache.catalina.util.SessionIdGenerator createSecureRandom
    INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [5172] milliseconds.

    关于本问题请参考官方文章末尾有说明 官方说明

    问题说明:

    Tomcat 7+ heavily relies on SecureRandom class to provide random values for its session ids and in other places. Depending on your JRE it can cause delays during startup if entropy source that is used to initialize SecureRandom is short of entropy

    译:tomcat7+严重依赖SecureRandom类为会话ids和其它地方提供的随机值,这会导致启动过程出现延迟。

    解决办法:

    There is a way to configure JRE to use a non-blocking entropy source by setting the following system property: -Djava.security.egd=file:/dev/./urandom

    译:添加jvm参数 -Djava.security.egd=file:/dev/./urandom

    [cjh@iZwz9catu2mrq92b07d1d0Z bin]$ pwd
    /home/cjh/apache-tomcat-7.0.82/bin
    
    //在开头注释后面添加参数
    [cjh@iZwz9catu2mrq92b07d1d0Z bin]$ vi catalina.sh
    
    ...
    JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom"
    ...
    
    
    //查看jvm运行参数,参数已添加
    [cjh@iZwz9catu2mrq92b07d1d0Z bin]$ jps -v
    ...
    
    //重新运行tomcat,查看启动日志,启动耗时正常
    ...

     3、安装反向代理nginx

    //安装nginx
    [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y install nginx
    
    //安装完成后查看配置文件路径
    [root@iZwz9catu2mrq92b07d1d0Z ~]# whereis nginx
    
    //检查配置文件内容,可以发现包含了另一个路径下的配置文件组
    [root@iZwz9catu2mrq92b07d1d0Z ~]# cat /etc/nginx/nginx.conf
    
    ...
    include /etc/nginx/conf.d/*.conf;
    ...
    
    //切换路径,检查文件组
    [root@iZwz9catu2mrq92b07d1d0Z ~]# cd /etc/nginx/conf.d/
    [root@iZwz9catu2mrq92b07d1d0Z conf.d]# ls -l | grep .conf
    -rw-r--r-- 1 root root 408 Nov 22 17:59 default.conf
    -rw-r--r-- 1 root root 686 Oct 31 2016 ssl.conf
    -rw-r--r-- 1 root root 283 Oct 31 2016 virtual.conf
    
    //修改default.conf
    [root@iZwz9catu2mrq92b07d1d0Z conf.d]# vi default.conf
    
    ...
    listen      端口号;
    server_name 域名/ip;
    ...
    
    //启动nginx
    [root@iZwz9catu2mrq92b07d1d0Z conf.d]# chkconfig nginx on
    [root@iZwz9catu2mrq92b07d1d0Z conf.d]# service nginx start
    
    //在浏览器上访问域名或ip,显示nginx的欢迎页面即配置成功

      ps:nginx访问日志的默认路径:/var/log/nginx,yum源http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    4、安装MySQL

    下载官方yum库

    https://dev.mysql.com/downloads/repo/yum/

    安装说明

    https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

    //下载MySQL Yum库
    [root@iZwz9catu2mrq92b07d1d0Z ~]# wget https://repo.mysql.com/mysql57-community-release-el6-10.noarch.rpm
    
    //安装yum库,yum库地址 /etc/yum.repos.d
    [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y localinstall mysql57-community-release-el6-10.noarch.rpm
    
    //检查库安装成功,默认已开启子库mysql57-community
    [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -C repolist enabled
    
    //安装MySQL5.7
    [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y install mysql-community-server
    
    //启动服务
    [root@iZwz9catu2mrq92b07d1d0Z yum.repos.d]# chkconfig mysqld on
    [root@iZwz9catu2mrq92b07d1d0Z ~]# service mysqld start
    Initializing MySQL database:                               [  OK  ]
    Starting mysqld:                                           [  OK  ]

    注意点1:

    1. 不同版本的os对应的yum库是不一样的,el后面的数字6代表的是系统6,数字11代表的是系列版本,可自行到https://repo.mysql.com/进行选择
    2. centos7因为放弃了MySQL,而改用MariaDB,所以应先卸载MariaDB再安装MySQL,下面附上处理方式。
    //查看
    [root@localhost project]# rpm -qa | grep mariadb
    mariadb-libs-5.5.56-2.el7.x86_64
    
    //强行卸载
    [root@localhost project]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
    
    //另外附上卸载yum库的代码
    [root@localhost project]# rpm -qa|grep mysql
    mysql57-community-release-el7-11.noarch
    
    [root@localhost project]# yum remove mysql57-community-release-el7-11.noarch

    注意点2:服务在初次启动时会进行初始化(仅5.7),超级用户会被创建,并且它的密码已被设置并存储在/var/log/mysqld.log,而非空

    A superuser account 'root'@'localhost' is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:

    //x值为数据库用户root的密码
    [root@iZwz9catu2mrq92b07d1d0Z ~]# cat /var/log/mysqld.log | grep password
    2017-11-22T14:27:56.638229Z 1 [Note] A temporary password is generated for root@localhost: x
    
    //进入成功
    [root@iZwz9catu2mrq92b07d1d0Z ~]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    ...
    
    //因为初次操作数据库时提示必须重置密码,附上密码修改方法
    mysql> set password = 'your password';

    注意点3:Expression #1 of ORDER BY clause is not in SELECT list

    问题的原因在与MySQL5.7以上提供了的一个检查GROUP BY合法性的sql_mode:ONLY_FULL_GROUP_BY,详细官方说明请看这里:https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_only_full_group_by

    解决方法:

    //打开my.cnf,去掉ONLY_FULL_GROUP_BY,如果文件里面没有sql_mode,可执行 select @@global.sql_mode 进行查询
    
    vi /etc/my.cnf
    
    [mysqld]
    
    sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    
    # service mysqld stop
    
    # service mysqld start

    转载请注明出处:http://www.cnblogs.com/cjh-notes/p/7868262.html

  • 相关阅读:
    大规模机器学习
    机器学习之推荐系统
    SVM实现邮件分类
    机器学习之异常检测
    降维算法学习
    手写数字识别实现
    动态规划训练之十七
    概率期望训练之三
    数据结构训练之四
    绵阳东辰国际test201910.25
  • 原文地址:https://www.cnblogs.com/cjh-notes/p/7868262.html
Copyright © 2020-2023  润新知