Set the file exchange in CentOS7

Source: Internet
Author: User
Tags vps

Set the file exchange in CentOS7
Problem Source

I want to set up a blog service on the purchased VPS. I prefer dynamic blogs and so on. I chose nodejs, And the range is reduced. At first I took a fancy to N-blog. You need to install bower. If the npm version is always prompted during installation:

npm WARN deprecated This version of npm lacks support for important features,npm WARN deprecated such as scoped packages, offered by the primary npmnpm WARN deprecated registry. Consider upgrading to at least npm@2, if not thenpm WARN deprecated latest stable version. To upgrade to npm@2, run:npm WARN deprecated npm WARN deprecated   npm -g install npm@latest-2npm WARN deprecated npm WARN deprecated To upgrade to the latest stable version, run:npm WARN deprecated npm WARN deprecated   npm -g install npm@latestnpm WARN deprecated npm WARN deprecated (Depending on how Node.js was installed on your system, younpm WARN deprecated may need to prefix the preceding commands with `sudo`, or ifnpm WARN deprecated on Windows, run them from an Administrator prompt.)npm WARN deprecated npm WARN deprecated If you're running the version of npm bundled withnpm WARN deprecated Node.js 0.10 LTS, be aware that the next version of 0.10 LTSnpm WARN deprecated will be bundled with a version of npm@2, which has some smallnpm WARN deprecated backwards-incompatible changes made to `npm run-script` andnpm WARN deprecated semver behavior.

It is clear that the npm version is too low and some features are not supported. Follow the prompts to execute

npm -g install npm@latest

After all, npm has not been upgraded at this time. After dozens of seconds, the following appears:

... The above omitted npm WARN deprecated backwards-incompatible changes made to 'npm run-script' andnpm WARN deprecated semver behavior. Killed

If you are not careful, you will find that the npm is not updated. A Killed prompt is displayed on the last line. You can find that this is becauseIf the memory is not enough and the server memory is not enough, the program will end directly. In fact, if the VPS memory is small, it will not only cause problems when installing the nodejs library, but also prompt when you directly use the yum installation package.Cannot allocate memory Error.

Solution upgrade VPS Configuration

The simplest way is to upgrade the VPS configuration. You only need to pay for it by clicking the button on the webpage. For individual players, it is just using VPS to build personal websites and make fun of things. There is not much traffic and it often does not require a good configuration. Therefore, the following method is used to addSwap files.

SWAP FILE

We usually hear more about swap partitions, that is, we can directly separate partitions on the hard disk as swap spaces. If it is inconvenient to create a partition after the system has been installed, you can use a file instead. Swap space is actually a hard disk. It is used as a large cache of memory in the system. When the memory of the operating system is insufficient, some infrequently used pages will be replaced with swap space. Therefore, the swap space will improve the performance of some systems. However, the larger the swap space, the better, because if the application uses the data in the swap space, there will be a large delay, large swap partitions can cause high latency of a large number of applications. Therefore, if the program has a large memory demand, the best way is to increase the physical memory.Buying memory is king, and swap space is just a way to slightly improve performance.

CentOS7 set swap file check system conditions

First, check whether the system has set a swap space. In principle, try to set only one swap space. In addition, check whether the system has enough disk space.

swapon -s

You can use the swapon command to view the swap space of the system, or use the free command to view the swap space.

free -h

Run the df command to check the remaining hard disk space of the system.

df -h
Create a swap file

Use the fallocate command to create a new swap file. Since my system memory is 512 MB, swap partitions are generally set to 2 ~ memory ~ 4 times, so I set it to 1 GB and mount it directly to the root directory.

sudo fallocate -l 1G /swapfile

You can use the ls command to view

ls -lh /swapfile

The result is as follows:

-rw-r--r-- 1 root root 1.0G Oct 30 11:00 /swapfile
Enable swap file

First, modify the/swapfile permission to only allow access by the root user.

sudo chmod 600 /swapfile

The ls result is as follows:

-rw------- 1 root root 1.0G Oct 30 11:00 /swapfile

Next, notify the system to create a swap space.

sudo mkswap /swapfile

Finally, enable the swap space

sudo swapon /swapfile

You can run the swapon-s or df-h command to view the result. The swap space is displayed.

Persistent Configuration

After the restart, the system will no longer set/swapfile as a swap space. You can add the following in/etc/fstab:

/swapfile   swap    swap    sw  0   0

After the instance is restarted, the/swapfile is automatically mapped to the swap space.

Last

As you can imagine, if the actual memory requirement is much larger than the physical memory size, data exchange between the memory and the swap space will occur frequently, and the damage to the hard disk will be relatively large. In addition, the application experience is poor.

So,The swap space is only a temporary solution, and the purchase of memory stick is king.

Appendix

NPM gets killed no matter what.

How To Add Swap on CentOS 7

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.