ATS+Nginx+FastDFS

Recently, there is a requirement to use a picture server. For this requirement, if we use the company to unify the internal cluster, there is no problem at all, but unfortunately our services must be deployed to the public cloud, that is to say, the company's internal tools and services, we generally If you buy public cloud services and tools, you will need to increase the cost. Therefore, we built our own image server through physical machines.
         Technical selection: ATS+Nginx+FastDFS
         FastDFS is used as image storage, ATS is used as CDN, and the overall architecture is as follows:



         FastDFS architecture (from 51CTO network):
      
         ATS (from oschina)

finally performs stress testing
A physical machine, memory: 252G, hard disk: 600G+, cpu: 64 cores, network card: Gigabit dual network card, 160kb+ picture
network card is almost full, rt is 500ms, thread 500, ATS load is still very small, more than 90% of ATS local returns within 1ms, so the network card becomes The final bottleneck.




===================================================== ============
Attach some information:
AST log: /usr/local/var/log/trafficserver
AST configuration file: /usr/local/etc/trafficserver
FstDFS configuration file: /etc/fdfs /

sudo /usr/bin/fdfs_test /etc/fdfs/client.conf upload ~/pic/3.pic.jpg


http://sofar.blog.51cto.com/353572/1656160
http://blog.csdn.net/xifeijian/article/details/38567839/ FastDFS Installation, Configuration, Deployment (1) - Installation and Deploymenthttp
:// bbs.chinaunix.net/thread-1941456-1-1.html [FastDFS] Detailed explanation of FastDFS configuration file
http://bbs.go-news.com/thread-54-1-1.html Trafficserver5.3 installation configuration
http: //twiki.corp.taobao.com/pub/SRE/OPS/CdnATStest/TS_%E5%8A%9F%E8%83%BD%E6%B5%8B%E8%AF%95%E4%B9%8BCache. pdf Cache of TS functional test
https://linux.cn/article-3215-1.html dstat monitoring tool under Linux terminal
https://docs.trafficserver.apache.org/en/latest/admin-guide/monitoring/statistics /core/cache.en.html cache monitor


trafficserver-5.3.2.tar.bz2
tengine-1.5.2.tar.gz
libfastcommon-1.0.7.tar.gz
fastdfs-5.05.tar.gz
fastdfs-nginx-module_v1. 16.tar.gz
======
Monitoring:
sar -n DEV 2
dstat

./traffic_line -r proxy.node.cache_hit_ratio_avg_10s #Query the current cache service hit
rate./traffic_line -r proxy.node.current_server_connections #Number of connections to the backend source
. /traffic_line -r proxy.node.current_client_connections #Number of connections from front-end users to TServer./traffic_line
-r proxy.node.user_agent_xacts_per_second #Average number of concurrent processing per
second./traffic_line -r proxy.node.client_throughput_out #Current TServer output to Front-end bandwidth traffic (in Mbps)

=======
Traffic Server is a fast, modular HTTP/1.1 compatible reverse proxy server, similar to Nginx and Squid, the latest version released by the Apache Software Foundation is Apache Traffic Server v5.3.0. The processing power of Traffic Server is very powerful, it can handle terabytes of data in real deployment environments with very strict content transmission requirements.

Official website: http://trafficserver.apache.org/
http://apache.fayea.com/trafficserver/trafficserver-5.3.0.tar.bz2

1. Installation dependencies
# yum install tcl-devel pcre-devel

2. Source code compilation
# cd /usr/local/src
# wget http://apache.fayea.com/trafficserver/trafficserver-5.3.0.tar.bz2
# tar jxf trafficserver-5.3.0.tar.bz2
# cd trafficserver-5.3.0
# ./configure --prefix=/usr/local/trafficserver
# make make install
# cp rc/trafficserver /etc/init.d/# boot
# chmod 755 /etc/init.d/trafficserver && chkconfig --add trafficserver && chkconfig trafficserver on

3. Configure
the records.config main configuration file, which is a configuration file in key-value format, responsible for most of the global The option settings of
storage.config are used to specify disk storage.
remap.config defines mapping rules for request rewrite (rewrite), reverse proxy is here to configure

storage.config example
/data1/cache 256M
/data2/cache 256M
remap.config example
map http://www.go-news.com http://192.168.4.56

records.config details
#ts management username
CONFIG proxy.config.admin.admin_user STRING admin #Configuration
file Number of copies
CONFIG proxy.config.admin.number_config_bak INT 3 #Options
are used to specify the traffic_server process to run, and can also be used to specify the ownership of configuration files and log files
CONFIG proxy.config.admin.user_id STRING nobody

##### ################################################## #########################
# Thread configurations. Docs:
# https://docs.trafficserver.apach ... c-thread-autoconfig
### ################################################## ###########################
# The number of TS threads is adjusted according to the number of available CPU cores. The default value is 1, which means it is enabled.
CONFIG proxy.config.exec_thread.autoconfig INT 1
# The above configuration is enabled, the default ratio between the number of TS CPU cores and the number of TS threads, the default scaling ratio is 1.5. Number of CPU cores * scaling ratio = number of TS threads
CONFIG proxy.config.exec_thread.autoconfig.scale FLOAT 1.5
# When proxy.config.exec_thread.autoconfig value is 0, set the number of TS threads
CONFIG proxy.config.exec_thread.limit INT 2
# Set the number of SSL threads, the default is the product of the number of CPUs and proxy.config.exec_thread.autoconfig.scale.
# You can set a non-zero value
CONFIG proxy.config.ssl.number.threads INT 0
# Set to 1 when enabled to run a separate thread to handle requests. If disabled (0), then there is only one thread
CONFIG proxy.config.accept_threads INT 1
# Configure the thread pool for tasks, recommended 2
CONFIG proxy.config.task_threads INT 2
# Set how many I/O threads are allocated per disk
CONFIG proxy. config.cache.threads_per_disk INT 8
# https://docs.trafficserver.apach ... xec-thread-affinity
CONFIG proxy.config.exec_thread.affinity INT 0

##############################################################################
# Specify server addresses and ports to bind for HTTP and HTTPS. Docs:
#    https://docs.trafficserver.apach ... g-http-server-ports
##############################################################################
# 配置端口,默认8080
CONFIG proxy.config.http.server_ports STRING 80

##############################################################################
# Via: headers. Docs:
#     https://docs.trafficserver.apach ... rt-response-via-str
################################################## ############################
# Configure the processing method of the via field, 1 update via
CONFIG proxy.config.http with normal information .insert_request_via_str INT 1
# Configure how to handle the via field of the response to the client, 0 does not modify it
# 1 Update via with normal information
# 2 Update via with detailed information
# 3 Update via
CONFIG proxy.config with most detailed information. http.insert_response_via_str INT 0

############################################# #################################
# Parent proxy configuration, in addition to these settings also see parent.config. Docs :
# https://docs.trafficserver.apach...proxy-configuration
# https://docs.trafficserver.apach...rent.config.en.html
################################################## ############################
# Set to close the parent node
CONFIG proxy.config.http.parent_proxy_routing_enable INT 0
# When the parent node is unavailable, Set the retry time
CONFIG proxy.config.http.parent_proxy.retry_time INT 300
# When the parent node is unavailable, set the timeout time
CONFIG proxy.config.http.parent_proxy.connect_attempts_timeout INT 30
# Configure to send authentication information to the parent node
CONFIG proxy.config .http.forward.proxy_auth_to_parent INT 0
# Set uncacheable request to use bypass request parent node
CONFIG proxy.config.http.uncacheable_requests_bypass_parent INT 1

##################### ################################################## #######
# HTTP connection timeouts (secs). Docs:
# https://docs.trafficserver.apach ... connection-timeouts
################################################## ############################
# Specify the connection time that will continue to be opened after the transaction ends to ensure subsequent incoming requests
CONFIG proxy.config.http .keep_alive_no_activity_timeout_in INT 115
# Specify the connection time that will continue to be opened to ensure subsequent egress requests after the transaction ends.
CONFIG proxy.config.http.keep_alive_no_activity_timeout_out INT 120
# Specify how long the ts server will communicate with the client if there is network congestion (in) Disconnect
CONFIG proxy.config.http.transaction_no_activity_timeout_in INT 30
# Specify how long the ts server will disconnect from the client if there is network congestion (out)
CONFIG proxy.config.http.transaction_no_activity_timeout_out INT 30
# and the client The longest time to keep the connection (in)
CONFIG proxy.config.http.transaction_active_timeout_in INT 900
# The longest time to keep the connection with the client (out)
CONFIG proxy.config.http.transaction_active_timeout_out INT 0
# The timeout for closing no active connections time interval
CONFIG proxy.config.http.accept_no_activity_timeout INT 120
# Set connection idle timeout setting
CONFIG proxy.config.net.default_inactivity_timeout INT 86400

######################## ################################################## ####
# Origin server connect attempts. Docs:
# https://docs.trafficserver.apach ... er-connect-attempts
#################### ################################################## ########
# When the origin server does not respond, ts maximum number of retries
CONFIG proxy.config.http.connect_attempts_max_retries INT 6
# When the origin server is unavailable, ts maximum number of retries
CONFIG proxy.config.http. connect_attempts_max_retries_dead_server INT 3
# If the server DNS does round robin, the maximum number of failed connection attempts allowed before the round robin entry is marked down
CONFIG proxy.config.http.connect_attempts_rr_retries INT 3
# The timeout value of the origin server connection
CONFIG proxy.config.http.connect_attempts_timeout INT 30
# During POST/PUT request, the timeout value of the origin server
CONFIG proxy.config.http.post_connect_attempts_timeout INT 1800
# After specifying how long, the TS marks the origin server To down
CONFIG proxy.config.http.down_server.cache_time INT 300
# The number of seconds between when a client abandons the request because the origin server is too slow to respond to the TS marking the server unreachable
CONFIG proxy.config.http.down_server .abort_threshold INT 10

############################################## ################################
# Negative response caching, for redirects and errors. Docs:
# https://docs .trafficserver.apach ... ve-response-caching
###################################### ###############################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
# Enable/disable negative response caching. When TS caches a negative response (such as 404), when the next client requests the corresponding URL, the TS server will directly return a negative response
# Negative responses include: 204 305 400 403 404 405 500 501 502 503 504
CONFIG proxy.config.http.negative_caching_enabled INT 0
# Set cache negative response time
CONFIG proxy.config.http.negative_caching_lifetime INT 1800

##################### ################################################## #######
# Proxy users variables. Docs:
# https://docs.trafficserver.apach ... roxy-user-variables
################## ################################################## ##########
# After enabling, add Client_IP header to preserve client's IP address
CONFIG proxy.config.http.anonymize_insert_client_ip INT 1
# After enabling, add client's IP address to x-forward-for
CONFIG proxy.config.http.insert_squid_x_forwarded_for INT 1
##############################################################################
# Security. Docs:
#    https://docs.trafficserver.apache.org/records.config#security
##############################################################################
# 启用/禁用HTTP PUSH的选项
CONFIG proxy.config.http.push_method_enabled INT 0

##############################################################################
# Enable / disable HTTP caching. Useful for testing, but also as an
# overridable (per remap) config
##############################################################################
# 配置开启http缓存
CONFIG proxy.config.http.cache.http INT 1

################################################## ############################
# Cache control. Docs:
# https://docs.trafficserver.apach ... onfig#cache -control
# https://docs.trafficserver.apach ... ache.config.en.html
############################ ##################################################
# Whether to ignore max-age headers in all clients
CONFIG proxy.config.http.cache.ignore_client_cc_max_age INT 1
# Normalize all Accept-Encoding headers when enabled
CONFIG proxy.config.http.normalize_ae_gzip INT 1
# Cache response cookies The five options
# 0 - don't cache all cookies for responses
# 1 - cache only content-type
# 2 - cache only images
# 3 - cache all text content-types
# 4 - cache for all but system responses without "Set-Cookie " or a literal content-type with "Cache-Control: public"
# ts cache cookies operation
CONFIG proxy.config.http.cache.cache_responses_to_cookies INT 1
# Cache dynamic file content
CONFIG proxy.config.http.cache.cache_urls_that_look_dynamic INT 1
# https://docs.trafficserver.apach ... -when- to-revalidate
# 5 options to revalidate content
# 0 - default. Use cache directive or heuristic cache
# 1 - heuristic cache
# 2 - always stale (always revalidate)
# 3 - don't refresh
# 4 - Validate if the request contains a condition, otherwise use the default
# If the request contains If-Modified-since, then TS always re-validates the cached content,
# and uses the If-Modified-Since header of the client's proxy request .
# TS revalidation cache mechanism
CONFIG proxy.config.http.cache.when_to_revalidate INT 0
# https://docs.trafficserver.apach ... he-required-headers
# Header required to configure TS cache
# Required header The three options:
# 0 - don't need to use headers to decide whether a document can be cached or not
# 1 - Requires Last-Modified:", "Expires:", or "Cache-Control: max-age"
# 2 - Explicit cache lifetime needs, "Expires:" or "Cache- Control: max-age
CONFIG proxy.config.http.cache.required_headers INT 2

################################# #############################################
# Heuristic cache expiration. Docs:
# https://docs.trafficserver.apach ... euristic-expiration
################################ ##############################################
# one in the cache The minimum time that an object with no expiration and no expiration time in the cache can be kept
CONFIG proxy.config.http.cache.heuristic_min_lifetime INT 3600
# The maximum time an object with no expiration and no expiration time can be kept in the cache
CONFIG proxy.config.http.cache.heuristic_max_lifetime INT 86400
# Set this variable to specify the aging factor for calculating the validity period. TS stores this percentage of time since the object was last modified. Default is 0.1
CONFIG proxy.config.http.cache.heuristic_lm_factor FLOAT 0.10

################################## ############################################
# Network. Docs:
# https://docs.trafficserver.apache.org/records.config#network
############################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################ #############################################
# Configure maximum network connections limit
CONFIG proxy.config.net.connections_throttle INT 30000

####################################### #######################################
# RAM and disk cache configurations. Docs:
# https ://docs.trafficserver.apache.org/records.config#ram-cache
# https://docs.trafficserver.apach ... rage.config.en.html
################################################## ############################
# Set RAM cache size
CONFIG proxy.config.cache.ram_cache.size INT -1
# Used to determine The size of the object written to the cache, only objects smaller than this value will be cached, the default is 4M
CONFIG proxy.config.cache.ram_cache_cutoff INT 4194304
# https://docs.trafficserver.apach ... imits-http-max-alts
# Specify the number of different versions of an object that TS caches. Default is: 5
CONFIG proxy.config.cache.limits.http.max_alts INT 5
# https://docs.trafficserver.apach ... -cache-max-doc-size
# Maximum file size stored in cache, set Set to 0 to disable maximum size checking
CONFIG proxy.config.cache.max_doc_size INT 0
# Configure minimum, average object size. Default is 8000
CONFIG proxy.config.cache.min_average_object_size INT 8000

################################################## ############################
# Logging Config. Docs:
# https://docs.trafficserver.apach ... gging-configuration
# https://docs.trafficserver.apach ... _xml.config.en.html
############################## ################################################
# On Custom log options
CONFIG proxy.config.log.custom_logs_enabled INT 1
# Enabled logging:
# 0: No logging at all
# 1: Log errors only
# 2: Log only transaction logs
# 3: Log all (errors and transactions)
CONFIG proxy.config.log.logging_enabled INT 0
# The size of the space allocated to the log directory (MB)
CONFIG proxy.config.log.max_space_mb_for_logs INT 25000
# Used to prevent the disk from being filled with logs
CONFIG proxy.config.log.max_space_mb_headroom INT 1000
# Enable/disable squid log format
CONFIG proxy.config.log.squid_log_enabled INT 0
# squid log format type. 1=ASCII 2=binary
CONFIG proxy.config.log.squid_log_is_ascii INT 0
# log file scrolling
# 0 - disable log file scrolling
# 1 - enable log file scrolling at specific time intervals. (requires proxy.config .log.rolling_interval_sec and proxy.config.log.rolling_offset_hr)
# 2 - Enable rolling of log files at specified file size (requires proxy.config.log.rolling_size_mb)
# 3 - Enable at specified file size or specific time interval Rolling log files (whichever occurs first)
# 4 - Enables rolling of log files when they reach a certain size in the specified interval
CONFIG proxy.config.log.rolling_enabled INT 1
# Log rolling interval in seconds. The minimum is 300 seconds, and the maximum is 86400, which is 1 day
. CONFIG proxy.config.log.rolling_interval_sec INT 86400
# Roll the log when the log file size is large.
CONFIG proxy.config.log.rolling_size_mb INT 10
# Whether to enable the automatic rolling of the file delete
CONFIG proxy.config.log.auto_delete_rolled_files INT 1

######################################## ######################################
# These settings control remapping, and if the proxy allows ( open) forward proxy or not. Docs:
# https://docs.trafficserver.apach ... fig#url-remap-rules
# https://docs.trafficserver.apach ... emap.config.en.html
# ################################################## ###########################
# When set to 1, remap.config of the mapping rules if you want TS to serve requests from the origin server CONFIG listed in the file
proxy.config.url_remap.remap_required INT 1
# https://docs.trafficserver.apach ... p-pristine-host-hdr
# When set to 1, will keep the client host on the remap request header, default is 0
CONFIG proxy.config.url_remap.pristine_host_hdr INT 1
# https://docs.trafficserver.apach ... onfig#reverse-proxy
# Enable/disable http reverse proxy
CONFIG proxy.config.reverse_proxy.enabled INT 1

############# ################################################## ###############
# SSL Termination. Docs:
# https://docs.trafficserver.apach ... lated-configuration
# https://docs.trafficserver.apach ... cert.config.en.html
########################################### ###################################
# Configure the CA CONFIG for TS to verify the origin server certificate
proxy.config.ssl .client.verify.server INT 0
# Specify the location of the CA-issued file
CONFIG proxy.config.ssl.client.CA.cert.filename STRING NULL
# The following two changes set the encryption method used by TS to use the HTTPS connection
CONFIG proxy.config.ssl.server.cipher_suite STRING ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM -SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:RC4-MD5:AES128-SHA:AES256-SHA:DES -CBC3-SHA!SRP:!DSS:!PSK:!aNULL:!eNULL:!SSLv2

############################# #################################################
# ICP Configuration. Docs:
# https://docs.trafficserver.apach ... g#icp-configuration
# https://docs.trafficserver.apach ... /icp.config.en.html
###### ################################################## ######################
# ICP mode
# 0 = ICP is disabled
# 1 = ICP query is allowed to be received
# 2 = ICP query is allowed to be sent and received
CONFIG proxy.config.icp.enabled INT 0

######################################## ######################################
# Debugging. Docs:
# https://docs. trafficserver.apach ... gging-configuration
######################################### #####################################
# You can use regular expressions to match debug theme names, But the corresponding performance will also be affected
. CONFIG proxy.config.diags.debug.enabled INT 0
# Match http dns characters
CONFIG proxy.config.diags.debug.tags STRING http.*|dns.*
# ToDo: Undocumented
# Tracking A weapon for memory leaks, but you need to use the ink allocator
CONFIG proxy.config.dump_mem_info_frequency INT 0
# Threshold for recording slow logs. When the request is greater than how many milliseconds, it will be recorded in the slow log. When the parameter value is greater than 0,
CONFIG proxy is enabled .config.http.slow.log.threshold INT 0

################################################## ############################
# Cluster Subsystem. Docs:
# https://docs.trafficserver.apache.org/records.config #cluster
################################################ ##############################
# The cluster type needs to be restarted to take effect
# 1=full cluster mode
# 2=management mode
# 3 =Non-cluster mode
LOCAL proxy.local.cluster.type INT 3
# Set the cluster mode Ethernet port
CONFIG proxy.config.cluster.ethernet_interface STRING lo
# Set the cluster port
CONFIG proxy.config.cluster.cluster_port INT 8086
# Configure reliable Service port. Reliable port is used to send configuration information between cluster nodes. All cluster nodes must use the same reliable service port
CONFIG proxy.config.cluster.rsport INT 8088
# Specify the multicast port. Multicast ports are used for node identification. All nodes in the cluster must use the same multicast port
CONFIG proxy.config.cluster.mcport INT 8089
# Specify a multicast address
CONFIG proxy.config.cluster.mc_group_addr STRING 224.0.1.37

4. Clear cache configuration
Edit the IP to be added in the configuration file
ip_allow.config
src_ip=127.0.0.1 action =ip_allow method=ALL

clear a single url
curl -X PURGE -v http://www.go-news.com/ -x 127.0.0.1:80
clear all caches
stop server
/usr/local/trafficserver/bin/traffic_server -Cclear
Start the server

5. Common commands
#Query the current cache service hit rate
/usr/local/trafficserver/bin/traffic_line -r proxy.node.cache_hit_ratio_avg_10s #Number
of connections to the backend source
/usr/local/trafficserver/bin/traffic_line -r proxy.node.current_server_connections
#Number of connections from front-end users to TServer
/usr/local/trafficserver/bin/traffic_line -r proxy.node.current_client_connections #The
average number of concurrency processed per second
/usr/local/trafficserver/bin/traffic_line -r proxy.node.user_agent_xacts_per_second
#Current TServer output bandwidth to the front end Traffic (in Mbps)
/usr/local/trafficserver/bin/traffic_line -r proxy.node.client_throughput_out #View
the value of the configuration
/usr/local/trafficserver/bin/traffic_line -r Variable name #Modify
the configuration
/usr/local/trafficserver /bin/traffic_line -s variable name -v variable value #Reread
the configuration file
/usr/local/trafficserver/bin/traffic_line -x #Make
the configuration take effect without restarting the service
/usr/local/trafficserver/bin/traffic_line -L

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326857262&siteId=291194637