可參考:php
https://blog.51cto.com/zero01/2052407
https://blog.51cto.com/zero01/2052428
https://blog.51cto.com/zero01/2052429css
location優先級: https://dev.tencent.com/u/aminglinux/p/nginx/git/blob/master/location/priority.mdhtml
301 、302規則: 跳轉兩種:1)跳域名 2)跳網址的 (uri) 301 --> 域名 302 --> 網址
設置zabbix 及源碼安裝(以此爲準) https://www.cnblogs.com/sanduzxcvbnm/p/6138642.html?utm_source=itdadao&utm_medium=referralmysql
兩臺Linux系統之間傳輸文件的幾種方法: https://blog.csdn.net/gatieme/article/details/51673229linux
8005端口啓動慢:https://github.com/aminglinux/linux2019/blob/master/4.61-%E7%AC%AC%E4%BA%8C%E4%B8%AAJAVA%E5%BA%94%E7%94%A8.mdnginx
配置nginx負載均衡時的後端服務器的健康檢查:https://dev.tencent.com/u/aminglinux/p/nginx/git/blob/master/proxy/lb.md案例三下方說明部分git
什麼是廣域網和局域網?https://help.aliyun.com/knowledge_detail/40637.html?spm=a2c4g.11186623.6.847.bd20161bSBq3KU#h2-url-2github
關於nginx的文檔 nginx.aminglinux.comweb
不作重點參考:sql
http://www.javashuo.com/article/p-eeasizkv-bc.html https://blog.csdn.net/u011709380/article/details/94149736 https://blog.csdn.net/u011709380/article/details/94208304 https://blog.csdn.net/u011709380/article/details/94298012
yum安裝nginx添加開機自啓動:
systemctl enable nginx.service
取消開機自啓動:
systemctl disable nginx.service
查看服務是否開機自啓動:
systemctl is-enabled nginx
mysql 老是顯示pid 各類問題,最後實際上是內存過低,須要性能調優,此處的雲主機內存爲0.5,也會致使mysql沒法啓動,或啓動中自動關閉
[mysqld] datadir=/data/mysql socket=/tmp/mysql.sock log-error=/data/mysql/error.log key_buffer=16K table_open_cache=4 query_cache_limit=256K query_cache_size=4M max_allowed_packet=1M sort_buffer_size=64K read_buffer_size=256K thread_stack=64K innodb_buffer_pool_size = 56M
配置nginx默認虛擬主機,把nginx配置文件裏定義的虛擬主機刪除 vim /usr/local/nginx/conf/nginx.conf #並添加如下內容 include vhost/*.conf; include /usr/local/nginx/conf/vhost/*.conf; 建立目錄 mkdir /usr/local/nginx/conf/vhost
首先安裝httpd: yum install -y httpd 而後使用httpd裏的htpasswd 命令去生成一個用戶密碼文件: htpasswd -c /usr/local/nginx/conf/htpasswd admin New password: Re-type new password: Adding password for user admin 生成完成後cat一下htpasswd 文件能夠看到以下內容: cat /usr/local/nginx/conf/htpasswd admin:$apr1$bwCvGuw9$71cc8LnzGEG0AEiSSB1uO. 若是還須要再次添加用戶的話就不須要加上-c選項了,加上-c選項會覆蓋原來的htpasswd 文件。
從新加載nginx的配置文件:
/usr/local/nginx/sbin/nginx -t /usr/local/nginx/sbin/nginx -s reload
搭建dedecms
建立默認站點目錄
mkdir /data/wwwroot/dedecms.com/
cd /usr/local/src/ wget http://updatenew.dedecms.com/base-v57/package/DedeCMS-V5.7-UTF8-SP2.tar.gz tar -zxvf DedeCMS-V5.7-UTF8-SP2.tar.gz mv DedeCMS-V5.7-UTF8-SP2/uploads/* /data/wwwroot/dedecms.com/
建立並編輯虛擬主機配置文件
vim /usr/local/nginx/conf/vhost/dedecms.com.conf server { listen 80; server_name www.dedecms.com; index index.html index.htm index.php; root /data/wwwroot/dedecms.com; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/dedecms.com$fastcgi_script_name; } location ^~ /dedecms/ { auth_basic "Auth"; auth_basic_user_file /usr/local/nginx/conf/htpasswd; #密碼文件路徑 } access_log /tmp/dedecms.com.log combined_realip; }
建立默認站點目錄
mkdir /data/wwwroot/discuz.com/
下載discuz主程序
cd /usr/local/src/ wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_UTF8.zip unzip Discuz_X3.3_SC_UTF8.zip mv upload/* /data/wwwroot/discuz.com/
建立並編輯虛擬主機配置文件
vim /usr/local/nginx/conf/vhost/discuz.com.conf server { listen 80; server_name www.discuz.com; index index.html index.htm index.php; root /data/wwwroot/discuz.com; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/discuz.com$fastcgi_script_name; } location ^~ /admin.php { auth_basic "Auth"; auth_basic_user_file /usr/local/nginx/conf/htpasswd; } access_log /tmp/discuz.com.log combined_realip; }
建立默認站點目錄
mkdir /data/wwwroot/zrlog.com/
下載zrlog主程序 cd /usr/local/src/ wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war unzip zrlog-1.7.1-baaecb9-release.war unzip zrlog-1.7.1-baaecb9-release.war -d /data/wwwroot/zrlog.com
編輯虛擬主機配置文件
vim /usr/local/tomcat/conf/server.xml
<Host name="www.zrlog.com" appBase="" unpackWARs= "true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="/data/wwwroot/zrlog.com/" debug="0" reloadable="true" crossContext="true"/> </Host>
編輯nginx的反向代理配置文件
vim /usr/local/nginx/conf/vhost/zrlog.com.conf
server { listen 80; server_name www.zrlog.com; location / { proxy_pass http://127.0.0.1:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /admin/ { auth_basic "Auth"; auth_basic_user_file /usr/local/nginx/conf/htpasswd; proxy_pass http://127.0.0.1:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /admin/ { auth_basic "Auth"; auth_basic_user_file /usr/local/nginx/conf/htpasswd; proxy_pass http://127.0.0.1:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log /tmp/zrlog.com.log combined_realip; }
編輯php-fpm的配置文件,並以下添加內容:
vim /usr/local/php-fpm/etc/php-fpm.conf
request_slowlog_timeout = 2 # 定義超過2秒就要記錄日誌 slowlog = /usr/local/php-fpm/var/log/www-slow.log # 定義日誌文件的存放路徑
修改完成,測試一下配置文件的語法,並從新加載配置文件:
/usr/local/php-fpm/sbin/php-fpm -t
日誌切割
vim /usr/local/sbin/phpslow_logrotate.sh
#! /bin/bash d=`date -d "-1 day" +%Y%m%d` logdir="/usr/local/php-fpm/var/log/" nginx_pid="/usr/local/nginx/logs/nginx.pid" cd $logdir for log in `ls *.log` do mv $log $log-$d done /bin/kill -HUP `cat $nginx_pid`
寫完腳本後,須要按期的自動執行日誌切割,因此咱們要設置一個任務計劃:
crontab -e
## 增長如下內容,這是定義0點的時候執行這個腳本 0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh 日誌只保留一個月,還須要往crontab裏添加如下這一行,每月的1號就刪除一次舊的日誌文件: * * 1 * * /usr/bin/find /usr/local/php-fpm/var/log/ -name *.log.* -type f -mtime +30 |xargs rm
訪問日誌
在nginx裏,日誌的格式能夠在主配置文件裏定義,編輯主配置文件:
vim /usr/local/nginx/conf/nginx.conf
搜索log_format,這一段就是用來定義日誌格式的: log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"'; 其中的combined_realip是日誌的名稱,這個名稱能夠自定義。
獲取到日誌名稱後編輯站點的虛擬主機配置文件:
vim /usr/local/nginx/conf/vhost/discuz.com.conf
增長如下內容: access_log /tmp/discuz.com.log combined_realip; #日誌的目錄能夠本身定義 這裏的combined_realip就是在nginx.conf中定義的日誌格式名字。 而後從新加載配置文件: /usr/local/nginx/sbin/nginx -t /usr/local/nginx/sbin/nginx -s reload
vim /usr/local/nginx/conf/vhost/discuz.com.conf
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 7d; access_log off; } location ~ .*\.(js|css)$ { expires 12h; access_log off; } 配置完後從新加載配置文件: /usr/local/nginx/sbin/nginx -t /usr/local/nginx/sbin/nginx -s reload
至於日誌切割其實就修改一下以前那個腳本文件便可,把logdir變量定義的路徑換成參數的形式,而後在定時任務計劃裏傳遞相應的路徑便可:
vim /usr/local/sbin/nginx_log_rotate.sh
#! /bin/bash d=`date -d "-1 day" +%Y%m%d` logdir="$1" nginx_pid="/usr/local/nginx/logs/nginx.pid" cd $logdir for log in `ls *.log` do mv $log $log-$d done /bin/kill -HUP `cat $nginx_pid` crontab -e 0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh "/usr/local/php-fpm/var/log/" 0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh "/data/wwwroot/discuz.com/data/log/" * * 1 * * /usr/bin/find /usr/local/php-fpm/var/log/ -name *.log.* -type f -mtime +30 |xargs rm * * 1 * * /usr/bin/find /data/wwwroot/discuz.com/data/log/ -name *.log.* -type f -mtime +30 |xargs rm 剩下的站點都是和以上步驟同樣照葫蘆畫瓢便可,最後將文件都同步到其餘web服務器上就能夠了。
使用visudo命令編輯配置文件,設置用戶的alias: User_Alias ADMINS = user1, user2, user3
而後批量執行useradd命令在所有服務器上添加user一、user二、user3用戶
找到Allow root to run any commands anywhere,在這行下面添加如下內容:
ADMINS ALL=(ALL) NOPASSWD: /usr/bin/su, /usr/bin/ls, /usr/bin/cat, /usr/bin/mkdir
sshd.config配置文件,修改如下內容:
vim /etc/ssh/sshd_config PermitRootLogin no PubkeyAuthentication yes PasswordAuthentication no 重啓服務:systemctl restart sshd.service
服務器A生成公鑰 ssh-keygen
查看公鑰內容 cat .ssh/id_rsa.pub
登陸服務器B,設置權限 .ssh/authorized_keys chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys