併發網伺服器遷移

ali清英發表於2016-04-05

本月將併發程式設計網站遷移到UCloud雲服務,本文是遷移的步驟,希望對其他同學有所幫助。

第一步:安裝軟體

軟體包括php,mysql和nginx。

yum -y install  php php-fpm mysql nginx lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy

第二步:軟體配置

2.1 配置nginx

vi /etc/nginx/nginx.conf

user            www www;
worker_processes  8;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections  65535;
}
http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;
log_format  main  `$remote_addr - $remote_user [$time_local] "$request" `
`$request_time $upstream_response_time`
`$status $body_bytes_sent "$http_referer" `
`"$http_user_agent" "$http_x_forwarded_for"`;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 10M;
sendfile on;
tcp_nopush     on;
keepalive_timeout 30;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;
gzip on;
 gzip_min_length 1k;
 gzip_buffers 4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types text/plain application/x-javascript text/css application/xml;
 gzip_vary on;
server
 {
 listen 80;
 server_name ifeve.com www.ifeve.com;
 index index.html index.htm index.php;
 try_files $uri $uri/ /index.php?q=$uri&$args;
 root /home/www/ifeve;
#include wp_params_supercache.conf;
location ~ .*.(php|php5)?$
 {
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 include fcgi.conf;
 }
}
 }

2.2 配置php-fpm

vi /etc/php-fpm.d/www.conf
;Start a new pool named `www`.
 [www]
; The address on which to accept FastCGI requests.
 ; Valid syntaxes are:
 ; `ip.add.re.ss:port` - to listen on a TCP socket to a specific address on
 ; a specific port;
 ; `port` - to listen on a TCP socket to all addresses on a
 ; specific port;
 ; `/path/to/unix/socket` - to listen on a unix socket.
 ; Note: This value is mandatory.
 listen = 127.0.0.1:9000
; Set listen(2) backlog. A value of `-1` means unlimited.
 ; Default Value: -1
 listen.backlog = 102400
; List of ipv4 addresses of FastCGI clients which are allowed to connect.
 ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
 ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
 ; must be separated by a comma. If this value is left blank, connections will be
 ; accepted from any ip address.
 ; Default Value: any
 listen.allowed_clients = 127.0.0.1,120.132.54.203,115.192.118.9
; Set permissions for unix socket, if one is used. In Linux, read/write
 ; permissions must be set in order to allow connections from a web server. Many
 ; BSD-derived systems allow connections regardless of permissions.
 ; Default Values: user and group are set as the running user
 ; mode is set to 0666
 ;listen.owner = nobody
 ;listen.group = nobody
 listen.mode = 0666
; Unix user/group of processes
 ; Note: The user is mandatory. If the group is not set, the default user`s group
 ; will be used.
 /pi
 ; be killed. This option should be used when the `max_execution_time` ini option
 ; does not stop script execution for some reason. A value of `0` means `off`.
 ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
 ; Default Value: 0
 request_terminate_timeout = 3s
; The timeout for serving a single request after which a PHP backtrace will be
 ; dumped to the `slowlog` file. A value of `0s` means `off`.
 ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
 ; Default Value: 0
 request_slowlog_timeout = 3s
; The log file for slow requests
 ; Default Value: not set
 ; Note: slowlog is mandatory if request_slowlog_timeout is set
 slowlog = /var/log/php-fpm/www-slow.log
; Set open file descriptor rlimit.
 ; Default Value: system defined value
 rlimit_files = 102400
; Set max core size rlimit.
 ; Possible Values: `unlimited` or an integer greater or equal to 0
 ; Default Value: system defined value
 rlimit_core = 0
; Chroot to this directory at the start. This value must be defined as an
 ; absolute path. When this value is not set, chroot is not used.
 ; Note: chrooting is a great security feature and should be used whenever
 ; possible. However, all PHP paths will be relative to the chroot
 ; (error_log, sessions.save_path, ...).
 ; Default Value: not set
 ;chroot =
; Chdir to this directory at the start. This value must be an absolute path.
 ; Default Value: current directory or / when chroot
 ;chdir = /var/www

第三步:遷移資料和網站

3.1 遷移資料庫

  • 在舊伺服器中匯出ifeve資料庫:mysql -f -h localhost -uroot -pifevepassword  ifeve > ifevedb_backup.sql
  • 在新伺服器中設定新mysql的預設密碼:mysqladmin -u root password 123
  • 在新伺服器中建立ifeve資料庫:mysqladmin -h localhost -u root -p create ifeve
  • 在新伺服器中匯入ifeve資料庫:mysql -f -h localhost -uroot -pifevepassword  ifeve < ifevedb_backup.sql

3.2 遷移網站

scp -r 192.168.0.1:/home/www/ifeve  192.168.0.2:/home/www/

3.3 設定目錄許可權

  • chown -R  www.www /home/www/ifeve
  • chmod -R 755 /home/www/ifeve

第四步:啟動應用

  • service php-fpm restart
  • service nginx restart
  • service mysqld restart

恭喜你遷移完成。


相關文章