做運維那麼久了,遇到的問題千奇百怪,現決定把大大小小的問題和解決方案做一個彙總。
一是爲了提倡開源精神,二是爲了自己記錄備忘。
問題1:Centos5.5服務器上想掛載一塊windows的移動硬盤。
錯誤:# mount –t ntfs /dev/sdb1 /mnt/
mount: unknown filesystem type ‘ntfs’
解決:
- 通過ntfs-3g來解決
- 打開ntfs-3g的下載點http://www.tuxera.com/community/ntfs-3g-download/ 下載最新的版本;
- #下載 :wget http://tuxera.com/opensource/ntfs-3g_ntfsprogs-2012.1.15.tgz
- 解壓,安裝:tar ntfs-3g_ntfsprogs-2012.1.15.tgz && cd ntfs-3g_ntfsprogs-2012.1.15 && ./configure && make && make install
- #查看移動硬盤的屬性: fdisk -l
- #掛載:mount -t ntfs-3g /dev/sdb1 /mnt/
問題2:如何查看apache加載的模塊?
- #通過幫助得知(/usr/local/apache/bin/apachectl -h)
- /usr/local/apache/binapachectl -l
- -l : list compiled in modules (列出static模塊)
- /usr/local/apache/bin/apachectl -t -D DUMP_MODULES
- -t -D DUMP_MODULES : show all loaded modules (包括共享模塊)
- 即http.d中Load Moudles加載的模塊
- 如下例子:
- [root@sonkwo1 modules]# /usr/local/apache/bin/apachectl -D DUMP_MODULES
- Loaded Modules:
- core_module (static)
- authn_file_module (static)
- authn_default_module (static)
- authz_host_module (static)
- authz_groupfile_module (static)
- authz_user_module (static)
- authz_default_module (static)
- auth_basic_module (static)
- include_module (static)
- filter_module (static)
- log_config_module (static)
- env_module (static)
- setenvif_module (static)
- mpm_prefork_module (static)
- http_module (static)
- mime_module (static)
- status_module (static)
- autoindex_module (static)
- asis_module (static)
- cgi_module (static)
- negotiation_module (static)
- dir_module (static)
- actions_module (static)
- userdir_module (static)
- alias_module (static)
- rewrite_module (static)
- so_module (static)
- php5_module (shared)
- rpaf_module (shared)
問題3:啓動apache的時候報:httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
- 雖然不妨礙使用,但是本着刨根問底的精神,經過查找發現,這個問題應該是沒有在 /$apache/httpd.conf
- 中設定 ServerName。所以apache會用主機上的名稱來取代,首先會去找 /etc/hosts 中有沒有主機的定義。
- 所以要解決這個問題可以設定httpd.conf文件中的 ServerName,如下:
- ServerName localhost:80
問題4:Directory index forbidden by Options directive
apache報錯:Directory index forbidden by Options directive: /var/www/
- 在 Apache 中要列出目錄內容需要 mod_autoindex 模塊的支持。
- 配置文件的設置方法:
- 打開列目錄功能:
- <Directory /path/to/directory>
- Options +Indexes
- </Directory>
- 關閉列目錄功能:
- <Directory /path/to/directory>
- Options -Indexes
- </Directory>
- 在使用如 RHEL 或 CentOS 發行版自帶 Apache 的朋友可能會碰到這樣的問題,無法列出網站根目錄下面的內容。其實問題原因很簡單,因爲 Apache 除了會讀取 /etc/httpd/conf/httpd.conf 配置文件外,還會讀取 /etc/httpd/conf.d/ 下以 .conf 結尾的文件。
- 在 /etc/httpd/conf.d/ 下有一個名爲 welcome.conf 的文件,這文件的內容如下:
- #
- # This configuration file enables the default "Welcome"
- # page if there is no default index page present for
- # the root URL. To disable the Welcome page, comment
- # out all the lines below.
- #
- <LocationMatch "^/+$">
- Options -Indexes
- ErrorDocument 403 /error/noindex.html
- </LocationMatch>
- 我們可以看到文件中去掉了目錄的Indexes屬性,這導致無法列出根目錄的內容。可以通過更改這個文件的後綴名或者註釋掉選項並重新加載配置文件解決該問題。
- 另外如果還有人建議需要一起刪除下面的文件,這個就要看你是否設置DirectoryIndex了。
- rm -f /var/www/error/noindex.html ← 刪除測試頁
問題5:error while loading shared libraries: xxx.so.x"錯誤的原因和解決辦法
- 一般我們在Linux下執行某些外部程序的時候可能會提示找不到共享庫的錯誤, 比如:
- tmux: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
- 原因一般有兩個, 一個是操作系統裏確實沒有包含該共享庫(lib*.so.*文件)或者共享庫版本不對, 遇到這種情況那就去網上下載並安裝上即可.
- 另外一個原因就是已經安裝了該共享庫, 但執行需要調用該共享庫的程序的時候, 程序按照默認共享庫路徑找不到該共享庫文件.
- 所以安裝共享庫後要注意共享庫路徑設置問題, 如下:
- 1) 如果共享庫文件安裝到了/lib或/usr/lib目錄下, 那麼需執行一下ldconfig命令
- ldconfig命令的用途, 主要是在默認搜尋目錄(/lib和/usr/lib)以及動態庫配置文件/etc/ld.so.conf內所列的目錄下, 搜索出可共享的動態鏈接庫(格式如lib*.so*), 進而創建出動態裝入程序(ld.so)所需的連接和緩存文件. 緩存文件默認爲/etc/ld.so.cache, 此文件保存已排好序的動態鏈接庫名字列表.
- 2) 如果共享庫文件安裝到了/usr/local/lib(很多開源的共享庫都會安裝到該目錄下)或其它"非/lib或/usr/lib"目錄下, 那麼在執行ldconfig命令前, 還要把新共享庫目錄加入到共享庫配置文件/etc/ld.so.conf中, 如下:
- # cat /etc/ld.so.conf
- include ld.so.conf.d/*.conf
- # echo "/usr/local/lib" >> /etc/ld.so.conf
- # ldconfig
- 3) 如果共享庫文件安裝到了其它"非/lib或/usr/lib" 目錄下, 但是又不想在/etc/ld.so.conf中加路徑(或者是沒有權限加路徑). 那可以export一個全局變量LD_LIBRARY_PATH, 然後運行程序的時候就會去這個目錄中找共享庫.
- LD_LIBRARY_PATH的意思是告訴loader在哪些目錄中可以找到共享庫. 可以設置多個搜索目錄, 這些目錄之間用冒號分隔開. 比如安裝了一個mysql到/usr/local/mysql目錄下, 其中有一大堆庫文件在/usr/local/mysql/lib下面, 則可以在.bashrc或.bash_profile或shell里加入以下語句即可:
- export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
- 一般來講這只是一種臨時的解決方案, 在沒有權限或臨時需要的時候使用.
- 4)如果程序需要的庫文件比系統目前存在的村文件版本低,可以做一個鏈接
- 比如:
- error while loading shared libraries: libncurses.so.4: cannot open shared
- object file: No such file or directory
- ls /usr/lib/libncu*
- /usr/lib/libncurses.a /usr/lib/libncurses.so.5
- /usr/lib/libncurses.so /usr/lib/libncurses.so.5.3
- 可見雖然沒有libncurses.so.4,但有libncurses.so.5,是可以向下兼容的
- 建一個鏈接就好了
- ln -s /usr/lib/libncurses.so.5.3 /usr/lib/libncurses.so.4
問題6:使用scp命令出現 "-bash: scp: command not found" 解決辦法
- 安裝yum -y install openssh-clients
問題7:編譯PHP 出現 undefined reference to 'libiconv' 解決辦法
- 但凡出現類似錯誤,都說明找不到鏈接庫,我們可以嘗試手動在系統中查找
- 然後在編譯的時候指定相關目錄即可
- #find / -name iconv.h
- #/usr/local/include/iconv.h
- 則編譯的時候增加目錄,讓程序能識別出鏈接庫的位置
- --with-iconv=/usr/local/include/