Linux Command records used for vps migration

Source: Internet
Author: User
Tags exit in import database yum repolist

Vps migration is a problem that many webmasters may encounter, below I will sort out and record some problems encountered by a webmaster during the migration of vps machines and the data migration commands to avoid convenient and direct use.

Because the previous Legu crowd could not find the old nest, the official website was suspended, and the Internet said it was running. Although someone had previously contacted me and said they had taken over from their company, when there was a problem, but no one is found. Therefore, we decided to change the vps. Briefly record the commands used for this vps migration.

The new vps is centos 32.
Change Password after login

After connecting to ssh, the first thing is to change the root password. The command used is passwd.

You can enter a new password twice in a row.
Add new user www

The password for passwd www to continue data www. You can add
Install the software package command Yum

The ubuntu package management software is app-get, and the centos package management software is yum. Because my vps is centos, yum is used.

The Code is as follows: Copy code

# Installation
Yum install xxx
# Delete
Yum remove httpd

Because I use lnmp, you can delete apache installed by default and use yum remove httpd.
Use screen to manage conversations

Often, when the network connection is poor and ssh is interrupted, the program is not sure whether it will succeed, so screen is available. If you have no command to use screen -- help, install the following command:

Yum install screen
Common screen commands

The Code is as follows: Copy code

# Create a screen Dialog
Screen-S lnmp
# View the currently running screen
Screen-ls
# Reading a screen
Screen-r lnmp
# Exit screen and execute exit in the current screen
Exit

Install lnmp

The Code is as follows: Copy code

Run the following command in CentOS: wget-c http://soft.vpser.net/lnmp/lnmp1.0-full.tar.gz & tar zxvf lnmp1.0-full.tar.gz & cd lnmp1.0-full &./centos. sh
Run the following command In Debian: wget-c http://soft.vpser.net/lnmp/lnmp1.0-full.tar.gz & tar zxvf lnmp1.0-full.tar.gz & cd lnmp1.0-full &./debian. sh
Run: wget-c http://soft.vpser.net/lnmp/lnmp1.0-full.tar.gz & tar zxvf lnmp1.0-full.tar.gz & cd lnmp1.0-full &./Ubuntu. sh

You may need to select the php version, mysql version, and mysql root Password.
Lnmp status management command

LNMP status management:/root/lnmp {start | stop | reload | restart | kill | status}
Nginx status management:/etc/init. d/nginx {start | stop | reload | restart}
MySQL status management:/etc/init. d/mysql {start | stop | restart | reload | force-reload | status}
Memcached status management:/etc/init. d/memcached {start | stop | restart}
PHP-FPM status management:/etc/init. d/php-fpm {start | stop | quit | restart | reload | logrotate}
PureFTPd status management:/etc/init. d/pureftpd {start | stop | restart | kill | status}
ProFTPd status management:/etc/init. d/proftpd {start | stop | restart | reload}

For example, restart LNMP and run/root/lnmp restart to restart mysql:/etc/init. d/mysql restart separately.

It takes about an hour to get the network speed of your vps)
LNMP-related software installation directory

Nginx Directory:/usr/local/nginx/
MySQL Directory:/usr/local/mysql/
MySQL database Directory:/usr/local/mysql/var/
PHP Directory:/usr/local/php/
PHPMyAdmin Directory: For version 0.9,/home/wwwroot/phpmyadmin/1.0 is/home/wwwroot/default/phpmyadmin/. We strongly recommend that you rename this directory as a name that is hard to guess. Phpmyadmin can download and replace the new version from the official website.
Default website directory:/home/wwwroot/0.9/home/wwwroot/default/
Nginx log directory:/home/wwwlogs/
/Root/vhost. sh:/usr/local/nginx/conf/vhost/
PureFtpd Directory:/usr/local/pureftpd/
PureFtpd web management Directory:/home/wwwroot/default/ftp/0.9/home/wwwroot/default/ftp/
Proftpd Directory:/usr/local/proftpd/
LNMP configuration file location

Nginx main configuration file:/usr/local/nginx/conf/nginx. conf
/Root/vhost. sh:/usr/local/nginx/conf/vhost/Domain Name. conf
MySQL configuration file:/etc/my. cnf
PHP configuration file:/usr/local/php/etc/php. ini
Php-fpm configuration file:/usr/local/php/etc/php-fpm.conf
PureFtpd configuration file:/usr/local/pureftpd/pure-ftpd.conf
PureFtpd MySQL profile:/usr/local/pureftpd/pureftpd-mysql.conf
Proftpd configuration file:/usr/local/proftpd/etc/proftpd. conf
Proftpd user configuration file:/usr/local/proftpd/etc/vhost/user name. conf
LNMPA directory file location

Apache directory:/usr/local/apache/
Apache configuration file:/usr/local/apache/conf/httpd. conf
Apache Virtual Host Configuration File directory:/usr/local/apache/conf/vhost/
Install nodejs

As a front-end, of course, to install nodejs, but centos can not be as convenient as ubuntu so use apt-get, and need to compile your own, and later on the nodejs official website saw centos can also use package management: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

Execute the following commands in the command line:

The Code is as follows: Copy code

Yum repolist
Curl-O http://download-i2.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
Sudo rpm-ivh epel-release-6-8.noarch.rpm
Sudo yum install npm -- enablerepo = epel

After the above tossing, it is generally enough to use node-v and npm-v.

At this time, you can try to install nodeppt: npm install-g nodeppt
Back up previous vps data

Package the web program and use zip.

The Code is as follows: Copy code

# Packaging
Zip-r www.zip www
# Decompress
Unzip www.zip

Back up database

The Code is as follows: Copy code

Mysqldump-u root-p -- default-character-set = utf8 -- all-databases> all1207. SQL

For ease of transmission, you can use zip to package all1207. SQL
Scp for data transmission between vps

For example, to transfer A to/home in/home/root/all.zip on B:

The Code is as follows: Copy code

Scp root @ A:/home/root/all.zip/home

If you want to transfer folders, add-r

The Code is as follows: Copy code
Scp-r root @ A:/home/root // home

Import Database

Go to mysql: mysql-u root-p and import data:

The Code is as follows: Copy code
Mysql> source/home/root/all. SQL

Lnmp Optimization

Although lnmp has been optimized well, you can adjust your lnmp configuration based on your vps features, such as multi-core and memory size.
Install eAccelerator

The eAccelerator is the php accelerator I use. It is easy to install in lnmp. Go to the lnmp download package and execute. /eaccelerator. sh. Select the corresponding eAccelerator version as prompted. I chose new because php5.3 is used.
Configure eAccelerator

After installation, you can download the management php of eAccelerator. First, open php, modify the login username and password, and then put it in the root directory of your network. By default, the cache is set to 1 MB, which is a little small. You can refer to "linux installation PHP accelerator eAccelerator" to modify the configuration.
Install memcached

Memcached is a memory cache that stores queried mysql Data into memcached to reduce IO operations. It is also very easy to install in lnmp. You can also enter the lnmp package and execute./memcached. sh.
Start memcached

/Usr/local/memcached/bin/memcached-d-p 11214-u root-m 10-c 1024-t 8-P/tmp/memcached. pid
Disable mysql logs

The log function of mysql is generally useless. Previously, my vps had caused hard disk alarms due to too many mysql logs, so this time I disabled it directly:
Delete logs

Run:/usr/local/mysql/bin/mysql-u root-p
Enter the password to log on and run the following command: reset master;

Modify the/etc/my. cnf file and find

The Code is as follows: Copy code

Log-bin = mysql-bin
Binlog_format = mixed

Auto-start

Modify/etc/rc. d/rc. local. Run vi/etc/rc. d/rc. local. For example, to add memcached to the self-starting task, add the following command to rc. local:

The Code is as follows: Copy code

/Usr/local/memcached/bin/memcached-d-p 11214-u root-m 10-c 1024-t 8-P/tmp/memcached. pid
/Usr/local/memcached/bin/memcached-d-p 11211-u root-m 14-c 1024-t 8-P/tmp/memcached-main.pid

Crontab scheduled task

Execute crontab-e in the command line to go to the scheduled task page. Just like vi, edit wq. You can use crontab to cut logs and restart automatically when the load is too high.

Cut log

The Code is as follows: Copy code

#! /Bin/bash
# This script run at 00:00

# The Nginx logs path
Logs_path = "/xxx/logs /"

Mkdir-p $ {logs_path} $ (date-d "yesterday" + "% Y % m % d ")/


Mv/home/wwwlogs/* $ {logs_path} $ (date-d "yesterday" + "% Y % m % d ")/
Kill-USR1 'cat/usr/local/nginx/logs/nginx. pid'

Add crontab and execute: 00 00 ***/bin/sh/xxx/bin/cut_nginx_logs.sh at every day.
Load too high automatically restart the load

The Code is as follows: Copy code

#! /Bin/bash
# Script to check server for extremely high load and restart Apache if the condition is matched
Check = 'cat/proc/loadavg | sed's/. // '| awk' {print $1 }''
Check = $ (printf "%. 0f" $ check)
# Define max load avarage when script is triggered
Max_load = 15
# Log file
High_load_log = '/root/lnmp_high_load_restart.log'

# Location to Lnmp init script
Lnmp = '/root/lnmp'

If [$ check-gt "$ max_load"]; then
$ Lnmp stop
Sleep 5
$ Lnmp restart
Echo "$ (date): Lnmp Restart due to excessive load | $ check |" >>$ high_load_log
Fi

Add crontab and check once every 10 minutes: */10 *****/bin/sh/root/lnmp_auto_restart.sh
Enhance php security

I used phpsecinfo to view the php configuration. For details, refer to http://phpsec.org/projects/phpsecinfo /. Modify php. ini as needed and restart php-fpm.
Soft connection ln

The Code is as follows: Copy code

Ln-s/home/www/webroot
Nginx reload

When a new nginx virtual host is configured or the nginx configuration file is modified, you can run the following command to reload the configuration without restarting nginx to cause website interruption:

The Code is as follows: Copy code

/Usr/local/nginx/sbin/nginx-s reload

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.