云服务器EC2配置Swap分区解决Cannot Allocate Memory

 centos  云服务器EC2配置Swap分区解决Cannot Allocate Memory已关闭评论
9月 192019
 

今天在EC2(Centos 7)上使用nvm 安装node时出现下面错误提示:

# nvm install 8.16.1
Downloading and installing node v8.16.1…
Downloading https://nodejs.org/dist/v8.16.1/node-v8.16.1-linux-x64.tar.xz…
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
xz: (stdin): Cannot allocate memory
tar: Child returned status 1
tar: Error is not recoverable: exiting now
Binary download failed, trying source.
Downloading https://nodejs.org/dist/v8.16.1/node-v8.16.1.tar.xz…
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
xz: (stdin): Cannot allocate memory
tar: Child returned status 1
tar: Error is not recoverable: exiting now
nvm: install v8.16.1 failed!

这台EC2内存只有1G,看来需要配个交换分区。

 

步骤

# 创建一个全0填充的2GB文件。InputFile利用Linux系统的/dev/zero。bs是BlockSize。

sudo dd if=/dev/zero of=/mnt/2GB.swap bs=1M count=2048

 

# 把该文件格式化为Swap文件

sudo mkswap /mnt/2GB.swap

 

# 把该Swap文件挂载为Swap分区

sudo swapon /mnt/2GB.swap

 

# 检查是否成功挂载。Swap那一行现在就不是0了。

$ free -m

total        used        free      shared  buff/cache   available

Mem:            963         677          74          78         211          52

Swap:          2047          84        1963

# 配置fstab,使开机时自动挂载Swap文件为Swap分区

sudo vim /etc/fstab

 

# 在/ect/fstab中添加

/mnt/2GB.swap none swap sw 0 0

 

xcode-select: error: tool ‘genstrings’ requires Xcode, but active developer directory ‘/Library/Developer/CommandLineTools’ is a command line tools instance 解决

 xcode  xcode-select: error: tool ‘genstrings’ requires Xcode, but active developer directory ‘/Library/Developer/CommandLineTools’ is a command line tools instance 解决已关闭评论
9月 092019
 

使用xcode时 在终端使用 genstrings命令时, 却提示: xcode-select: error: tool ‘genstrings’ requires Xcode, but active developer directory ‘/Library/Developer/CommandLineTools’ is a command line tools instance, 可以使用下面的方法解决:

1. 打开xcode, 进入Xcode -> preferences 菜单,或者直接快捷键command + , 进入菜单。
2. 在Locations这个tab下,找到 “Command Line Tools” ,在这个组合框里选择对应的xcode版本即可,我机器选择的是:Xcode 10.2.1(10E1001)

DONE!

virtualbox 里使用itunes步骤及注意事项

 virtualBox  virtualbox 里使用itunes步骤及注意事项已关闭评论
8月 022019
 

在virtualbox 里想使用itunes,会发现插入usb端口,设备连接了但发现不了iphone设备等问题, 网上找到一篇英文等资料,有详细步骤及注意事项,大家可以参考下(我遇到的问题就是原来打开的是USB 1.0,实际需要打开:USB 2.0 EHCI controller ):

Ok, for the record, I’m not the biggest fan of iTunes for Windows, and that’s why when I needed to use iTunes I decided to install it within an Oracle Virtualbox virtual machine.

This configuration provides the benefit of portability and it also prevents Apple iTunes from wreaking havoc on your host PC.

Hooray for no iTunes on my host machine!!!

Anyway, this is how you do it,

How to set it up

  1. Download and install Oracle VirtualBox from https://www.virtualbox.org/
  2. Open VirtualBox and click MACHINE > NEW to create a new virtual machine.
  3. Select your OS and memory allocation. In my case I chose Microsoft Windows 7 32 bit
    Oracle VirtualBox Screenshot
  4. Choose option Create a virtual hard drive now. You can use the defaults for the next prompts. It’s advisable that you  allocate more hard disk space if you are going to store your media files within the Virtual Machine. In my situation I created a shared folder on my host which I mapped to the Virtual Machine.
  5. Plug in your iDevice to your PC.
  6. You should now see your Virtual Machine in the VirtualBox Manager window. Click SETTINGS to configuring your VM.
    Oracle VirtualBox screenshot
  7. You’ll need to mount the OS storage media within the Storagepanel to install your OS.
  8. Enable the Network Adapter in Bridged Mode so that you have internet access.
  9. In the USB pane, ensure the USB 2.0 EHCI controller is enabled otherwise your iDevice will not operate correctly. If you plugged in your iDevice then click the green ‘+’ button and select your iDevice, this will ensure that control of your device is passed straight to your VM automatically each time you start your VM. Otherwise you can manually ‘pass through’ the device once the VM is started.
    Oracle VirtualBox Screenshot
  10. It’s also advisable to enable 2D hardware acceleration and add additional Video Memory for improved performance.
  11. Click OK to save your changes
  12. Start your Virtual Machine and install the OS and Apple iTunes
  13. Setup your iTunes library to find your media files. It’s recommended that you use the ‘Consolidate Files‘ library option in iTunes to store all your media files in one single location, that way it’ll be easier for you to relocate your Virtual Machine in future to another PC.
  14. If you need access to the CD Drive on your host machine, simply start your Virtual Machine and ‘pass through’ control of your CD drive to your Virtual Machine through the DEVICES > CD/DVD DEVICES > HOST DRIVE option
  15. iTunes should now see your device and should sync successfully.
    iTunes Screenshot

Issues that I encountered

I had iTunes setup to consolidate all media files to an external USB drive. I experienced device ‘timeout‘ issues and ‘Could not connect to lockdown port‘ errors while syncing with my iPhone. After much hair pulling I realised that the timeouts were occurring only when I configured VirtualBox to ‘pass through’ my USB drive to the Virtual Machine. The issue was solved by instead creating a Shared Machine Folder within the Virtual Machine settings mapping to my USB drive.

I would certainly suggest that you create a snapshot of your Virtual Machine once you’ve created it incase anything goes wrong and you need to rollback to an earlier time.

docker 在mac系统下, 修改/etc/docker/daemon.json期望改变dns无效解决方法

 docker  docker 在mac系统下, 修改/etc/docker/daemon.json期望改变dns无效解决方法已关闭评论
7月 252019
 

mac系统下,直接修改/etc/docker/daemon.json期望改变容器的dns是无效的,正确的方式是:

点击应用程序里的docker.app 或者 点击顶部工具条中 “鲸鱼”的icon –> 选择“preferences”  –> daemon –> advanced , 在这里更改, 修改完后点击 “apply && restart”,  再运行容器时, 可以看到容器中/etc/resolv.conf的dns已经是修改后的了。

终端使用git命令提示:No user exists for uid 501 问题解决

 git  终端使用git命令提示:No user exists for uid 501 问题解决已关闭评论
4月 092019
 

使用iTerm输入git命令时提示:

No user exists for uid 501 fatal: Could not read from remote repository.
Please make sure you have the correct access rightsand the repository exists.

解决方法:

关掉终端,再打开即可, 晕!

升级完macOS mojave后,git命令出现xcrun 错误解决方法

 git, mac  升级完macOS mojave后,git命令出现xcrun 错误解决方法已关闭评论
3月 292019
 

今天升级macOS 到 macOS mojave,升级完后终端里使用git的时候,弹出一行错误:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

解决方法,重装xcode command line:

xcode-select --install

如果没有解决问题,执行以下命令

sudo xcode-select -switch /

DONE!!

.gitignore修改后不生效解决办法

 git  .gitignore修改后不生效解决办法已关闭评论
3月 182019
 

.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。那么解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:
git rm -r –cached .
git add .
git commit -m ‘update .gitignore’
git push origin 分支名

pm2 status error 解决

 Nodejs, pm2  pm2 status error 解决已关闭评论
2月 202019
 

今天使用pm2  启动nodejs应用, 发现启动一会儿,pm2 中status状态就从online变成error, 日志也看没有什么记录, 后来发现可以通过下面的步骤解决:  pm2 update

如果彻底些,可以先kill 掉pm2的进程, 再执行pm2 update命令。

查看帮助

$ pm2 update -h

  Usage: update [options]

  (alias) update in-memory PM2 with local PM2

  Options:

    -h, –help  output usage information

通过上面命令查看,估计问题出在本机PM2的内存数据里