Thursday, September 22, 2016

Linux (CentOS) cannot connect to the Internet

The original post is from
http://ahhafree.blogspot.hk/2013/08/linux-mint-ubuntu.html
I just adjusted it to CentOS, only wired connection is tested.

1.先變身為 root -- 在 debian 系列 (例如 ubuntu) 的版本裡, sudo bash 然後打自己的密碼
2.Linux 有沒有抓到網卡?
  (1)按 Ctrl-Alt-T 開啟終端機,輸入 ifconfig -a 如果只出現 lo 一項, 就是沒偵測到網卡。正常應該至少偵測到 lo, eth0 (有線網卡)……
In centos system "enp3s0"

  (2) 如果沒有偵測到硬體, 就無法往下做了 -- 這時請用您的 linux 版本名稱及網卡晶片名稱上網搜尋。(原來可上網,當然這部分沒問題)
3.如果有偵測到網卡, 但網路卻不通, 請下 route -n 應該要看到至少兩列數字, 類似這樣:
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
       0.0.0.0         192.168.3.254   0.0.0.0         UG    0      0        0 eth0
  (1)如果有, 表示網路其實已正常連線; 可能只是沒設定 DNS。 請跳到下一節 「設定 DNS」。
  (2)如果沒有出現上方的兩列數字, 那麼請按照您的連線環境, 挑一個方法設定連線:
      ( 結果沒有出現兩列數字)
4.有線網卡, 自動取得 ip---因為租屋的網路,所以挑這個
若您的網路環境是自動取得 ip, 請下 dhclient 網卡名稱
有些版本的指令是 dhcpd 而不是 dhclient; 總之先按 dhc 然後按一兩次 Tab 鍵, 系統會提示。
 (結果出現了 dhclient)
5.在 dhclient 後輸入 eth0 ,按 [Enter]果然網路就通了 ☺
Centos: $ sudo dhclient enp3s0

dhclient is used to get an IP address from a DHCP server.

6. If still not work
Or come out the output:
dhclient is already runing -exiting

# ifdown enp3s0
# ifup enp3s0
### RHEL/CentOS/Fedora specific command ###
# /etc/init.d/network restart

★若您有網路問題,可連結到[網路基本指令(洪朝貴教授的網頁)]查看,加以解決。本文即轉貼自此網頁。
==========
2015補充:
Ⓞ搬新家後,設定了新的光纖網路,結果筆電剛開始有線可以上網,無線都不能;過幾天連有線也不能上網了^^|||。要去設定,發現都無法設定,只好到網路上搜尋解決方法如下:

一、無線網路:
1.如上述檢查網路卡情況
2.用root權限打開 etc/network/interfaces
3.將其他各列都以#註記,只留下以下兩行:
auto lo
iface lo inet loopback


Thursday, September 8, 2016

Vim configuration in CentOS 7

Initialization

1. Build vim from source

https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source
Note that

cd ~
git clone https://github.com/vim/vim.git
cd vim
./configure --with-features=huge \
            --enable-multibyte \
            --enable-rubyinterp \
            --enable-pythoninterp \
            --with-python-config-dir=/usr/lib64/python2.7/config \
            --enable-python3interp \
            --with-python3-config-dir=/usr/lib64/python3.5/config \
            --enable-perlinterp \
            --enable-luainterp \
            --enable-gui=gtk2 --enable-cscope --prefix=/usr


2. Install vundle


https://github.com/VundleVim/Vundle.vim


3. Install plugin


Youcompleteme
http://www.alexeyshmalko.com/2014/youcompleteme-ultimate-autocomplete-plugin-for-vim/
https://valloric.github.io/YouCompleteMe/#general-usage

NerdTree
http://vimawesome.com/plugin/nerdtree-red

VimAwesome (include a lot plugins)
http://vimawesome.com/


Problem unsolved:

when install plugin
YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.3+) support
check python support in vim
:echo has('python') -> 0


Cheat Sheet
http://vim.rtorr.com/

NerdTree
https://www.cheatography.com/stepk/cheat-sheets/vim-nerdtree/


Tuesday, September 6, 2016

batch process images

find '/home/jwangae/bundleroot/Viewer/public/user_drive2/575fc0536e7a72be4cbd6b68' -name "*.JPG" | while read file; do   convert "$file" -rotate 90 "$file"; done

Friday, August 26, 2016

[nodemon] Internal watch failed: watch ENOSPC solution

 运行环境:CentOS 7,  node.js v5.11.1, nodemon 1.10.2
  在WS自带的终端输入nodemon server.js启动项目,报如下错误提示,服务能正常跑,但是无法监测文件修改。
[nodemon] Internal watch failed: watch *** ENOSPC
  解决办法是在终端输入如下命令,然后重新运行nodemon server.js。
echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
  注意,在WS的终端执行Ctrl + C并不能结束node进程,从而导致下一次服务启动时端口被占用而失败。正确的方法是直接点击终端窗口旁边的红色小叉以结束掉当前会话。

From original blog
http://www.cnblogs.com/jaxu/p/5568703.html

Centos: Cannot login GUI, file too large

Usually, the /root disk is full.
Just remove some useless files.
/var/crash stores some large files.

Wednesday, September 16, 2015

opencv pkgconfig error


To add the correct path to your bashrc you can do the following steps
  1. sudo find / -name "opencv.pc" -type f
  2. notice the directory output from 1. (without filename)
  3. open /etc/bash.bashrc sudo vi /etc/bash/bash.bashrc
  4. find and edit or add the following lines
    PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/your/path/from/#1
    export PKG_CONFIG_PATH
  5. save your file :wq
  6. logout and login again to active the changes

Install nvidia driver in Centos 7

I tested it on a fresh CentOS 7 installation (using the GNOME Desktop option) and it was pretty straightforward.

Import the rpm GPG key


rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

Install ELRepo


yum install http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

Remove Glamor


This is an open source Xorg graphics driver that may cause conflicts with proprietary drivers. If the package is installed it needs to be removed.
yum remove xorg-x11-glamor
  1. Disable Nouveau Driver

  2. open “/etc/modprobe.d/blacklist.conf in your favourite editor and add blacklist nouveau”, ofcourse without double-quotes.

  3. blacklist nouveau

  4. Next create a new initramfs file and taking backup of existing.

  5. # mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
  6. # dracut -v /boot/initramfs-$(uname -r).img $(uname -r)

  7. Reboot the machine. Login into command mode using Alt+F4 / ALT+F5 as root.

Install nvidia-detect [ optional ]


This is a small utility which detects graphic cards, suggests specific driver versions and checks compatibility with Xorg.
yum install nvidia-detect
Sample output:
nvidia-detect -x
Probing for supported NVIDIA devices...
[10de:11c0] NVIDIA Corporation GK106 [GeForce GTX 660]
This device requires the current 340.32 NVIDIA driver kmod-nvidia
[10de:11c0] NVIDIA Corporation GK106 [GeForce GTX 660]
This device requires the current 340.32 NVIDIA driver kmod-nvidia

Checking ABI compatibility with Xorg Server...
Xorg Video Driver ABI detected: 15
ABI compatibility check passed

Install kmod-nvidia


When running a 64bit OS, the 32bit Nvidia libraries may also be needed for compatibility, I always install them. The good thing is that kmod-nvidia also disables nouveauautomatically, so no more manually tweaking modprobe and grub :)
yum install kmod-nvidia nvidia-x11-drv-32bit


Download nvidia driver according to graphic card version


The are only a few commands to learn. First one is lscpi and here is a quick example showing how to fetch details about graphics unit (also called vga card or video card).
$ lspci -vnn | grep VGA -A 12
00:02.0 VGA compatible controller [0300]: Intel Corporation 82G35 Express Integrated Graphics Controller [8086:2982] (rev 03) (prog-if 00 [VGA controller])
        Subsystem: Intel Corporation Device [8086:d701]
        Flags: bus master, fast devsel, latency 0, IRQ 44
        Memory at e0200000 (32-bit, non-prefetchable) [size=1M]
        Memory at d0000000 (64-bit, prefetchable) [size=256M]
        I/O ports at 2440 [size=8]
        Expansion ROM at <unassigned> [disabled]
        Capabilities: <access denied>
        Kernel driver in use: i915



Now, we need to drop to text-only console, because the driver cannot install when the graphics thingies are in use. To do this, switch into runlevel 3. This is still done like before, for compatibility purposes, even though CentOS has switched away from traditional RC scripts to code-monkey object-oriented event-based whatever the new stupid thing is called, systemd or such.
init 3
Login as root. Find the downloaded Nvidia driver on your disk. Make the file executable and then run it. Follow the prompts provided by the Nvidia installer text wizard. You should also make sure to install the 32-bit libs.
chmod +x <Nvidia file>.run
./<Nvidia file>.run
Once this step is complete, go back into runlevel 5.
init 5



if after rebooting, the system cannot go to GUI

  1. # X -configure

  2. Copy xorg.conf.new as /etc/X11/xorg.conf.

  3. # cp /root/xorg.conf.new /etc/X11/xorg.conf

  4. Now switch to X Window as root user by typing.

  5. # init 5

  6. Launch NVIDIA configuration window and set the Resolution, manually, and at last click on Save to X Configuration File and quit. For reference, follow the screen shot added below.