Secondary Study Notes of the qingting Resin server

Source: Internet
Author: User
Tags jconsole

The following content is reproduced from http://blog.csdn.net/ndcs_dhf2008/article/details/5709386

Resin installation and configuration optimization

1. Resin installation and auto-Start Settings
Create boot auto start
CP contrib/init. Resin/etc/rc. d/init. d/resin

VI/etc/rc. d/init. d/resin

Set the correct path
Java_home =/usr/local/jdk1.6.0 _ 13

Resin_home =/usr/local/resin-3.1.8

Grant executable permissions
Chmod + x/etc/rc. d/init. d/resin

Add as self-starting service:
Chkconfig -- add Resin

Chkconfig -- level 35 Resin on

Service resin start

Solve the Service Startup error: log_daemon_msg: Command not found

Comment out the called part of the function and use echo instead. For example:
Log_daemon_msg "resin start"

Change
Echo "resin start"

After modification, you can use service resin start/stop/restart to execute related commands.
 

2. Set the resin. conf parameter and JVM settings

<JVM-Arg>-xmx4096m </JVM-Arg>

<JVM-Arg>-xms4096m </JVM-Arg>

<JVM-Arg>-xmn512m </JVM-Arg>

<JVM-Arg>-xss50m </JVM-Arg>

<JVM-Arg>-XX: permsize = 768 m </JVM-Arg>

<JVM-Arg>-XX: maxpermsize = 768 m </JVM-Arg>

<JVM-Arg>-XX: Required vorratio = 8 </JVM-Arg>

<JVM-Arg>-XX: maxtenuringthreshold = 7 </JVM-Arg>

<JVM-Arg>-XX: gctimeratio = 19 </JVM-Arg>

<JVM-Arg>-XX: + useparnewgc </JVM-Arg>

<JVM-Arg>-XX: + useconcmarksweepgc </JVM-Arg>

<JVM-Arg>-XX: + cmspermgensweepingenabled </JVM-Arg>

<JVM-Arg>-XX: + cmsclassunloadingenabled </JVM-Arg>

<JVM-Arg>-XX: + usecmscompactatfullcollection </JVM-Arg>

<JVM-Arg>-XX: cmsfullgcsbeforecompaction = 2 </JVM-Arg>

<JVM-Arg>-XX:-cmsparallelremarkenabled </JVM-Arg>

<JVM-Arg>-XX: + disableexplicitgc </JVM-Arg>

<JVM-Arg>-XX: cmsinitiatingoccupancyfraction = 70 </JVM-Arg>
 

<JVM-Arg>-XX: softreflrupolicymspermb = 0 </JVM-Arg>

<JVM-Arg>-XX: + printclasshistogram </JVM-Arg>

<JVM-Arg>-XX: + printgcdetails </JVM-Arg>

<JVM-Arg>-XX: + printgctimestamps </JVM-Arg> <JVM-Arg>-XX: + printgcapplicationconcurrenttime </JVM-Arg>

<JVM-Arg>-XX: + printgcapplicationstoppedtime </JVM-Arg>

<JVM-Arg>-xloggc: log/GC. Log </JVM-Arg>

<JVM-Arg>-xdebug </JVM-Arg>

<JVM-Arg>-DCOM. Sun. Management. jmxremote </JVM-Arg>
 

Memory Configuration:
<Memory-free-min> 5 m </memory-free-min>

Maximum number of threads
<! -- Maximum number of threads. -->

<Thread-max> 1024 </thread-max>

<! -- Configures the socket timeout -->

<Socket-Timeout> 65 S </socket-Timeout>

Configure the most active connection and timeout
<! -- Configures the keepalive -->

<Keepalive-max> 2048 </keepalive-max>

Keepalive-Timeout> 15 S </keepalive-Timeout>

3. Configure jconsole to monitor JVM
$ Java_home/JRE/lib/management/jmxremote. Password. template is the file that sets the user and password for remote connection,
CP $ java_home/JRE/lib/management/jmxremote. Password. template $ java_home/jconsole/jmxremote. Password
Chmod 600 $ java_home/jconsole/jmxremote. Password
VI jmxremote. Password
Remove the comments before # monitorrole red and change red to the password you want to set. Add the following configuration in resin. conf. the IP address of the monitored host must be the same as that of the host.

<JVM-Arg>-DCOM. Sun. Management. jmxremote. Port = 12345 </JVM-Arg>

<JVM-Arg>-DCOM. Sun. Management. jmxremote. SSL = false </JVM-Arg>

<JVM-Arg>-DCOM. sun. management. jmxremote. access. file =/usr/local/jdk1.6.0 _ 13/JRE/lib/management/jmxremote. access </JVM-Arg> <JVM-Arg>-DCOM. sun. management. jmxremote. password. file =/usr/local/jdk1.6.0 _ 13/JRE/lib/management/jmxremote. password </JVM-Arg>

<JVM-Arg>-DCOM. Sun. Management. jmxremote. Authenticate = true </JVM-Arg>

<JVM-Arg>-djava. RMI. server. hostname = 192.168.100.9 </JVM-Arg>
 

You do not need to set it on the client. Start jconsole.exe In the JDK installation directory (<jdk_home>/bin/jconsole.exe) to open the main interface. Enter the 192.168.100.9: 12345 username and password to view information about JVM on the monitoring page. Operation

Double-click jconsole.exe start connection dialog box

 

4. Configure the resin backend Management
<Management Path = "$ {resin. Root}/admin">

<User name = "admin" Password = "mnhpobdovrmoy?woa5w7a ="/>

<Resin: If test = "$ {resin. Professional}">

<Deploy-service/>

<JMX-service/>

<Log-service/>

<XA-log-service/>

</Resin: If>

</Management>

<Web-app id = "/resin-admin" Root-directory = "$ {resin. Home}/PHP/admin">

<! --

-Administration application/resin-Admin -->

<Prologue>

<Resin: Set Var = "resin_admin_user" value = "admin"/>

<Resin: Set Var = "resin_admin_password" value = "password"/>

<Resin: Set Var = "resin_admin_external" value = "true"/>

<Resin: Set Var = "resin_admin_insecure" value = "true"/>

</Prologue>

</Web-app>

Ii. Network Optimization
1. Reduce the time-Wait or close-Wait packet in the TCP Connection
Add the following configurations to VIM/etc/sysctl. conf:

Net. ipv4.tcp _ syncookies = 1

Net. ipv4.tcp _ tw_reuse = 1

Net. ipv4.tcp _ tw_recycle = 1

Net. ipv4.tcp _ fin_timeout = 15

Net. ipv4.tcp _ keepalive_time = 1200

Net. ipv4.tcp _ keepalive_probes = 5

Net. ipv4.tcp _ keepalive_intvl = 15

 
 

Configuration attributes:
Net. ipv4.tcp _ syncookies = 1 indicates enabling syn cookies. When a SYN wait queue overflows, cookies are enabled to prevent a small number of SYN attacks. The default value is 0, indicating that the process is disabled;
Net. ipv4.tcp _ tw_reuse = 1 indicates enabling reuse. Allow time-Wait sockets to be re-used for a New TCP connection. The default value is 0, indicating that the TCP connection is disabled;
Net. ipv4.tcp _ tw_recycle = 1 indicates to enable quick recovery of Time-Wait sockets in TCP connections. The default value is 0, indicating to disable it.
Tcp_syn_retries: integer
The default value is 5.
For a new connection, the kernel determines how many syn connection requests are sent before giving up. It should not be greater than 255. The default value is 5, corresponding to the left-right time of 180 seconds. (For a network with high load and good physical communication, this value is too high and can be changed to 2. This value is only for external connections. The incoming connections are determined by tcp_retries1)

Tcp_synack_retries: integer
The default value is 5.
For the remote connection request SYN, the kernel sends the SYN + ACK datagram to confirm receipt of the previous SYN connection request packet. This is the second step of the so-called threeway handshake mechanism. The number of SYN + ACK sent by the kernel before the connection is abandoned. It should not be greater than 255. The default value is 5, corresponding to the left-right time of 180 seconds. (This value can be determined based on the above tcp_syn_retries)

Tcp_keepalive_time: integer
The default value is 7200 (2 hours)
When keepalive is enabled, the frequency at which TCP sends the keepalive message. (Due to factors such as network attacks, this attack is very frequent. Some Cu friends once mentioned that if a connection is established on both sides, if no data or RST/FIN messages are sent, will the duration be 2 hours or empty connection attacks? Tcp_keepalive_time is used to prevent this situation. I personally changed the value to 1800 seconds when performing the NAT service)

Tcp_keepalive_probes: integer
The default value is 9.
TCP sends a keepalive test to determine the number of times the connection has been disconnected. (Note: It is sent only when the so_keepalive socket option is enabled. The number of requests does not need to be modified by default. Of course, this value can be shortened as appropriate. It is more appropriate to set it to 5)

Tcp_keepalive_intvl: integer
The default value is 75.
The frequency of probe message sending. Multiply by tcp_keepalive_probes to get the time for the connection that has not responded since the start of the probe. The default value is 75 seconds, indicating that connections without activity will be dropped after about 11 minutes. (For common applications, this value is too large and can be changed as needed. Especially for Web servers, this value needs to be changed to a smaller value. 15 is a suitable value)

Run the following command to make the modification take effect immediately:/sbin/sysctl-P
Use the following statement to check the TCP status of the server:
Netstat-N | awk '/^ TCP/{++ s [$ NF]} end {for (a in S) print a, s [a]}'

3. Solve the too program open files Problem
Too program open files has two problems:
One is that it appears during search, most of which is because the index has been moved after it is created. If this error is not found during index creation, it will not appear during search. If so, there are two solutions: Modify the merging factor and the minimum merging factor, and use
Indexwriter. Optimize () Optimizes the index, which reduces the number of index files to the file system limit. Another way is to modify the limit on the number of files opened by the operating system. The method is as follows:
Set the system according to the maximum number of opened files, and check the/proc/sys/fs/file-Max file to confirm that the maximum number of opened files has been set correctly. The configuration procedure is as follows:
# Cat/proc/sys/fs/file-max
If the value is too small, modify the variable of the file/etc/sysctl. conf to the appropriate value. This will take effect after each restart.
# Echo 65535>/proc/sys/fs/file-max
Edit the/etc/sysctl. conf file and insert it to the downstream file.
FS. File-max = 65535

Run sysctl-P.
Set ulimit-N 65535
Set the maximum number of opened files in the/etc/security/limits. conf file. The following is a line of prompt:
#
Add the following line.
*-Nofile 65535
This line sets the default number of files opened by each user to 2048. Note that "nofile" has two possible restrictions. Is hard and soft under the item. To make the maximum number of files opened after modification take effect, you must set these two restrictions. If the "-" character is used, both hard and soft settings are set.
Hard limit indicates the maximum value that can be set in the soft limit. The soft limit refers to the setting value that takes effect for the current system. The hard limit value can be reduced by common users. But cannot be added. Soft restrictions cannot be set more than hard restrictions. Only root users can increase the hard limit value.
When the file limit description is added, you can simply double the current value. The example is as follows. If you want to increase the default value by 1024, it is best to increase it to 2048. If you want to continue to increase it, you need to set it to 4096.
Another case is that there are two possibilities when creating an index. One is that the merge factor is too small, resulting in the number of files created exceeds the operating system limit. In this case, you can modify the merge factor, you can also modify the limit on the number of files opened by the operating system. The other is that the merging factor is limited by the memory of the Virtual Machine and cannot be adjusted to a greater value. The number of DOC files to be indexed is very large, in this case, you can only modify the limit on the number of files opened by the operating system.

During System Access peak hours, run the following script as the root user. The possible results are as follows:
# Lsof-N | awk '{print $2}' | sort | uniq-c | sort-Nr | more

131 24204

57 24244

The first line is the number of opened file handles, and the second line is the process number. After obtaining the process number, we can use the ps command to get the detailed content of the process.
PS-AEF | grep 24204

MySQL 24204 24162 99? 00:24:25/usr/sbin/mysqld

By default, a maximum of 1024 file handles can be opened. However, if the system concurrency is very large, especially the squid server, it is likely to exceed 1024. At this time, you must adjust the system parameters to adapt to application changes. Linux has hard and soft limits. You can use ulimit to set these two parameters. Run the following command as the root user:
In the command above ulimit-HSN 4096, H specifies the hard size, s specifies the soft size, and N indicates setting the maximum number of open file handles for a single process. After the number of handles is set, the default value is restored after the system restarts. If you want to save it permanently,/etc/security/limits. conf

This section is a customized shell script (centos6_64bit) for resin services.

#!/bin/sh## Linux startup script for Resin# chkconfig: 345 85 15# description: Resin is a Java Web server.# processname: wrapper.pl## To install, configure this file as needed and copy init.resin# to /etc/rc.d/init.d as resin.  Then use "# /sbin/chkconfig resin reset"#JAVA_HOME=/usr/local/java/jdk1.6.0_26# RESIN_HOME=/root/resin-3.1.8 RESIN_HOME=/usr/local/resinexport JAVA_HOME RESIN_HOMEJAVA=$JAVA_HOME/bin/java## If you want to start the entire Resin process as a different user,# set this to the user name.  If you need to bind to a protected port,# e.g. port 80, you can't use USER, but will need to use bin/resin.#USER=## Set to the server id to start##SERVER="-server app-a"#ARGS="-resin-home $RESIN_HOME $SERVER"# if test -r /lib/lsb/init-functions; then#  . /lib/lsb/init-functions# else  log_daemon_msg () {      if [ -z "$1" ]; then          return 1      fi      if [ -z "$2" ]; then          echo -n "$1:"          return      fi      echo -n "$1: $2"  }  log_end_msg () {      [ -z "$1" ] && return 1      if [ $1 -eq 0 ]; then         echo "!!!!!"      else        echo " Failed!"      fi    return $1  }#ficase "$1" in  start)        #       log_daemon_msg "Starting resin"        echo "Strating resin"        if test -n "$USER"; then          su $USER -c "$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS start" 1>/dev/null 2>/dev/null        else          $JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS start 1>/dev/null 2>/dev/null        fi        log_end_msg $?        ;;  stop)#       log_daemon_msg "Stopping resin"        echo "Stopping resin"        if test -n "$USER"; then          su $USER -c "$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS stop" 1>/dev/null 2>/dev/null        else          $JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS stop 1>/dev/null 2>/dev/null        fi        log_end_msg $?        ;;  restart)        $0 stop        $0 start        ;;  *)        echo "Usage: $0 {start|stop|restart}"        exit 1esacexit 0

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.