并发网服务器迁移

本月将并发编程网站迁移到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

恭喜你迁移完成。

查询各种日志

  • tail -fn 5 /var/log/nginx/error.log
  • tail -fn 5 /var/log/nginx/access.log
  • tail -fn 500 /var/log/php-fpm/error.log
  • tail -fn 5 /var/log/php-fpm/www-slow.log

原创文章,转载请注明: 转载自并发编程网 – ifeve.com本文链接地址: 并发网服务器迁移

  • Trackback 关闭
  • 评论 (3)
    • cocode
    • 2015/01/13 10:44上午

    有没有可能通过docker运行,这样下次换服务商更方便

    • 木槿花萧
    • 2015/01/29 9:54下午

    网站迁用scp很巧妙。。

return top