Linux command records for VPS migrations

Source: Internet
Author: User
Tags exit in fpm mysql version ssh vps import database phpmyadmin yum repolist

Because before the music valley gathered to find the nest, the official website is hung, Online said to run, although someone had contacted me before I said there are their companies take over, but when there are problems in contact, but can not find people. So decided to replace the VPS. Simple record of the use of this VPS migration command.

The new VPS is used by the CentOS 32.
Change Password after landing

After connecting SSH, the first thing is to replace the root password, the command used is passwd

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

passwd www continues the data www password. You can add
Install Package Command Yum

Ubuntu Package management software is App-get,centos package management software is yum, because my VPS is CentOS, so use yum.

The code is as follows Copy Code

# installation
Yum Install xxx
# Delete
Yum Remove httpd

Because I am using LNMP, so for the default installed Apache can be deleted, using Yum remove httpd.
Use screen to manage conversations

Often meet the network connection is not good, ssh interruption, then the implementation of the program does not know will succeed, so with screen. If you do not have a command using screen--help, you need to install the following:

Yum Install screen
Screen common commands

The code is as follows Copy Code

# Create Screen Dialog
Screen-s LNMP
# View the screen now running
Screen-ls
# Read some screen
Screen-r LNMP
# Exit screen, execute exit in current screen
Exit

Install LNMP

The code is as follows Copy Code

CentOS System execution: 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
Debian system execution: 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
Ubuntu system execution: 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

The middle will want you to choose PHP version, MySQL version, MySQL root password
LNMP Status Management Command

LNMP State Management:/ROOT/LNMP {start|stop|reload|restart|kill|status}
Nginx State Management:/etc/init.d/nginx {Start|stop|reload|restart}
MySQL State management:/etc/init.d/mysql {start|stop|restart|reload|force-reload|status}
memcached State Management:/etc/init.d/memcached {Start|stop|restart}
PHP-FPM State Management:/etc/init.d/php-fpm {start|stop|quit|restart|reload|logrotate}
PUREFTPD State Management:/etc/init.d/pureftpd {start|stop|restart|kill|status}
PROFTPD State Management:/etc/init.d/proftpd {start|stop|restart|reload}

such as restart Lnmp, input command:/root/lnmp Restart can be, separate restart Mysql:/etc/init.d/mysql restart

About one hours (see the 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: Version 0.9 for/home/wwwroot/phpmyadmin/1.0 version/home/wwwroot/default/phpmyadmin/ It is highly recommended that you rename this directory to a name that is not easily guessed. phpMyAdmin can download the new version of the replacement from the official website.
Default Web Site Directory: Version 0.9 is/home/wwwroot/1.0 version/home/wwwroot/default/
nginx log directory:/home/wwwlogs/
/root/ Vhost.sh added virtual host configuration file directory:/usr/local/nginx/conf/vhost/
pureftpd directory:/usr/local/pureftpd/
pureftpd Web Admin directory: Version 0.9 is/home/wwwroot/default/ftp/1.0 version of/home/wwwroot/default/ftp/
Proftpd directory:/usr/local/proftpd/
LNMP related configuration file location

Nginx Main configuration file:/usr/local/nginx/conf/nginx.conf
/root/vhost.sh added Virtual host configuration file:/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 config file:/usr/local/pureftpd/pureftpd-mysql.conf
PROFTPD configuration file:/usr/local/proftpd/etc/proftpd.conf
PROFTPD User profile:/usr/local/proftpd/etc/vhost/user name. conf
Lnmpa Related 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 easy to use as Ubuntu Apt-get, but need to compile their own, and later in the Nodejs official website saw CentOS can also use package management: https://github.com/ Joyent/node/wiki/installing-node.js-via-package-manager

Execute on the command line in turn:

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 toss, generally can, using node-v and npm-v on it.

This is the time to try the installation Nodeppt success: NPM install-g nodeppt
Pre-backup VPS data

Before you package the Web program, use zip.

The code is as follows Copy Code

# Packing
Zip-r Www.zip www
# decompression
Unzip Www.zip

Backing up a 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
Between VPS transport Data SCP

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

The code is as follows Copy Code

SCP Root@a:/home/root/all.zip/home

If you need to transfer a folder, you need to add the-R

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

Import Database

Enter Mysql:mysql-u root-p, import data:

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

LNMP optimization

Although the LNMP has been optimized, but according to its own VPS features, such as multi-core, memory size, you can adjust their lnmp configuration.
Install Eaccelerator

Eaccelerator is the PHP accelerator I use, LNMP in the installation is very simple, into the LNMP download package, and then execute. Eaccelerator.sh, according to the prompts to choose the corresponding Eaccelerator version, I chose the new because it is php5.3.
Configure Eaccelerator

After installation can download Eaccelerator management php, first open PHP, modify the login username and password, and then placed in their own network root directory can be accessed. The default settings cache is 1M, feel a little bit, you can refer to the "Linux installation PHP accelerator eaccelerator" under the modified configuration.
Install memcached

Memcached is the memory cache, can be queried data such as MySQL, stored in memcached to reduce IO operations. It is also very simple to install in Lnmp, and also to enter the LNMP package, execute./memcached.sh, it's okay.
Start memcached

/usr/local/memcached/bin/memcached-d-P 11214-u root-m 10-c 1024-t 8-p/tmp/memcached.pid
Close MySQL Log

MySQL log function, generally no use, before my VPS once because the MySQL log too much led to the hard disk alarm, so this time I closed directly:
Delete Log

Executive:/usr/local/mysql/bin/mysql-u root-p
Enter password login and then execute: RESET master;

Modify the/etc/my.cnf file to find

The code is as follows Copy Code

Log-bin=mysql-bin
Binlog_format=mixed

Power-on Self-starter

Modify/etc/rc.d/rc.local. Need to use VI execution: vi/etc/rc.d/rc.local, for example, to add memcached to the start task heavy, you need to 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 timed Task

In the command line to perform CRONTAB-E into the scheduled Task page, with the same as VI, edit well: Wq on it. Through the crontab can do log cutting, load too high automatic restart.

Cutting 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, daily 0 o'clock in the morning: * * */bin/sh/xxx/bin/cut_nginx_logs.sh
Load too high and automatically restart load

  code is as follows copy code

#!/bin/bash
# Script to check server for extremely high load and restart Apac He if the condition is matched
check= ' cat/proc/loadavg | sed ' s/.//' | awk ' {print '} '
check=$ (printf "%.0f" $check)
# define Max load Avarage when the script is triggered
max_load=15
# log file
high_load_log= '/root/ln Mp_high_load_restart.log '

# location to lnmp init script
lnmp= '/root/lnmp '

If [$check-gt ' $max _load '] ; Then
    $lnmp stop
    sleep 5
    $lnmp restart
 & nbsp;  echo "$ (date): Lnmp restart due to excessive load | $check | ">> $high _load_log
fi

Add Crontab, No 10-minute test: */10 * * * * * */bin/sh/root/lnmp_auto_restart.sh
Enhance PHP Security

I use the Phpsecinfo to view the configuration of PHP, you can view the next http://phpsec.org/projects/phpsecinfo/. Modify PHP.ini According to your situation and restart PHP-FPM.
Soft Connection Ln

The code is as follows Copy Code

Ln-s/home/www/webroot/webroot
Nginx Reload

When you configure a new Nginx virtual host, or modify the Nginx profile, you can reload the configuration with the following command without restarting the Nginx causing the site to break:

  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.