linux運(yùn)維相關(guān)操作(centos/Ubuntu)

1.centos 網(wǎng)絡(luò)配置相關(guān)的文件
/etc/hostname 主機(jī)名配置
/etc/sysconfig/network-scrips/ifcfg-enoN 網(wǎng)卡參數(shù)配置
/etc/resolv.conf DNS配置
/etc/hosts 主機(jī)ip域名配置
重啟網(wǎng)卡 service network restart

網(wǎng)站建設(shè)公司,為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及定制網(wǎng)站建設(shè)服務(wù),專注于企業(yè)網(wǎng)站設(shè)計(jì),高端網(wǎng)頁制作,對(duì)成都輕質(zhì)隔墻板等多個(gè)行業(yè)擁有豐富的網(wǎng)站建設(shè)經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。專業(yè)網(wǎng)站設(shè)計(jì),網(wǎng)站優(yōu)化推廣哪家好,專業(yè)成都網(wǎng)站營銷優(yōu)化,H5建站,響應(yīng)式網(wǎng)站。

2.路由設(shè)置
可以將該命令寫入/etc/rc.d/rc.local 每次開機(jī)都執(zhí)行
route -n 顯示路由信息
route add default gw 192.168.1.254
route del default gw 192.168.1.254
ifconfig eth0:1 10.66.47.1/24 up 配置網(wǎng)卡的子ip
route -p add -net 10.66.47.1/24 gw 10.65.255.254 -p永久生效
route del -net 10.66.47.1/24

3.iptables防火墻
防火墻規(guī)則可以配置到文件:/proc/sys/net/ipv4/ip_forward
iptables -t filter -F 清除所有filter規(guī)則
iptables -nv -L 查看各個(gè)鏈的信息
iptables -t filter -A INPUT -s 10.66.47.2/32 -j ACCEPT
-t 表示用于filter(或nat等)的表,-A 表示新增到哪條鏈路(INPUT FORWARD OUTPUT) -s 子網(wǎng)或主機(jī) -j 動(dòng)作(ACCEPT DROP REJECT)

iptables -A INPUT -p tcp -s 10.66.47.0/24 --dport 22 -j DROP 禁用22號(hào)端口
iptables -D INPUT 1 刪除INPUT的第一條規(guī)則
nc -v 10.66.47.1 443 -w 3 測(cè)試10.66.47.1 的 443端口是否能連通

4.tcpdump
tcpdump -i eth0 tcp and dst host 127.0.0.1 and dst port 3306 -s100 -XX -n (-XX 以16進(jìn)制和ascii顯示,-n不對(duì)主機(jī)轉(zhuǎn)換)
tcpdump tcp port 80 -n -s0 抓取http包 (-s0抓取盡可能大的包65535)
tcpdump tcp host 10.16.2.85 and port 2100 -s 0 -X 

5.dhcp
dpcp服務(wù)器可以為使用dhcp的客戶端網(wǎng)卡動(dòng)態(tài)的分配地址。其過程使用C/S模式,由dhcp客戶端主動(dòng)請(qǐng)求分配ip地址。

6.策略路由配置
ip rule list 查看所有路由表 (local main default)
ip route list table local 查看local表中的路由策略
echo 100 test1 > /etc/iproute2/rt_tables 建立一張id為100的test1路由表
ip rule add from 10.66.47.1/24 table test1 ;來自10.66.47.1/24網(wǎng)路的ip都使用test1表中的規(guī)則
ip rule del table test1 刪除路由表test1
ip route add default via 10.65.47.1 table test1 在test1表中添加了一條默認(rèn)路由
ip route add 10.65.0.0/24 via 10.65.47.1 table test1

7.磁盤管理
fdisk分區(qū)管理
fdisk -l 查看所有磁盤設(shè)備文件及其對(duì)應(yīng)的分區(qū)文件信息
fdisk /dev/sda 進(jìn)入磁盤設(shè)備文件/dev/sda
p 顯示該設(shè)備文件分區(qū)
n 創(chuàng)建一個(gè)分區(qū) 輸入分區(qū)結(jié)束位置
d 刪除分區(qū)
parted分區(qū)管理
parted /dev/sda 進(jìn)入磁盤設(shè)備文件/dev/sda
print 顯示該設(shè)備文件分區(qū)
mkpart 創(chuàng)建一個(gè)分區(qū)
rm 刪除分區(qū)

8.squid代理服務(wù)器配置
局域網(wǎng)通過代理服務(wù)器訪問外網(wǎng)

9.nginx.conf反向代理配置和負(fù)載均衡配置
location ~* .(mp3|mp4)$ { #不區(qū)分大小寫,匹配以mp3或mp4結(jié)束的請(qǐng)求,代理到本地的8080;不修改用戶真實(shí)的ip
proxy_pass http://localhost:8080
}

location / { #匹配任意url,代理到8000,
proxy_pass http://localhost:8000
proxy_set_header X-Forwarded-For $remote_addr
}

負(fù)載均衡配置
http{
upstream backendservers{
ip_hash;
server www.example1.com weight=2;
server www.example2.com weight=1;
server www.example3.com weight=1;
}
server{
listen 80;
server_name www.example.com;
location / {
proxy_pass http://backendservers;
}
}
}

10.MySQL復(fù)制數(shù)據(jù)同步
https://www.cnblogs.com/rwxwsblog/p/4542417.html (單向數(shù)據(jù)同步)
http://blog.csdn.net/swandy45/article/details/6982421 (雙向數(shù)據(jù)同步)

11.防火墻規(guī)則添加
systemctl restart firewalld //重啟防火墻
firewall-cmd --reload //重新加載防火墻配置
systemctl start firewalld.service //開啟服務(wù)
systemctl enable firewalld.service //開機(jī)制動(dòng)啟動(dòng)
systemctl stop firewalld.service //關(guān)閉服務(wù)
systemctl disable firewalld.service //禁止開機(jī)啟動(dòng)
–permanent #永久生效,沒有此參數(shù)重啟后失效
在每次修改 端口和服務(wù)后 /etc/firewalld/zones/public.xml 文件就會(huì)被修改 所以也可以在文件中直接修改 然后reload重新加載

firewall-cmd --permanent --add-port=1234/tcp 對(duì)外暴露該端口
firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.0.4/24" service name="http" accept"//設(shè)置某個(gè)ip 訪問某個(gè)服務(wù)
firewall-cmd --permanent --zone=public --remove-rich-rule="rule family="ipv4" source address="192.168.0.4/24" service name="http" accept" //刪除配置

firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=192.168.0.1/24 port port=80 protocol=tcp accept' //設(shè)置某個(gè)ip段訪問某個(gè)端口
firewall-cmd --permanent --remove-rich-rule 'rule family=ipv4 source address=192.168.0.1/2 port port=80 protocol=tcp accept' //刪除配置

firewall-cmd --query-masquerade # 檢查是否允許偽裝IP
firewall-cmd --add-masquerade # 允許防火墻偽裝IP(端口轉(zhuǎn)發(fā))
firewall-cmd --remove-masquerade# 禁止防火墻偽裝IP

firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080 # 將80端口的流量轉(zhuǎn)發(fā)至8080
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.1.0.1 # 將80端口的流量轉(zhuǎn)發(fā)至192.168.0.1
firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.0.1:toport=8080 # 將80端口的流量轉(zhuǎn)發(fā)至192.168.0.1的8080端口

firewall-cmd –state //獲取 firewalld 狀態(tài)
firewall-cmd –state && echo “Running” || echo “Not running” //狀態(tài)輸出
firewall-cmd –reload //重新加載防火墻
firewall-cmd –get-zones //獲取支持的區(qū)域列表
firewall-cmd –get-services //獲取所有支持的服務(wù)
firewall-cmd –list-all-zones //列出全部啟用的區(qū)域的特性
firewall-cmd [–zone=] –add-interface= //將接口增加到區(qū)域
firewall-cmd [–zone=] –change-interface= //修改接口到區(qū)域
firewall-cmd [–zone=] –remove-interface= //刪除接口到區(qū)域
firewall-cmd [–zone=] –query-interface= //查詢區(qū)域中的接口

12.apache2和centos 網(wǎng)站配置
apache2
1.sudo vi /etc/apache2/sites-available/public_cloud.conf

<VirtualHost *:8000>
ServerName www.nsfocuscontrol.com
ServerAlias nsfocuscontrol12.com
DocumentRoot /home/shanghai/pc_django/PCCon/PCCon

<Directory /home/shanghai/pc_django/PCCon/PCCon>
    Require all granted
</Directory>
WSGIScriptAlias / /home/shanghai/pc_django/PCCon/PCCon/wsgi.py
# WSGIDaemonProcess ziqiangxuetang.com python-path=/home/tu/blog:/home/tu/.virtualenvs/blog/lib/python2.7/site-packages
# WSGIProcessGroup ziqiangxuetang.com

<Directory /home/shanghai/pc_django/PCCon/PCCon>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

</VirtualHost>

2.sudo vim /etc/apache2/ports.conf
// If you just change the port or add more ports here, you will likely also
// have to change the VirtualHost statement in
// /etc/apache2/sites-enabled/000-default.conf

Listen 8000

<IfModule ssl_module>
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

3.更改apache2的運(yùn)行用戶
apache 服務(wù)器運(yùn)行用戶可以在 /etc/apache2/envvars 文件里面改,這里使用的是默認(rèn)值,當(dāng)然也可以更改成自己的當(dāng)前用戶,這樣的話權(quán)限問題就簡單很多,但在服務(wù)器上推薦有 www-data 用戶,更安全。以下是默認(rèn)設(shè)置:
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

4.添加認(rèn)證HEAD
添加文件 /etc/apache2/.htacess 內(nèi)容:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.)
RewriteRule .
- [e=HTTP_AUTHORIZATION:%1]

編輯/etc/apache2/apache2.conf 添加一行:
AccessFileName .htaccess
WSGIPAssAuthorization On

5.sudo vi ~/pc_django/PCCon/PCCon/wsgi.py
添加
import sys
from os.path import join,dirname,abspath
PROJECT_DIR = dirname(dirname(abspath(file)))
sys.path.insert(0,PROJECT_DIR)

6.設(shè)置目錄和文件權(quán)限
假如項(xiàng)目位置在 ~/pc_django/PCCon (在zqxt 下面有一個(gè) manage.py,zqxt 是項(xiàng)目名稱)
一般目錄權(quán)限設(shè)置為 755,文件權(quán)限設(shè)置為 644
cd ~/pc_django/PCCon
sudo chmod -R 644 PCCon
sudo find PCCon -type d | xargs chmod 755

如果是上傳文件的保存目錄或者sqlite3的數(shù)據(jù)庫文件,需要apache執(zhí)行用戶的寫權(quán)限
sudo chgrp -R www-data uploads_dir
sudo chmod -R g+w uploads_dir

7.激活新網(wǎng)站并重啟服務(wù)器
a2ensite /etc/apache2/sites-available/public_cloud.conf
服務(wù)重啟
sudo service apache2 restart 或 sudo service apache2 reload

cat /etc/passwd|cut -f 1 -d:

mount -rw -o remount /

centos

1.sudo vi /etc/apache2/sites-available/public_cloud.conf

<VirtualHost *:8000>
ServerName www.nsfocuscontrol.com
ServerAlias nsfocuscontrol12.com
DocumentRoot /home/shanghai/pc_django/PCCon/PCCon

<Directory /home/shanghai/pc_django/PCCon/PCCon>
    Require all granted
</Directory>
WSGIScriptAlias / /home/shanghai/pc_django/PCCon/PCCon/wsgi.py
# WSGIDaemonProcess ziqiangxuetang.com python-path=/home/tu/blog:/home/tu/.virtualenvs/blog/lib/python2.7/site-packages
# WSGIProcessGroup ziqiangxuetang.com

<Directory /home/shanghai/pc_django/PCCon/PCCon>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

</VirtualHost>

2.sudo vim /etc/apache2/ports.conf
// If you just change the port or add more ports here, you will likely also
// have to change the VirtualHost statement in
// /etc/apache2/sites-enabled/000-default.conf

Listen 8000

<IfModule ssl_module>
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

3.更改apache2的運(yùn)行用戶
apache 服務(wù)器運(yùn)行用戶可以在 /etc/apache2/envvars 文件里面改,這里使用的是默認(rèn)值,當(dāng)然也可以更改成自己的當(dāng)前用戶,這樣的話權(quán)限問題就簡單很多,但在服務(wù)器上推薦有 www-data 用戶,更安全。以下是默認(rèn)設(shè)置:
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

4.添加認(rèn)證HEAD
添加文件 /etc/apache2/.htacess 內(nèi)容:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.)
RewriteRule .
- [e=HTTP_AUTHORIZATION:%1]

編輯/etc/apache2/apache2.conf 添加一行:
AccessFileName .htaccess
WSGIPAssAuthorization On

5.sudo vi ~/pc_django/PCCon/PCCon/wsgi.py
添加
import sys
from os.path import join,dirname,abspath
PROJECT_DIR = dirname(dirname(abspath(file)))
sys.path.insert(0,PROJECT_DIR)

6.設(shè)置目錄和文件權(quán)限
假如項(xiàng)目位置在 ~/pc_django/PCCon (在zqxt 下面有一個(gè) manage.py,zqxt 是項(xiàng)目名稱)
一般目錄權(quán)限設(shè)置為 755,文件權(quán)限設(shè)置為 644
cd ~/pc_django/PCCon
sudo chmod -R 644 PCCon
sudo find PCCon -type d | xargs chmod 755

如果是上傳文件的保存目錄或者sqlite3的數(shù)據(jù)庫文件,需要apache執(zhí)行用戶的寫權(quán)限
sudo chgrp -R www-data uploads_dir
sudo chmod -R g+w uploads_dir

7.激活新網(wǎng)站并重啟服務(wù)器
a2ensite /etc/apache2/sites-available/public_cloud.conf
服務(wù)重啟
sudo service apache2 restart 或 sudo service apache2 reload

cat /etc/passwd|cut -f 1 -d:
mount -rw -o remount /

分享文章:linux運(yùn)維相關(guān)操作(centos/Ubuntu)
文章鏈接:http://muchs.cn/article42/ghecec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作商城網(wǎng)站、標(biāo)簽優(yōu)化網(wǎng)站收錄、定制開發(fā)電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作