• Linux服务器配置(一)


    Linux服务器配置(一)

    jdk,tomcat,nginx记录

    最近公司买了三台服务器System x3650 M5用来跑公司的项目。现,记录一下真机部署与后期维护历程~
    因为系统是服务器买来就装好的,所以避免不了有一些不符合应用场景的程序,服务等,首先使用yum grouplist命令来看看当前系统中已经包含哪些东西~

    Loaded plugins: fastestmirror, refresh-packagekit, security
    Setting up Group Process
    Loading mirror speeds from cached hostfile
     * base: mirrors.tuna.tsinghua.edu.cn
     * extras: mirror.bit.edu.cn
     * updates: mirror.bit.edu.cn
    Installed Groups:
       Java 平台
       NFS 文件服务器
       Perl 支持
       SNMP 支持
       X 窗口系统
       万维网服务器
       互联网应用程序
       互联网浏览器
       办公套件和生产率
       图形管理工具
       基本
       字体
       安全性工具
       性能工具
       打印客户端
       打印服务器
       拨号网络支持
       服务器平台
       桌面
       桌面平台
       桌面调试和运行工具
       电子邮件服务器
       目录客户端
       硬件监控工具
       继承 UNIX 兼容性
       继承 X Windows 系统的兼容性
       网络基础设施服务器
       网络文件系统客户端
       联网工具
       调试工具
       输入法
       通用桌面
       附加开发
    

    系统默认安装了java平台,看看是不是我们想要的。

    [root@hart ~]# java -version
    java version "1.7.0_45"
    OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
    OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
    

    原来安装的是OpenJDK,好吧。我们自己动手换成我们自己常用的oracle jdk.那么首先我们要将OpenJDK卸载。

    [root@hart ~]# rpm -qa | grep jdk
    java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
    java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
    [root@hart ~]# yum -y remove java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64 java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
    ....
    ....
    ....
    Complete!
    [root@hart ~]# 
    

    ok 卸载完成。

    http://www.oracle.com/technetwork/java/javase/downloads/index.html
    

    自行下载jdk

    
    [root@hart hart]# tar -zxvf jdk-7u80-linux-x64.gz //解压jdk到当前目录下
    [root@hart hart]# mkdir /usr/java
    [root@hart hart]# mv jdk1.7.0_80/ /usr/java/jdk1.7
    [root@hart jdk1.7]# vi /etc/profile
    //在文件最后面添加
    export JAVA_HOME=/usr/java/jdk1.7/
    export PATH=$PATH:$JAVA_HOMEin
    export CLASSPATH=.
    //保存 退出 :wq
    [root@hart jdk1.7]# source /etc/profile
    [root@hart jdk1.7]# java
    [root@hart jdk1.7]# javac
    [root@hart jdk1.7]# java -version
    java version "1.7.0_80"
    Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
    

    Ok~JDK安装配置完成。下面安装tomcat

    [root@hart tomcat]# ls
    apache-tomcat-7.0.69.tar.gz
    [root@hart tomcat]# tar -zxvf apache-tomcat-7.0.69.tar.gz 
    [root@hart tomcat]# ls
    apache-tomcat-7.0.69  apache-tomcat-7.0.69.tar.gz
    [root@hart tomcat]# mv apache-tomcat-7.0.69 tomcat7.0
    [root@hart tomcat]# ls
    apache-tomcat-7.0.69.tar.gz  tomcat7.0
    

    配置tomcat

    [root@hart tomcat]# cd tomcat7.0/conf/
    [root@hart conf]# ls
    catalina.policy      context.xml         server.xml        web.xml
    catalina.properties  logging.properties  tomcat-users.xml
    [root@hart conf]# vi server.xml 
    <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" URIEncoding="UTF-8" />
    //port自行修改,最后加上URIEncoding="UTF-8"可以避免地址栏路径中文乱码问题
    //在<Host>标签中添加以下代码,可以使tomcat访问虚拟路径
    <Context docBase="/usr/filePath" path="/file" />
    //此外,在context.xml中配置也可以
    [root@hart conf]# vi web.xml 
    <servlet>
            <servlet-name>default</servlet-name>
            <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
            <init-param>
                <param-name>debug</param-name>
                <param-value>0</param-value>
            </init-param>
            <init-param>
                <param-name>listings</param-name>
                <!-- 将false改为true-->
                <param-value>true</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
    

    Ok,安装nginx

    [root@hart nginx]# ls
    nginx-1.8.1.tar.gz
    [root@hart nginx]# tar -zxvf nginx-1.8.1.tar.gz 
    [root@hart nginx]# cd nginx-1.8.1
    [root@hart nginx-1.8.1]# ./configure 
    [root@hart nginx-1.8.1]# ./configure 
    checking for OS
     + Linux 2.6.32-431.el6.x86_64 x86_64
    checking for C compiler ... not found
    
    ./configure: error: C compiler cc is not found
    //没有gcc,安装
    [root@hart nginx-1.8.1]# yum -y install gcc
    Complete!
    [root@hart nginx-1.8.1]# ./configure 
    ./configure: error: the HTTP rewrite module requires the PCRE library.
    You can either disable the module by using --without-http_rewrite_module
    option, or install the PCRE library into the system, or build the PCRE library
    statically from the source with nginx by using --with-pcre=<path> option.
    //安装pcre-devel
    [root@hart nginx-1.8.1]# yum install pcre-devel
    Total download size: 516 k
    Is this ok [y/N]: y
    Complete!
    [root@hart nginx-1.8.1]# ./configure 
    ./configure: error: the HTTP gzip module requires the zlib library.
    You can either disable the module by using --without-http_gzip_module
    option, or install the zlib library into the system, or build the zlib library
    statically from the source with nginx by using --with-zlib=<path> option.
    //哎= =!安装zlib-devel
    [root@hart nginx-1.8.1]# yum -install zlib-devel
    
    Total download size: 44 k
    Installed size: 115 k
    Is this ok [y/N]: y
    Complete!
    [root@hart nginx-1.8.1]# ./configure 
    Configuration summary
      + using system PCRE library
      + OpenSSL library is not used
      + using builtin md5 code
      + sha1 library is not found
      + using system zlib library
    
      nginx path prefix: "/usr/local/nginx"
      nginx binary file: "/usr/local/nginx/sbin/nginx"
      nginx configuration prefix: "/usr/local/nginx/conf"
      nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
      nginx pid file: "/usr/local/nginx/logs/nginx.pid"
      nginx error log file: "/usr/local/nginx/logs/error.log"
      nginx http access log file: "/usr/local/nginx/logs/access.log"
      nginx http client request body temporary files: "client_body_temp"
      nginx http proxy temporary files: "proxy_temp"
      nginx http fastcgi temporary files: "fastcgi_temp"
      nginx http uwsgi temporary files: "uwsgi_temp"
      nginx http scgi temporary files: "scgi_temp"
    //终于哦了~~~make
    [root@hart nginx-1.8.1]# make install
    

    nginx代理tomcat

    //在/usr/local/nginx/conf/nginx.conf中:
    //配置tomcat节点:在http节点内部,server节点外部
    	upstream tomcat-servers {
    		server ip:tomcatport;
    	}
    //server节点内部:
    	location / {
    		proxy_pass http://tomcat-servers;
    		proxy_redirect    off;
    		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    		proxy_set_header X-Real-IP $remote_addr;
    		proxy_set_header Host $http_host;
    		proxy_next_upstream http_502 http_504 error timeout invalid_header;
    	}
    

    只是现在从别的机器还访问不了,怎么办呢?

    [root@hart sbin]# vi /etc/rc.d/init.d/iptables 
    //加入以下这条规则
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
    [root@hart sbin]# service iptables restart
    

    ok.这样就可以访问啦~~
    先这样简单的记录一下步骤。深入的运维管理,让我们一起慢慢学习。

  • 相关阅读:
    codis安装手册
    引用对象的使用和易产生bug的示例
    shallow copy 和 deep copy 的示例
    [转载] 公知其实就是正常人嘛
    Spring GET请求实体中日期的转换
    [转载] 方方: 借陸遊三個字:錯,錯,錯(3月16日)
    [转载] 英国防疫怪招
    [记录] Disruptor 介绍
    [记录] 重要网址备忘
    [转载] 面对新冠病毒在全球的大流行,我们如何自保?
  • 原文地址:https://www.cnblogs.com/tdg-yyx/p/6823083.html
Copyright © 2020-2023  润新知