服务器采购腾讯云S2系列,Intel Xeon E5-2680 v4(2.4 GHz),4核16G,内网带宽1.5Gbps,公网带宽5Mbps。
使用版本CentOS release 6.10 (Final):
(1)查看Linux版本
cat /etc/redhat-release
(2)查看内核版本
uname -a
(1)实时监控Linux系统状况,cpu、内存、用户数、进程
top -m
(2)系统实时活动情况报告
sar 1
(System ActivityReporter系统活动情况报告)文件的读写情况、系统调用的使用情况、磁盘I/O、CPU效率、内存使用状况、进程活动及IPC有关的活动
(3)服务器处理连接任务情况
netstat -n | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
(4)查看所有磁盘分区信息
fdisk -l
(5)查看文件系统磁盘格式、空间占用、挂载位置情况
df -h
(6)查看网卡
ip a s
(7)查看端口
netstat -ant
//列出所有TCP的连接
netstat -npl
//查看服务器端口工作状态
netstat -s
//显示自从系统启动以来,各个协议的总体数据信息。
(8)查看进程
ps -ef
(9)查看IO使用磁盘平均使用率
iostat -x 1 2
(10)查看进程明细
pidstat -w -t -l -C “关键字”
(11)监控网络数据收发
sar -n TCP,UDP 1
(12)查看系统资源使用限制
ulimit -a
[root@VM-0-15-centos ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 31384
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 31384
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
find / -name 文件名
[root@VM-0-15-centos ~]# find / -name redis
/data/redis
/etc/rc.d/init.d/redis
/etc/redis
[root@VM-0-15-centos ~]# find / -name php-fpm.conf
/root/php-7.3.15/sapi/fpm/php-fpm.conf
/usr/local/php/etc/php-fpm.conf
(1)查看软件是否安装
rpm -qa | grep 软件名
//查看软件是否安装返回版本信息
[root@VM-0-15-centos ~]# rpm -qa | grep vsftp
vsftpd-2.2.2-24.el6.x86_64
rpm -qal | grep 软件名
//返回软件安装包相关所有文件路径
[root@VM-0-15-centos ~]# rpm -qal | grep vsftp
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/rc.d/init.d/vsftpd
/etc/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
/etc/vsftpd/vsftpd_conf_migrate.sh
/usr/sbin/vsftpd
/usr/share/doc/vsftpd-2.2.2
/usr/share/doc/vsftpd-2.2.2/AUDIT
/usr/share/doc/vsftpd-2.2.2/BENCHMARKS
/usr/share/doc/vsftpd-2.2.2/BUGS
/usr/share/doc/vsftpd-2.2.2/COPYING
/usr/share/doc/vsftpd-2.2.2/Changelog
/usr/share/doc/vsftpd-2.2.2/EXAMPLE
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE/README
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE/README.configuration
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE/vsftpd.conf
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE/vsftpd.xinetd
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE_NOINETD
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE_NOINETD/README
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE_NOINETD/README.configuration
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/PER_IP_CONFIG
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/PER_IP_CONFIG/README
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/PER_IP_CONFIG/README.configuration
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/PER_IP_CONFIG/hosts.allow
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/README
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_HOSTS
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_HOSTS/README
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS/README
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS/README.configuration
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS/logins.txt
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS/vsftpd.conf
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS/vsftpd.pam
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS_2
/usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS_2/README
/usr/share/doc/vsftpd-2.2.2/FAQ
/usr/share/doc/vsftpd-2.2.2/INSTALL
/usr/share/doc/vsftpd-2.2.2/LICENSE
/usr/share/doc/vsftpd-2.2.2/README
/usr/share/doc/vsftpd-2.2.2/README.security
/usr/share/doc/vsftpd-2.2.2/REWARD
/usr/share/doc/vsftpd-2.2.2/SECURITY
/usr/share/doc/vsftpd-2.2.2/SECURITY/DESIGN
/usr/share/doc/vsftpd-2.2.2/SECURITY/IMPLEMENTATION
/usr/share/doc/vsftpd-2.2.2/SECURITY/OVERVIEW
/usr/share/doc/vsftpd-2.2.2/SECURITY/TRUST
/usr/share/doc/vsftpd-2.2.2/SIZE
/usr/share/doc/vsftpd-2.2.2/SPEED
/usr/share/doc/vsftpd-2.2.2/TODO
/usr/share/doc/vsftpd-2.2.2/TUNING
/usr/share/doc/vsftpd-2.2.2/vsftpd.xinetd
/usr/share/man/man5/vsftpd.conf.5.gz
/usr/share/man/man8/vsftpd.8.gz
/usr/share/augeas/lenses/dist/vsftpd.aug
/usr/lib/python2.6/site-packages/sos/plugins/vsftpd.py
/usr/lib/python2.6/site-packages/sos/plugins/vsftpd.pyc
/usr/lib/python2.6/site-packages/sos/plugins/vsftpd.pyo
(2)查找软件安装路径
whereis 软件名
[root@VM-0-15-centos ~]# whereis php
php: /usr/bin/php /usr/local/php
(3)查找软件运行文件所在路径(执行文件)
which 软件名
[root@VM-0-15-centos ~]# which php
/usr/bin/php
(1)用户组列表
cat /etc/group
(2)用户列表
cat /etc/passwd
(3)查看可以登录系统的用户
cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1
(4)查看登录用户
who
(5)查看用户登录历史记录
last
(6)root权限修改其他用户密码
passwd
(1)SecureCRT (个人推荐)
(2)PuTTY
FileZilla
(1)查询是否安装
rpm -q vsftpd
[root@VM-0-15-centos ~]# rpm -q vsftpd
vsftpd-2.2.2-24.el6.x86_64
(2)检查vsftpd是否运行
netstat -ntpl | grep vsftpd
[root@VM-0-15-centos ~]# netstat -ntpl | grep vsftpd
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1645/vsftpd
(3)启动vsftpd服务
service vsftpd start
(4)开机自启动
chkconfig vsftpd on
[root@VM-0-15-centos ~]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@VM-0-15-centos ~]# chkconfig vsftpd on
[root@VM-0-15-centos ~]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
(1)阻止匿名访问和切换根目录
vim /etc/vsftpd/vsftpd.conf
anonymous_enable=NO #禁用匿名用户
chroot_local_user=YES # 禁止切换根目录
chroot_list_enable=NO #是否启用chroot_list_file配置项指定的用户列表文件
chroot_list_file=/etc/vsftpd/chroot_list #哪些用户可以切换到自家目录的上级
service vsftpd restart
(2)添加登录白名单
vi /etc/vsftpd/vsftpd.conf
#配置用户拦截机制,启用 /etc/vsftpd/user_list 文件且设置为白名单
userlist_enable=YES
userlist_deny=NO
vim /etc/vsftpd/user_list
用户名1
用户名2
...
在列表中添加用户名
(1)用户
useradd -d /home/ftpuser ftpuser
passwd ftpuser
chmod –R 777 /home/ftpuser
(2)用户组
groupadd webgroup
usermod -G groupname username
//添加到指定组,但以前添加的组会清空gpasswd -a username groupname
//添加用户到一个组,并保留以前添加的组使用版本 nginx/1.16.1
ps -ef | grep nginx
[root@VM-0-15-centos ~]# ps -ef | grep nginx
root 1744 1 0 Feb13 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www 1746 1744 0 Feb13 ? 00:00:03 nginx: worker process
root 22781 18418 0 15:22 pts/0 00:00:00 grep nginx
service nginx status
[root@VM-0-15-centos ~]# service nginx status
nginx (pid 1746 1744) is running...
(1)查找nginx目录
find /(查找范围) -name nginx -type d
[root@VM-0-15-centos ~]# find / -name nginx -type d
/usr/local/nginx
(2)查找nginx配置文件
find /(查找范围) -name nginx.conf -print
[root@VM-0-15-centos ~]# find /usr -name nginx.conf -print
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx -t
[root@VM-0-15-centos ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
(1)启动
/usr/local/nginx/sbin/nginx
(2)关闭
/usr/local/nginx/sbin/nginx -s stop
(3)重启
/usr/local/nginx/sbin/nginx -s reload
chkconfig --add nginx
chkconfig nginx on
[root@VM-0-15-centos ~]# chkconfig --list nginx
nginx 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@VM-0-15-centos ~]# chkconfig nginx on
[root@VM-0-15-centos ~]# chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
server {
listen 80;
server_name domain.com;
set $root_path '/data/www/laravel/public';
location / {
root $root_path;
index index.php index.html;
# Nginx找不到文件时,转发请求给后端Apache
error_page 404 @proxy;
# css, js 静态文件设置有效期1天
location ~ .*\.(js|css)$ {
access_log off;
expires 1d;
}
# 图片设置有效期3天
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
access_log off;
expires 3d;
}
}
# 动态文件.php请求转发给后端Apache
location ~ \.php$ {
#proxy_redirect off;
#proxy_pass_header Set-Cookie;
#proxy_set_header Cookie $http_cookie;
# 传递真实IP到后端
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
location @proxy {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
}
server {
listen 80;
server_name bi.mydomain.cn;
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server {
listen 443 ssl;
server_name bi.brandsstory.cn;
index index.php;
root /home/web/bi/public;
ssl_certificate /usr/local/nginx/cert/1_bi.mydomain.cn_bundle.crt;
ssl_certificate_key /usr/local/nginx/cert/2_bi.mydomain.cn.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
#为了使Laravel正常工作,所有的请求都应该被传递给Laravel本身,即所有的请求 都被传递给了index.php,Laravel的应用主文件。如果这一步没有配置,那么我们 只能够打开项目主页,其余页面将无法跳转。
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
root /home/web/bi/public;
#trim on;
#fastcgi_pass 127.0.0.1:9001;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
#fastcgi_index index.php;
}
ps -elf |grep nginx
[root@VM_0_15_centos ~]# ps -elf |grep nginx
1 S root 27008 1 0 80 0 - 11909 sys_rt Aug31 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
5 S www 27009 27008 0 80 0 - 24758 ep_pol Aug31 ? 02:01:25 nginx: worker process
0 R root 27801 27641 0 80 0 - 25831 - 11:26 pts/0 00:00:00 grep nginx
[root@VM_0_15_centos ~]# cat /proc/27009/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 10485760 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 63691 63691 processes
Max open files 65535 65535 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 63691 63691 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
公式
max_clients = worker_processes * worker_connections/2
公式
max_clients = worker_processes * worker_connections/4
一般一个进程足够了,你可以把连接数设得很大。(worker_connections: 10,000)
如果有SSL、gzip这些比较消耗CPU的工作,而且是多核CPU的话,可以设为和CPU的数量一样。(worker_processes: CPU核心数)
或者要处理很多很多的小文件,而且文件总大小比内存大很多的时候,也可以把进程数增加,以充分利用IO带宽(主要似乎是IO操作有block)
//0001表示启用第一个CPU内核,0010表示启用第二个CPU内核,依此类推
//2核是 01,四核是0001,8核是00000001,有多少个核,就有几位数,1表示该内核开启,0表示该内核关闭。
1)connections不是随便设置的,而是与两个指标有重要关联,一是内存,二是操作系统级别的“进程最大可打开文件数”。
2)内存:每个连接数分别对应一个read_event和write_event事件,一个连接数大概占用232字节,2个事件总占用96字节,一个连接总共占用328字节,65535个连接数大概会占用内存: 65535 * 328 / 1024 / 1024 = 20.5M
3)单进程最大可打开文件数:可打开文件数受限于操作系统,可通过 ulimit -n 命令查询,以前是1024,现在是65535,
4)worker_rlimit_nofile 65535;
nginx提供的最大可打开文件数指令,该指令与使用ulimit对用户的设置是同样的效果,此指令的值将覆盖ulimit的值
ps -ef | grep httpd
find / -name 'httpd'
(1)启动
service httpd start
(2)停止
service httpd stop
(3)重启
service httpd restart
(4)开机自启动
chkconfig --add httpd
chkconfig httpd on
编辑httpd配置文件
vim /etc/httpd/conf/httpd.conf
(1)全局环境
ServerTokens OS //告知用户端WWW服务器的版本与操作系统
ServerRoot "/etc/httpd" //Apache安装路径
PidFile run/httpd.pid //放置PID的目录,方便软件管理,是相对路径
Timeout 120 //持续连接如果等待超过120秒则连接断开
KeepAlive Off //是否允许持续性的连接,预设为否
MaxKeepAliveRequests 100 //保持的连接的人数,改成0就是说没有人数的限制
KeepAliveTimeout 15 //在允许KeepAlive条件下,保持连接的超出时间
Listen 80 //监听的端口号
LoadModule access_module modules/mod_access.so
……(下面省略)显示载入的模块组
Include conf.d/*.conf使得目录/etc/httpd/conf.d/下的配置文件*.conf都会被读入
User apache //子进程的用户
Group apache //由谁启动Apache服务器
(2)主服务配置
ServerAdmin root@localhost //网页出错给谁发信通知
UseCanonicalName Off //是否使用标准主机名称,预设为否
DocumentRoot "/var/www/html" //网页存放的路径,文档的根目录
DirectoryIndex index.html //定义主页文件
AddDefaultCharset UTF-8 //字符编码,中文需要改为gb2312或者gbk
<Directory "/var/www/html"> # 网站容器开始标识
Options Indexes FollowSymLinks //找不到主页时,以目录的方式呈现,并允许链接到网站根目录以外
AllowOverride None //none不使用.htaccess控制,all允许
Require all granted //granted表示运行所有访问,denied表示拒绝所有访问
</Directory> # 容器结束
本章完