• 在linux centos7 上安装java运行时环境,tomcat自启动脚本


    第一步,安装mysql,

    一、检查系统是否安装老版本,有的话干掉
    #yum list installed | grep mysql
    mysql-libs.x86_64 5.1.73-5.el6_6 @anaconda-CentOS-201508042137.x86_64/6.7 #yum -y remove mysql-libs.x86_64

    二、安装及配置
    # wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
    # rpm -ivh mysql-community-release-el6-5.noarch.rpm
    # yum repolist all | grep mysql
    安装MYSQL数据库(网络原因,下载时间过长,这是唯一的缺点,如果机房网络环境好可以这样装)
    # yum install mysql-community-server -y
    设置为开机启动)
    # chkconfig --list | grep mysqld
    # chkconfig mysqld on
    //不必这样 即可
    systemctl enable mysql

      systemctl list-unit-files    | grep  tomcat      //查看native级别的自启动

    centos7 分两种启动的级别,一个是系统的,用systemctl enable xxx。一个是sysV的,用chkconfig mysqld on

    三、设置远程root
    1.启动mysql和设置密码、登录
    # service mysqld start
    # mysql_secure_installation
    # mysql -uroot -p 
    2.建立远程root用户
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你设置的密码' WITH GRANT OPTION;
    mysql> flush privileges;
    四、设置utf-8编码

    查看mysql原本编码:
    mysql> show variables like 'character%';
    设置编码
    # vi /etc/my.cnf
    如下(少补):
    [mysqld]
    character-set-server=utf8 
    collation-server=utf8_general_ci 
    performance_schema_max_table_instances=400 
    table_definition_cache=400 
    table_open_cache=256
    # 修改
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    
    [mysql]
    default-character-set = utf8
    
    [mysql.server]
    default-character-set = utf8
    
    
    [mysqld_safe]
    default-character-set = utf8
    
    
    [client]
    default-character-set = utf8
     
     

    重启mysql

    # service mysqld restart

    再次查看编码:

    # mysql -uroot -p
    mysql> show variables like 'character%';
    +--------------------------+----------------------------+
    | Variable_name | Value |
    +--------------------------+----------------------------+
    | character_set_client | utf8 |
    | character_set_connection | utf8 |
    | character_set_database | utf8 |
    | character_set_filesystem | binary |
    | character_set_results | utf8 |
    | character_set_server | utf8 |
    | character_set_system | utf8 |
    | character_sets_dir | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)

    另外发现,在第二天打开服务器时,提示链接超时,如下:

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 126,421,823 milliseconds ago. The last packet sent successfully to the server was 126,421,823 milliseconds ago. is longer than the server configured value of ‘wait_timeout’. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property ‘autoReconnect=true’ to avoid this problem.

    修改办法为,

    mysql mysql> show global variables like ‘wait_timeout’;
    
      其默认值为8小时
    
      mysql的一个connection空闲时间超过8小时,mysql会自动断开该连接。
    
      1.修改配置
    
      vi /etc/my.cnf
    
      [mysqld] wait_timeout=5,184,000‬
    在mysqld节点,增加一行,wait_timeout=5,184,000‬,我修改为60天了。默认windows最大是24天,linux是365天。单位为秒。

     若发现查询时,wait_timeout 设置不起作用,是因为session会话的原因,查询时加入global关键字,

    show global variables like 'wait_timeout'; 

    第二步,安装jdk,从网上下载jdk1.8,的rpm包,用sftp传到服务器上,rpm -ivh xxxx.rpm 即可。在安装前,检查旧版本,若有删掉。

    安装后,自动配置好了,jdk和jre环境,可以用java -version,和 javac -version,查看版本。

    第三步,安装tomcat,若有旧版本,先删除,

    yum list installed | grep tomcat

    yum -y remove xxx.xx

    删除后,然后下在tomcat8.5,tar -xf  xxxxx.tar.gz 到根目录下。

    /lib/systemd/system目录下创建一个脚本文件tomcat.service,里面的内容如下

    [Unit]
    Description=Tomcat
    After=network.target

    [Service]
    Type=forking
    PIDFile=/usr/local/tomcat/pid
    ExecStart=/usr/local/tomcat/bin/catalina.sh start
    ExecReload=/usr/local/tomcat/bin/catalina.sh restart
    ExecStop=/usr/local/tomcat/bin/catalina.sh stop

    [Install]
    WantedBy=multi-user.target

    在/usr/local/下面,建立tomcat的目录。确保路径真实有效。


    在tomcat的bin/catalina.sh里面,添加

    CATALINA_PID=/usr/local/tomcat/pid
    # OS specific support. $var _must_ be set to either true or false. cygwin=false
    ....略..

    创建软链接

    ln -s /lib/systemd/system/tomcat.service /etc/systemd/system/multi-user.target.wants/tomcat.service

    创建好了,重载一下

    systemctl daemon-reload

    设置开机自启

     systemctl enable tomcat

    另外,需要改8080端口,在server.xml里修改。

     更改jvm的设置,默认最大是256m,改为实际物理内存的80%,这个在tomcat的bin目录的catalina.sh文件中修改,加在有效代码的第一行之前。

    JAVA_OPTS="-server -Xms512m -Xmx768m -XX:NewSize=128m -XX:MaxNewSize=192m -XX:SurvivorRatio=8"
  • 相关阅读:
    【Python学习之七】递归——汉诺塔问题的算法理解
    【Python学习之六】高阶函数2(map、reduce、filter、sorted)
    【Python学习之五】高级特性5(切片、迭代、列表生成器、生成器、迭代器)
    【Python学习之五】高级特性4(切片、迭代、列表生成器、生成器、迭代器)
    【Python学习之五】高级特性3(切片、迭代、列表生成器、生成器、迭代器)
    【Python学习之五】高级特性2(切片、迭代、列表生成器、生成器、迭代器)
    【Python学习之五】高级特性1(切片、迭代、列表生成器、生成器、迭代器)
    【Python学习之四】递归与尾递归
    Golang 调度器GPM原理与调度分配
    Mongo索引优化
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/12172739.html
Copyright © 2020-2023  润新知