安裝完CentOS 7 Minimal之后,從頭打造桌面工作環境
裝完CentOS 7之后,以前裝好的win7或是其它系統沒有出現在啟動項中的解決辦法
安裝Markdown解析器(python-markdown)
安裝配置管理Apache HTTP Server(httpd)
U盤裝CentOS 7 DVD版不能引導的解決辦法
用UltraISO將DVD版的iso刻錄到U盤后,刪除packages文件夾(節省空間,不刪除亦可),將iso文件復制進U盤根目錄,開機之后出現
dracut:/#
輸入命令
$ cd dev
$ ls
找到U盤的盤符,比如sda5,然后重新開機,按方向鍵選擇到第一項Install CentOS 7
,按下Tab鍵,出現
vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
修改為
vmlinuz initrd=initrd.img repo=hd:/dev/sda5:/ quiet
更改root密碼
用root賬戶登錄shell,Alt+(F1F6)切換tty1tty6。
# passwd
SSH登錄
$ ssh root@SERVER_IP_ADDRESS
增加除root之外的常規用戶
# useradd newusername
# passwd newusername
裝完CentOS 7之后,以前裝好的win7或是其它系統沒有出現在啟動項中的解決辦法
在/boot/grub2/grub.cfg中添加
menuentry 'Windows 7 Professional' {
set root=(hd0,1)
chainloader +1
}
(hd0,1)代表第一個分區。
安裝GNOME桌面環境
# yum grouplist
# yum groupinstall "GNOME Desktop"
CentOS 6.x與CentOS 7的yum group是不同的,CentOS 6.x需要這樣
# yum groupinstall "X Window System" "Desktop" "Chinese Support"
啟動桌面環境
# startx
設置是否默認啟動桌面環境
$ vi /etc/inittab
/etc/inittab
文件明確聲明了inittab is no longer used when using systemd
,並指示了如何用systemd的方式來做。
# systemctl get-default
# systemctl set-default multi-user.target
# systemctl set-default graphical.target
沒有ifconfig命令的解決辦法
如果沒有安裝桌面環境,那么minimal版本沒有ifconfig
命令。
找出哪個包提供了ifconfig
命令
# yum provides ifconfig
或
# yum whatprovides ifconfig
輸出中可以看到net-tools
包提供了ifconfig
命令。
# yum install net-tools
網絡配置
$ ifconfig -a
# ifconfig enp0s3 up // 開啟enp0s3網卡
# ifconfig enp0s3 down // 關閉enp0s3網卡
$ dhclient enp0s3 // 發送DHCP請求
DNS工具與Windows一樣
$ nslookup
安裝第三方源(EPEL和RPMForge)
CentOS官方文檔聲稱嚴重推薦EPEL,不推薦RPMForge,因為RPMForge已經不再被維護了,雖然曾經被CentOS推薦。
EPEL
官方網站http://fedoraproject.org/wiki/EPEL
EL7下載地址http://download.fedoraproject.org/pub/epel/7/x86_64/repoview/epel-release.html
# rpm -ivh epel-release-7-5.noarch.rpm
EPEL的repo文件已經在目錄/etc/yum.repos.d/下。
RPMForge
官方網站http://repoforge.org/
EL7下載地址http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
# rpm -ivh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
RPMForge的repo文件已經在目錄/etc/yum.repos.d/下。
安裝C++編譯器
# yum install gcc-c++
掛載NTFS文件系統
CentOS自身的源里沒有支持NTFS的包,需要從EPEL或RPMForge(也叫RepoForge)源里安裝。
# yum install ntfs-3g --enablerepo=epel
或
# yum install fuse-ntfs-3g --enablerepo=rpmforge
安裝VirtualBox
VirtualBox要編譯內核,所以需要kernel-devel這個包。
# yum install kernel-devel
# yum localinstall *.rpm
對於VirtualBox只能裝32位系統的情況,涉及到Host的CPU是否支持虛擬化以及是否開啟了虛擬化,如果沒有開啟,在BIOS里面設置,一般在CPU的子設置里面,且含有“Virtualization”或“Virtual”字樣,將它設為Enable
。
安裝Markdown解析器(python-markdown)
Linux下Markdown解析器有很多,CentoOS官方Yum源(extras)里有python-markdown。
# yum install python-markdown
python-markdown
的命令名是markdown_py
,查看幫助。
$ markdown_py -h
用法簡單,舉例說明,用以備忘。
-
解析*.md,輸出html內容到stdout。
$ markdown_py *.md
-
解析*.md,利用重定向,輸出html內容到*.html。
$ markdown_py *.md > *.html
-
可以不使用重定向,利用
markdown_py
命令的-f
選項,輸出html內容到*.html。$ markdown_py -f *.html *.md
-
-o
選項用來指定解析完之后html的輸出格式,可以是html5
、html4
和xhtml1
,默認xhtml1
,所以最好明確指定-o
選項。$ markdown_py -o html5 *.md > *.html
安裝Flash Player
-
adobe官網下載yum安裝包
# rpm -ivh *.rpm # yum install flash-plugin --enablerepo=adobe-linux-x86_64
-
adobe官網下載rpm安裝包
# rpm -ivh *.rpm
-
利用RPMforge
# yum install flash-plugin --enablerepo=rpmforge
安裝wkhtmltopdf
# yum localinstall wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm
# wkhtmltopdf http://wkhtmltopdf.org/ wkhtmltopdf.pdf
安裝MPlayer
RPMforge(現在叫RepoForge)的repo中沒有CentOS 7的smplayer,所以需要源代碼安裝。
安裝MPlayer通常需要以下3個東西:
- source code(源代碼tarball文件)
- binary codecs(一堆二進制的解碼器文件)
- a skin(皮膚)
官網下載source code。
$ ./configure --enable-gui --language=zh_CN --disable-ossaudio
--enable-gui
告訴configure以后運行MPlayer需要圖形界面,不僅只從command line運行。
--language=zh_CN
告訴configure安裝中文環境。
--disable-ossaudio
是因為linux2.4以后的內核逐漸拋棄oss音頻架構而轉向alsa(詳細說明請參考http://blog.csdn.net/meizum10/article/details/17437959)。
提示No FFmpeg checkout, press enter to download one with git or CTRL+C to abort
,按下回車鍵。
通常configure會失敗,因為需要一些依賴。它告訴缺什么就裝什么。
提示./configure: line 1522: git: command not found Failed to get a FFmpeg checkout
,configure需要利用git下載ffmpeg,如果git沒有安裝,那么就安裝git。
# yum install git
提示Error: Compiler is not functioning correctly. Check your installation and custom CFLAGS .
,源代碼編譯安裝當然需要gcc,如果沒有安裝,那么就安裝它。g++依賴於gcc,所以為了以后省事,干脆安裝g++。
# yum install gcc-c++
提示Error: yasm not found, use --yasm='' if you really want to compile without
,缺少yasm,去yasm官網http://yasm.tortall.net下載源代碼tarball,簡單的三步走:
$ ./configure
$ make
$ su
# make install
In function avcodec_register_all' 提示
Error: The GUI requires X11.`,缺少X11,yum安裝gtk2-devel,注意要安裝gtk2-devel,gtk3-devel不行。
# yum install gtk2-devel
configure通過,接着
$ make
$ su
# make install
OK,安裝完成,在command line里運行mplayer 媒體文件名
一般可以播放。
官網下載binary codecs,是個tarball,解壓,得到一堆解碼器文件,將這些解碼器文件放到/usr/local/lib/codecs/里。/usr/local/lib/下如果沒有codecs文件夾,那就手動創建一個。
官網下載skin文件(我安裝的是clearplayer),是個tarball,解壓,得一文件夾,將這文件夾放到/usr/local/share/mplayer/skins/里,之后建立一個叫default的符號鏈接,指向皮膚文件夾。
# ln -s <文件夾名字> default
當然,也可以把文件夾名字直接改成default。
如果播放沒有聲音,那么就這么干:
# yum install *alsa*
安裝了一堆alsa相關的東西。
至於CentOS 6.x,RPMforge(現在叫RepoForge)的CentOS 6.x的repo中有smplayer,所以直接yum安裝。
# yum install smplayer --enablerepo=rpmforge
配置GoAgent
服務端上傳:
$ python server/uploader.py // linux & mac
雙擊server/uploader.bat // windows
客戶端運行:
$ python local/proxy.py // linux & mac
雙擊local/goagent.exe // windows
Firefox和Opera需要導入證書。
對於CentOS 6.x:
# yum install centos-release-SCL
# yum install python27
在/etc/ld.so.conf.d/文件夾中建立文件python27.conf,內容為/opt/rh/python27/root/usr/lib64。
# ldconfig // 加載配置
$ /opt/rh/python27/root/usr/bin/python proxy.py
安裝配置管理Git
安裝
# yum install git
git config
安裝完需要用git config
配置user name和user email,否則不能commit。
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"
$ git config --list
git config
有3種選項,對應不同配置文件。
- --system /etc/gitconfig
- --global ~/.gitconfig
- no option .git/config
SSH KEY
為了使用GitHub的SSH keys功能,利用ssh-keygen
工具在本地生成rsa密鑰對。
$ ssh-keygen -t rsa -C "your_email@example.com" // generate a rsa key pair in the file ~/.ssh/id_rsa & ~/.ssh/id_rsa.pub
$ ssh-keygen -p //adding or changing a passphrase
.gitignore
各種類型的gitignore模板https://github.com/github/gitignore
。
# 此為注釋
*.a 忽略所有目錄下.a結尾的文檔
!lib.a 但不忽略lib.a文檔
*.[oa] 忽略所有目錄下.a或.o結尾的文檔
*~ 忽略所有目錄下~結尾的文檔
TODO 忽略所有目錄下的TODO文檔
/TODO 僅僅忽略根目錄下的TODO文檔
build/ 忽略所有目錄下的build文件夾
/build/ 僅僅忽略根目錄下的build文件夾
doc/**/*.txt 忽略doc文件夾下的所有.txt文檔
星號*匹配零個或多個任意字符
[abc] 匹配任何一個列在方括號中的字符(這個例子要么匹配一個 a,要么匹配一個 b,要么匹配一個 c)
問號?只匹配一個任意字符
如果在方括號中使用短划線分隔兩個字符,表示所有在這兩個字符范圍內的都可以匹配,比如 [0-9] 表示匹配所有 0 到 9 的數字
常用命令
$ git init
$ git add *
$ git commit -m 'message'
$ git status
$ git status -s
$ git status --short
$ git diff
$ git clone git@github.com:who/whatrepo.git
$ git clone https://github.com/who/whatrepo
$ git clone https://github.com/who/whatrepo SpecifiedFolder
$ git remote
$ git remote -v
$ git remote add [shortname] [url]
$ git remote rm [remote-name]
$ git remote rename [old-name] [new-name]
$ git remote fetch [remote-name]
$ git push [remote-name] [branch-name]
$ git pull
安裝配置管理Apache HTTP Server(httpd)
安裝
# yum install httpd
管理
在Windows下,httpd是以系統服務的形式運行,在Unix(Linux)下,httpd作為daemon(守護進程)運行。
httpd官方文檔推薦用apachectl這個script來調用httpd可執行程序,原因是:apachectl首先會設置一些為保證httpd正確運行所必要的環境變量,然后再去調用httpd可執行程序,而且apachectl會把命令行參數原封不動的傳遞給httpd。
apachectl是httpd daemon的front end。所以管理員應該用apachectl來管理httpd daemon。
apachectl在CentOS 6.x和CentOS 7下均可用。
# apachectl start
# apachectl stop或graceful-stop
# apachectl restart或graceful
# apachectl status
如果不使用apachectl這個script,也可以使用service這個管理daemon的命令。
# service httpd start
# service httpd stop
# service httpd restart
# service httpd status
如果系統支持systemd(CentOS 7開始支持systemd),既可以用service命令,也可以用systemd。
# systemctl start httpd.service
# systemctl stop httpd.service
# systemctl restart httpd.service
# systemctl status httpd.service
# systemctl is-active httpd.service
設置開機自動啟動
要設置開機自動啟動httpd,需要區分在CentOS 6.x和CentOS 7下2種情況。
CentOS 6.x沒有systemd,我最喜歡的方式是修改/etc/rc.d/rc.local
這個文件。
# vi /etc/rc.d/rc.local
添加以下命令。
/usr/sbin/apachectl start
CentOS 7用了systemd。
# systemctl enable httpd.service
# systemctl disable httpd.service
理解並設置虛擬主機
httpd的主配置文件是/etc/httpd/conf/httpd.conf
。目錄/etc/httpd/conf.d/
下的文件只要以.conf
作為擴展名,其內容就能被集成到主配置文件中。所以盡量不直接修改主配置文件,而是在目錄/etc/httpd/conf.d/
下面搞。
httpd官方文檔把Virtual Host(虛擬主機)分為了2種:IP-based和Name-based。
我的理解是:
在配置文件里放一個<VirtualHost></VirtualHost>
block,就代表配置了一個Virtual Host,放2個就代表配置了2個。起始標簽<VirtualHost>
里需要說明IP地址和端口,即這個樣子<VirtualHost 192.168.1.1:80>
,IP可以是*
,端口可以不寫。
一個request來了之后,就根據IP地址和端口按照配置文件中的順序來一個個匹配<VirtualHost></VirtualHost>
block。如果所有的<VirtualHost></VirtualHost>
block都沒匹配上,那么就去咨詢主配置文件里的指示了。而一旦某些<VirtualHost></VirtualHost>
block匹配上了,那么只有這些匹配上的block才能成為request的候選者,其它的<VirtualHost></VirtualHost>
block包括主配置文件就都沒有機會了。
如果候選者只有1個,那么沒的挑了,就是你了。而如果候選者有多個,怎么選?
就得看<VirtualHost></VirtualHost>
block里面的ServerName
和ServerAlias
指示了,誰的ServerName
、ServerAlias
與request的HTTP報文的header的Host相匹配,那么誰就勝出。如果多個block都匹配,那么先來后到,誰在前邊誰勝出。如果都不匹配,那么還是先來后到。
Listen 80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.example.com
ServerAlias example.com
</VirtualHost>
<Directory "/var/www/html">
AllowOverride All
</Directory>
AllowOverride All
的作用是使web目錄內的.htaccess文件起作用,常用於開啟Drupal的簡潔URL。
如果VirtualHost指定了端口,需要寫上Listen
指示,因為只有先告訴httpd監聽某個端口,request才能從這個端口進來,進而進入某個VirtualHost。httpd主配置文件默認已經配置了Listen 80
,所以VirtualHost如果指定80端口,就不需要再此指示監聽80端口了,配置文件里重復的指示不符合語法。
安裝配置管理MySQL(MariaDB)
安裝
MySQL
# yum install mysql-server
MariaDB
# yum install mariadb-server
mysql-server package依賴於mysql package,所以沒必要這么做:yum install mysql mysql-server
。
管理
MySQL
# service mysqld start
# service mysqld stop
# service mysqld restart
# service mysqld status
MariaDB
# service mariadb start
# service mariadb stop
# service mariadb restart
# service mariadb status
也可以用systemd方式
# systemctl start mariadb.service
# systemctl stop mariadb.service
# systemctl restart mariadb.service
# systemctl status mariadb.service
# systemctl is-active mariadb.service
配置
# mysql_secure_installation
或
# mysqladmin -u root password ''
設置開機自動啟動
MySQL
# vi /etc/rc.d/rc.local
添加以下命令
/usr/sbin/service mysqld start
MariaDB
# systemctl enable mariadb.service
# systemctl disable mariadb.service
登錄
$ mysql -hhost -Pport -Ddatabase -uusername -p
登錄后的常見命令
> create database if not exists * default character set utf8;
> show databases;
> use *;
> show tables;
安裝配置管理PHP
安裝
# yum install php
僅僅安裝PHP往往是不夠的,通常還需要安裝模塊。
# yum install php-mysql
# yum install php-gd
# yum install php-xml
# yum install php-mbstring
配置
PHP配置文件
/etc/php.int
通常需要改配置文件
upload_max_filesize = 2M
Linux(Yum系)常用壓縮打包命令
.tar.gz
$ tar xzvf *.tar.gz
$ tar czvf *.tar.gz file1 file2
.tar.bz2
$ tar xjvf *.tar.bz2
$ tar cjvf *.tar.bz2 file1 file2
.tar.xz
$ tar xJvf *.tar.xz
$ tar cJvf *.tar.xz file1 file2
.zip
# yum install zip unzip
$ zip *.zip file1 file2
$ unzip *.zip
.rar
# yum install rar --enablerepo=rpmforge
$ rar a *.rar file1 file2
$ rar x *.rar
.7z
# yum install p7zip --enablerepo=rpmforge
$ 7za a *.7z file1 file2
$ 7za x *.7z
Yum和RPM常用命令備忘錄
yum history
# yum history
# yum history list <ID>
# yum history info <ID>
# yum history undo <ID>
# yum history redo <ID>
yum update
# yum clean all
# yum makecache
# yum update
rpm安裝卸載
# rpm -ivh *.rpm
# rpm -qa
# rpm -qa|grep *
# rpm -e *
# rpm -e * --nodeps
制作bash腳本
#!/bin/bash
write cmd line here
# comment
Hard Link(硬鏈接)
$ ln target_file link_file
Symbolic Link(符號鏈接、軟鏈接)
$ ln -s target_file link_file
查找文件
$ find / -name "*"
常用配置文件
/etc/resolv.conf
/etc/hosts
/etc/inittab
/etc/yum.repos.d/
~/.config/user-dirs.dirs
~/.bash_profile
改變Aptana Rubles文件夾默認在家目錄的解決辦法
eclipse.ini文件中,在-vmargs之后添加
-Dstudio.rubleUserLocation=Aptana Rubles
GNOME配置
$ gnome-tweak-tool