Linux web服务器初始化设置
生活随笔
收集整理的這篇文章主要介紹了
Linux web服务器初始化设置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、Linux系統安裝??軟件包安裝?? Development Libraries
?? Development Tools
?? Editors
? ?Base
? ?System Tools
* ?soft ?nofile ?65535
*? hard? nofile ?65535?
ulimit -HSn 65536?
? ? ? ? ? ? ? ? ? ? ?net.ipv4.ip_local_port_range = 1024 65536
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.ipv4.tcp_fin_timeout = 3
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_no_metrics_save=1
net.core.somaxconn = 262144
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1?????????以上參數,主要優化Linux系統網絡參數,優化TCP連接?????????詳細參數請見http://www.cyberciti.biz/faq/linux-kernel-etcsysctl-conf-security-hardening/
2.4、防止密碼被修改????? ????# chattr +i /etc/passwd???????? # chattr +i /etc/shadow????????注:如要修改密碼,先執行????????????chattr -i /etc/passwd????????????chattr -i /etc/shadow?2.5、記錄用戶登錄和歷史記錄?????# vi /etc/profile????在文件尾加入以下內容????????HISTSIZE=5000
????????export HISTTIMEFORMAT="%F %T "????????user=`whoami`
????????ip=`who -u am i | awk '{print $NF}' | sed 's/[()]//g'`
????????dt=`who -u am i | awk '{print $3" "$4}'`
????????date=`date "+%Y-%m-%d"`
????????user_date=/tmp/history/$user/$date
????????history_file=$user_date/$user\_history_$date.txt
????????login_file=$user_date/$user\_login_$date.txt????????if [ ! -d $user_date ]
????????then
????????????????mkdir -p $user_date
????????fi????????printf "$user\t$dt\t$ip\n" >> $login_file
????????chmod 600 $login_file
????????touch $history_file
????????export HISTFILE="$history_file"
????????chmod 600 $history_file結果如下所示:/tmp/history/?????????????????????????????????????????????????????? #歷史記錄目錄
|-- root?????????????????????????????????????????????????????????????? #用戶名
|?? `-- 2012-11-20??????????????????????????????????????????????? #日期
|?????? |-- root_history_2012-11-20.txt?????????????????????#歷史操作記錄
|?????? `-- root_login_2012-11-20.txt???????????????????????#用戶登錄信息(用戶名,時間,登錄IP)
3、Web環境優化
3.1、Nginx參數優化? ? ? # vi /opt/nginx/conf/nginx.conf
worker_rlimit_nofile 51200;
events {
? ? ? ? ? ? ? ? ? ?use epoll;
? ? ? ? ? ? ? ? worker_connections? 51200;
}? ?????備注:使用Linux系統epoll網絡模型,減少系統資源占用,增加IO并發量增加進程描述符和連接數
<value name="max_children">128</value>
<value name="rlimit_files">51200</value>備注:增加php連接數和文件描述符
? ? ? ? ? ? ? ? ? ? ? ? ? ? skip-name-resolve
? ? ? ? ? ? ? ? ? ? ? ? ? ? max_connections = 500
table_open_cache = 2048
sort_buffer_size = 8M
join_buffer_size = 8M
query_cache_size = 64M
key_buffer_size = 32M
? ? ? ? ? ? ? ? ? ?備注:增加mysql連接數,數據庫表,排序,查詢,索引緩存
? ? # cd /etc/yum.repos.d
????# wget?http://mirrors.163.com/.help/CentOS5-Base-163.repo
????# yum makecache????詳細見?http://mirrors.163.com/.help/centos.html
?? Development Tools
?? Editors
? ?Base
? ?System Tools
2、Linux系統環境優化
2.1、優化Linux系統文件描述符
# vi /etc/security/limits.conf* ?soft ?nofile ?65535
*? hard? nofile ?65535?
2.2、讓系統啟動環境添加文件描述符
# vi /etc/rc.localulimit -HSn 65536?
2.3、優化Linux內核參數
? ????????????? #? vi /etc/sysctl.conf? ? ? ? ? ? ? ? ? ? ?net.ipv4.ip_local_port_range = 1024 65536
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.ipv4.tcp_fin_timeout = 3
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_no_metrics_save=1
net.core.somaxconn = 262144
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1?????????以上參數,主要優化Linux系統網絡參數,優化TCP連接?????????詳細參數請見http://www.cyberciti.biz/faq/linux-kernel-etcsysctl-conf-security-hardening/
2.4、防止密碼被修改????? ????# chattr +i /etc/passwd???????? # chattr +i /etc/shadow????????注:如要修改密碼,先執行????????????chattr -i /etc/passwd????????????chattr -i /etc/shadow?2.5、記錄用戶登錄和歷史記錄?????# vi /etc/profile????在文件尾加入以下內容????????HISTSIZE=5000
????????export HISTTIMEFORMAT="%F %T "????????user=`whoami`
????????ip=`who -u am i | awk '{print $NF}' | sed 's/[()]//g'`
????????dt=`who -u am i | awk '{print $3" "$4}'`
????????date=`date "+%Y-%m-%d"`
????????user_date=/tmp/history/$user/$date
????????history_file=$user_date/$user\_history_$date.txt
????????login_file=$user_date/$user\_login_$date.txt????????if [ ! -d $user_date ]
????????then
????????????????mkdir -p $user_date
????????fi????????printf "$user\t$dt\t$ip\n" >> $login_file
????????chmod 600 $login_file
????????touch $history_file
????????export HISTFILE="$history_file"
????????chmod 600 $history_file結果如下所示:/tmp/history/?????????????????????????????????????????????????????? #歷史記錄目錄
|-- root?????????????????????????????????????????????????????????????? #用戶名
|?? `-- 2012-11-20??????????????????????????????????????????????? #日期
|?????? |-- root_history_2012-11-20.txt?????????????????????#歷史操作記錄
|?????? `-- root_login_2012-11-20.txt???????????????????????#用戶登錄信息(用戶名,時間,登錄IP)
3、Web環境優化
3.1、Nginx參數優化? ? ? # vi /opt/nginx/conf/nginx.conf
worker_rlimit_nofile 51200;
events {
? ? ? ? ? ? ? ? ? ?use epoll;
? ? ? ? ? ? ? ? worker_connections? 51200;
}? ?????備注:使用Linux系統epoll網絡模型,減少系統資源占用,增加IO并發量增加進程描述符和連接數
3.2、Php參數優化
?????????????????? # vi /opt/php/etc/php-fpm.conf<value name="max_children">128</value>
<value name="rlimit_files">51200</value>備注:增加php連接數和文件描述符
3.3、Mysql參數優化
?????????????????? # vi /etc/my.cnf? ? ? ? ? ? ? ? ? ? ? ? ? ? skip-name-resolve
? ? ? ? ? ? ? ? ? ? ? ? ? ? max_connections = 500
table_open_cache = 2048
sort_buffer_size = 8M
join_buffer_size = 8M
query_cache_size = 64M
key_buffer_size = 32M
? ? ? ? ? ? ? ? ? ?備注:增加mysql連接數,數據庫表,排序,查詢,索引緩存
4、配置yum更新源
????# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup? ? # cd /etc/yum.repos.d
????# wget?http://mirrors.163.com/.help/CentOS5-Base-163.repo
????# yum makecache????詳細見?http://mirrors.163.com/.help/centos.html
轉載于:https://blog.51cto.com/cqfish/1022362
總結
以上是生活随笔為你收集整理的Linux web服务器初始化设置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL case when then 的
- 下一篇: SqlServer中从字符串中获取项目指