查看系統(tǒng)版本和環(huán)境
uname -a
查看所用的linux版本號
cat /etc/issue
查看所用的linux版本號
lsb_release -a
查看所用的linux版本號
python --version
python環(huán)境
perl --version
perl環(huán)境
ruby --version
ruby環(huán)境
java -version
java環(huán)境
node -v
nodejs環(huán)境
gcc --version
gcc環(huán)境
sudo apt-get install language-pack-zh-hans
#配置中文環(huán)境
sudo apt-get install zhcon
#配置中文環(huán)境
安裝軟件
sudo apt-get update
更新軟件源
sudo apt-get upgrade
從軟件源處更新軟件
sudo apt-get autoremove
自動卸載系統(tǒng)不需要的軟件
sudo apt-get install vim
安裝vim編輯器
sudo update-alternatives --config editor
默認編輯設置為vim
sudo apt-get install tmux
tumx用于保持工作現(xiàn)場
sudo apt-get install lnav
安裝終端看訪問日志的神器 lnav
觀看
sudo apt-get install openssh-server
安裝ssh-server,可供遠程登錄
sudo apt-get install git
安裝git,用于管理代碼
sudo apt-get install unrar
安裝rar解壓工具,unrar x test.rar
解壓到當前文件夾
sudo apt-get install zsh
安裝zsh 配置oh-my-zsh
Nginx
參考文檔
sudo apt-get install libpcre3 libpcre3-dev openssl libssl-dev zlib1g-dev
sudo yum -y install gcc automake pcre pcre-devel zlib zlib-devel open openssl-devel
(對比CentOS)
sudo ./configure --prefix=/server/nginx_1_8_2
設置安裝位置
sudo make
sudo make install
sudo path/to/nginx
啟動
sudo path/to/nginx -s reload
重啟
sudo path/to/nginx -s stop
停止
curl localhost
測試是否安裝正確
nginx 403 forbidden
- 缺少index.html或者index.PHP文件
- 目錄權(quán)限:nginx的啟動用戶默認是nginx的,把web目錄的權(quán)限改大释簿,或者是把nginx的啟動用戶改成目錄的所屬用戶糕篇,重起一下就能解決
http://segmentfault.com/a/1190000003067828#articleHeader1
http://macshuo.com/?p=547 趣談個人建站 lnmp 架構(gòu)
使用apt-get安裝 lnmp 架構(gòu)
使用的是root用戶
安裝mysql
apt-get install mysql-server mysql-client
安裝nginx
service apache2 stop update-rc.d -f apache2 remove apt-get remove apache2
apt-get install nginx
service nginx start
curl localhost # 驗證下安裝是否成功
安裝php-fpm
apt-get install php5-fpm
apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php-apc
配置文件 vim /etc/php5/fpm/php.ini
cgi.fix_pathinfo=0
改變php-fpm監(jiān)聽 vi /etc/php5/fpm/pool.d/www.conf
;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000
新建個測試文件 vim /usr/share/nginx/html/info.php
<?php phpinfo(); ?>
重新啟動php5-fpm service php5-fpm reload
重新啟動nginx service nginx reload
錯誤處理 報錯 reload: Unknown instance
sudo pkill php5-fpm; sudo service php5-fpm start
瀏覽器訪問下 localhost/info.php
查看是否支持php以及相關模塊
安裝 Memcache
sudo apt-get install memcached #安裝php memcached 擴展
memcached -d -m 50 -p 11211 -u root #啟動一個memcached服務
-d 是啟動一個守護進程
-m 指定使用多少兆的緩存空間;
-p 指定要監(jiān)聽的端口地梨;
-u 指定以哪個用戶來運行
-l 是監(jiān)聽的服務器ip地址酿联,默認為127.0.0.1
-c是最大并發(fā)連接數(shù)系馆,默認1024
-P是保存pid文件 如/tmp/memcached.pid
使用telnet測試 memcached 服務
$ telnet localhost 11211 Trying 127.0.0.1...Connected to localhost.
ubuntu 16.04 搭建Ubuntu(16.04) + Apache(2.4) + Mysql(5.7) + PHP(7.0)環(huán)境
搭建目標
cky@cky-pc:~/worksapce$ apache2 -v
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2016-04-15T18:00:57
cky@cky-pc:~/worksapce$ mysql --version
mysql Ver 14.14 Distrib 5.7.12, for Linux (x86_64) using EditLine wrapper
PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
安裝并配置apache2.4
sudo apt-get install apache2
sudo vim /etc/apache2/apache2.conf
// 將 <Directory /var/www/>
// 改成 <Directory "你的目錄">
sudo vim /etc/apache2/sites-available/000-default.conf
// 將 DocumentRoot /var/www/html
// 改成 DocumentRoot "你的目錄"
sudo /etc/init.d/apache2 restart
安裝php7.0
sudo apt-get install php7.0
sudo apt-get install libapache2-mod-php7.0
安裝更多的模塊
sudo apt-get install php7.0[tab]
安裝數(shù)據(jù)庫
sudo apt-get install mysql-server mysql-client
sudo apt-get install php7.0-mysql
操作數(shù)據(jù)庫
/etc/init.d/mysql start|stop|restart
搭建lamp開發(fā)環(huán)境
sudo apt-get install apache2 memcached php5 mysql-server mysql-client php5-memcached curl php5-curl
sudo apt-get install php5-gd php5-mcrypt php5-imagick php5-intl php5-apcu php5-sqlite php5-pgsql php5-mysqlnd
開啟 Mcrypt 模塊
sudo php5enmod mcrypt
sudo service apache2 restart
apache 相關的
http://blog.csdn.net/u013178760/article/details/45393183 Apache 2.4 Rewrite 模塊
http://blog.csdn.net/u013178760/article/details/48436777 Apache2 虛擬主機配置
安裝apache
sudo apt-get install apache2
開啟和關閉模塊
sudo a2enmod rewrite #啟用rewrite模塊
sudo a2dismod rewrite #禁用rewrite模塊
開啟和關閉站點
sudo a2ensite sitename #啟用站點
sudo a2dissite sitename #停用站點
允許使用.htaccess
AllowOverride None 改為 AllowOverride All
重啟|開啟|關閉apache
sudo service apache2 restart|start|stop 重啟|開啟|關閉apache
sudo /etc/init.d/apache2 restart|start|stop 重啟|開啟|關閉apache
url重寫
http://www.example.com/USA/California/San_Diego
“/USA/California/San_Diego” 是能夠Rewrite的字符串像鸡!
重寫:就是實現(xiàn)URL的跳轉(zhuǎn)和隱藏真實地址粉渠,基于Perl語言的正則表達式規(guī)范。平時幫助我們實現(xiàn)擬靜態(tài)胁镐,擬目錄偎血,域名跳轉(zhuǎn),防止盜鏈等
.htaccess
RewriteEnine on
RewriteRule ^/t_(.*).html$ /test.php?id = $1#當訪問任何以t_開頭希停,以.html結(jié)尾的文件時烁巫,將$1用與(.*)匹配的字符替換后署隘,訪問相應的test.php頁面RewriteRule ^/test([0-9]*).html$ /test.php?id=$1RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]#當我們訪問的地址不是以www.163.com開頭的宠能,那么執(zhí)行下一條規(guī)則RewriteCond %{HTTP_HOST} !^www.163.com [NC]RewriteRule ^/(.*) http://www.163.com/ [L]
Apache Rewrite規(guī)則修正符
1) R 強制外部重定向
2) F 禁用URL,返回403HTTP狀態(tài)碼。
3) G 強制URL為GONE磁餐,返回410HTTP狀態(tài)碼违崇。
4) P 強制使用代理轉(zhuǎn)發(fā)。
5) L 表明當前規(guī)則是最后一條規(guī)則诊霹,停止分析以后規(guī)則的重寫羞延。
6) N 重新從第一條規(guī)則開始運行重寫過程。
7) C 與下一條規(guī)則關聯(lián) 如果規(guī)則匹配則正常處理脾还,以下修正符無效
8) T=MIME-type(force MIME type) 強制MIME類型
9) NS 只用于不是內(nèi)部子請求
10) NC 不區(qū)分大小寫
11) QSA 追加請求字符串
12) NE 不在輸出轉(zhuǎn)義特殊字符 \%3d$1 等價于 =$1
核心模塊
core_module,so_module,http_module,mpm
全局配置指令
#表示apache2這個軟件安裝的目錄
ServerRoot "/usr/local/apache2"
#監(jiān)聽端口命令 Listen ip:portListen 80
#加載動態(tài)模塊伴箩,
LoadModule 模塊名 模塊路徑
LoadModule php5_module modules/libphp5.so
#是否加載某個模塊容器
<IfModule ></IfMoudle>
#設置先讀取 index.php 文件
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#留下管理員郵箱
ServerAdmin 1162097842@qq.com
#用于多個域名訪問同一個ip時,辨別它們訪問的主機
ServerName pms.com
#設置主機所有文檔的根目錄
DocumentRoot "/var/www/html"
# 默認目錄訪問的文件
DirectoryIndex index.html index.htm index.php
添加默認字符集 AddDefaultCharset GB2312
監(jiān)聽ip是192.168.1.1的地址和端口為80創(chuàng)建虛擬目錄
Alias /down "/sofТWare /download" 創(chuàng)建名為down的虛擬目錄鄙漏,它對應的物理路徑是:/sofТWare /download
設置目錄權(quán)限<Directory "目錄路徑"> 此次寫設置目錄權(quán)限的語句
Options FollowSymLinks 允許符號鏈接 Options Indexes 允許用戶瀏覽網(wǎng)頁目錄嗤谚,(不安全的設置棺蛛,建議刪除)
AllowOverride None 不允許 .htaccess 重寫這個目錄,改為 All 則能重寫
</Directory>
Set Search Domain
在Ubuntu設置IPv4時巩步,
ip 地址 : 10.10.10.19
子網(wǎng)掩碼 : 24
網(wǎng)關: 10.10.10.1
DNS服務器:119.29.29.29,114.114.114.114
搜索域:lingyunstrong.com
cky@cky-pc:~$ ping a
PING a.lingyunstrong.com (183.16.2.95) 56(84) bytes of data.
64 bytes from 183.16.2.95: icmp_seq=1 ttl=64 time=0.595 ms
64 bytes from 183.16.2.95: icmp_seq=8 ttl=64 time=0.655 ms
^C
--- a.lingyunstrong.com ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 6997ms
rtt min/avg/max/mdev = 0.595/0.657/0.683/0.036 ms
cky@cky-pc:~$
cky@cky-pc:~$ ping cky
PING cky.lingyunstrong.com (10.10.10.19) 56(84) bytes of data.
64 bytes from 10.10.10.19: icmp_seq=1 ttl=64 time=0.026 ms
64 bytes from 10.10.10.19: icmp_seq=2 ttl=64 time=0.025 ms
^C
--- cky.lingyunstrong.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.025/0.025/0.026/0.005 ms
cky@cky-pc:~$ ping cky.linyunstrong.com
PING cky.linyunstrong.com.lingyunstrong.com (183.16.2.95) 56(84) bytes of data.
64 bytes from 183.16.2.95: icmp_seq=1 ttl=64 time=0.594 ms
64 bytes from 183.16.2.95: icmp_seq=4 ttl=64 time=0.648 ms
^C
--- cky.linyunstrong.com.lingyunstrong.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 0.594/0.629/0.662/0.036 ms
cky@cky-pc:~$ ping a
PING a.lingyunstrong.com (183.16.2.95) 56(84) bytes of data.
64 bytes from 183.16.2.95: icmp_seq=1 ttl=64 time=0.587 ms
64 bytes from 183.16.2.95: icmp_seq=3 ttl=64 time=0.641 ms
^C
--- a.lingyunstrong.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.587/0.628/0.658/0.041 ms
cky@cky-pc:~$ ping baidu.com
PING baidu.com (180.149.132.47) 56(84) bytes of data.
64 bytes from 180.149.132.47: icmp_seq=1 ttl=54 time=36.8 ms
64 bytes from 180.149.132.47: icmp_seq=4 ttl=54 time=39.6 ms
^C
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 36.188/37.903/39.637/1.439 ms
cky@cky-pc:~$ ping sina.com
PING sina.com (66.102.251.33) 56(84) bytes of data.
^C
--- sina.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1007ms
安裝monaco字體
進入github下載這個字體旁赊,github地址是https://github.com/cstrap/monaco-font
sudo ./install-font-ubuntu.sh https://github.com/todylu/monaco.ttf/blob/master/monaco.ttf?raw=true
這個命令
追蹤路由
? blog git:(master) sudo traceroute m.dev.yunchongba.com
traceroute to m.dev.yunchongba.com (120.25.71.101), 30 hops max, 60 byte packets
1 10.10.10.1 (10.10.10.1) 0.587 ms 0.584 ms 0.576 ms
2 183.15.192.1 (183.15.192.1) 6.095 ms 6.930 ms 6.930 ms
3 113.106.44.53 (113.106.44.53) 6.070 ms 7.084 ms 7.552 ms
4 119.145.47.185 (119.145.47.185) 7.049 ms 7.318 ms 7.317 ms
5 183.56.65.6 (183.56.65.6) 12.428 ms 183.56.65.14 (183.56.65.14) 12.696 ms 183.56.65.18 (183.56.65.18) 11.576 ms
6 202.97.85.114 (202.97.85.114) 27.501 ms * *
7 220.191.200.14 (220.191.200.14) 32.215 ms 220.191.200.18 (220.191.200.18) 28.028 ms *
8 115.236.101.221 (115.236.101.221) 32.115 ms 115.238.21.117 (115.238.21.117) 32.036 ms 115.236.101.213 (115.236.101.213) 34.018 ms
9 42.120.247.109 (42.120.247.109) 30.852 ms 42.120.247.53 (42.120.247.53) 33.999 ms 42.120.247.57 (42.120.247.57) 30.814 ms
10 42.120.239.138 (42.120.239.138) 58.777 ms 58.821 ms 42.120.242.81 (42.120.242.81) 58.187 ms
11 42.120.239.134 (42.120.239.134) 56.089 ms 42.120.239.158 (42.120.239.158) 52.129 ms 42.120.239.146 (42.120.239.146) 57.078 ms
12 42.120.253.6 (42.120.253.6) 50.913 ms 51.081 ms 42.120.253.2 (42.120.253.2) 54.589 ms
13 42.120.253.6 (42.120.253.6) 50.205 ms * *