安装 ngnix 1 tar -zxvf nginx-1.18.0.tar.gz 
1 2 3 4 5 6 7 8 9 yum install pcre -y yum install pcre-devel -y yum install zlib -y yum install zlib-devel -y yum install openssl openssl-devel -y yum install lsof -y yum install -y unzip zip yum install -y vim* yum -y install gcc gcc-c++ autoconf automake make 
1 2 cd nginx-1.18.0 ./configure --prefix=/usr/local/nginx --with-http_ssl_module 
注意:如果出现这个错误: ./configure: error: C compiler cc is not found 执行命令:yum -y install gcc gcc-c++ autoconf automake make
 
出现*** 没有规则可以创建“default”需要的目标“build”。 停止。问题:安装依赖和 make && make install 顺序出现了错乱。
 
在 /usr/local/nginx 目录下,可以看到如下4个目录: conf 配置文件,html网页文件,logs日志文件,sbin主要二进制程序
 
访问不到有可能是防火墙未开启80端口
 
ngnix 日志切片 编写脚本
1 2 3 4 5 6 7 8 9 10 11 LOGPATH=/data/wwwlogs/ngnix/pc_websocket_access.log BASEPATH=/home/data/wwwlogs/websocket YESTERDAY=$(date -d yesterday +%Y-%m-%d) BAK=$BASEPATH /${YESTERDAY} _access.log mv $LOGPATH  $BAK  /usr/local /nginx/sbin/nginx -s reopen 
如果执行时报错:pcaccelog.sh:行6: $’\r’: 未找到命令,是因为将 mac 或者 windows 的文件复制到 linux 的结果,需要下载软件 
1 2 3 yum install dos2unix -y dos2unix pcwebsocketlog.sh  chmod -x pcwebsocketlog.sh 
然后执行,最后执行
1 2 3 4 crontab -e 0 0 * * * /bin/bash /user/local /ngnix/xxx.sh crontab -l  
如果出错 crontab: error renaming /var/spool/cron/#tmp.xx.XXXX3tTwiC to /var/spool/cron/root
 
防火墙配置 CentOS7 使用 firewall-cmd 打开关闭防火墙与端口。
1 systemctl start firewalld 
1 systemctl status firewalld 
1 systemctl disable  firewalld 
1 systemctl stop firewalld 
1 firewall-cmd --zone=public --list-ports 
1 firewall-cmd --zone=public --add-port=80/tcp --permanent 
–permanent 没有此参数重启后失效
 
 添加完后立即生效
 
1 firewall-cmd --zone=public --query-port=80/tcp 
1 firewall-cmd --zone=public --remove-port=80/tcp --permanent 
配置ngnix 配置文件 ngnix.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 user www www; #worker_processes auto; #worker_rlimit_nofile 10000000; worker_processes 8; worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; # worker_processes 4; # worker_cpu_affinity 0001 0010 0100 1000; error_log /data/wwwlogs/ngnix/error.log crit; pid /var/run/nginx.pid; worker_rlimit_nofile 51200; events {   use epoll;   worker_connections 51200;   multi_accept on; } http {   include mime.types;   default_type application/octet-stream;   server_names_hash_bucket_size 128;   client_header_buffer_size 32k;   large_client_header_buffers 4 32k;   client_max_body_size 1024m;   client_body_buffer_size 10m;   sendfile on;   tcp_nopush on;   keepalive_timeout 120;   server_tokens off;   tcp_nodelay on;   fastcgi_connect_timeout 300;   fastcgi_send_timeout 300;   fastcgi_read_timeout 300;   fastcgi_buffer_size 64k;   fastcgi_buffers 4 64k;   fastcgi_busy_buffers_size 128k;   fastcgi_temp_file_write_size 128k;   fastcgi_intercept_errors on;   #Gzip Compression   gzip on;   gzip_buffers 16 8k;   gzip_comp_level 6;   gzip_http_version 1.1;   gzip_min_length 256;   gzip_proxied any;   gzip_vary on;   gzip_types     text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml     text/javascript application/javascript application/x-javascript     text/x-json application/json application/x-web-app-manifest+json     text/css text/plain text/x-component     font/opentype application/x-font-ttf application/vnd.ms-fontobject     image/x-icon;   gzip_disable "MSIE [1-6]\.(?!.*SV1)";   #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.   open_file_cache max=1000 inactive=20s;   open_file_cache_valid 30s;   open_file_cache_min_uses 2;   open_file_cache_errors on; ######################## default ############################   server {     listen 80;   #  listen 443;     server_name _;     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {       expires 30d;       access_log off;     }     location ~ .*\.(js|css)?$ {       expires 7d;       access_log off;     }     location ~ /\.ht {       deny all;     }   }   include /data/wwwconf/ngnix_conf/*.conf; } 
安装 tomcat 
tar -zvxf apache-tomcat-9.0.35.tar.gz 
配置 server.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE server-xml [ <!ENTITY include-conf-path SYSTEM "file:///data/wwwconf/tomcat_conf/tomcat_businessChannel_8080.xml"> ]> <Server  port ="7000"  shutdown ="SHUTDOWN" >   <Listener  className ="org.apache.catalina.startup.VersionLoggerListener"  />    <Listener  className ="org.apache.catalina.core.AprLifecycleListener"  SSLEngine ="on"  />    <Listener  className ="org.apache.catalina.core.JreMemoryLeakPreventionListener"  />    <Listener  className ="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"  />    <Listener  className ="org.apache.catalina.core.ThreadLocalLeakPreventionListener"  />    <GlobalNamingResources >      <Resource  name ="UserDatabase"  auth ="Container"                 type ="org.apache.catalina.UserDatabase"                description ="User database that can be updated and saved"                factory ="org.apache.catalina.users.MemoryUserDatabaseFactory"                pathname ="conf/tomcat-users.xml"  />   </GlobalNamingResources >    <Service  name ="Catalina" >      <Connector  port ="8080"                   protocol ="HTTP/1.1"                 connectionTimeout ="20000"                 redirectPort ="8443"                 maxThreads ="1000"                 minSpareThreads ="100"                 acceptCount ="1000"                 compression ="on"                 compressionMinSize ="1024"                 noCompressionUserAgents ="gozilla, traviata"                 compressibleMimeType ="text/html,text/xml,text/plain,text/css,text/javascript,application/javascript"                 disableUploadTimeout ="true"                 useSendfile ="false"                 maxHttpHeaderSize ="102400"                 useBodyEncodingForURI ="true"                  enableLookups ="false"                 	             URIEncoding ="UTF-8" />     <Engine  name ="Catalina"  defaultHost ="localhost" >        <Realm  className ="org.apache.catalina.realm.LockOutRealm" >          <Realm  className ="org.apache.catalina.realm.UserDatabaseRealm"                  resourceName ="UserDatabase" />       </Realm >        &include-conf-path;     </Engine >    </Service >  </Server > 
配置 tomcat_businessChannel_8080.xml
1 2 3 4 5 6 7 <Host  name ="localhost"  appBase =""  unpackWARs ="false"  autoDeploy ="true" >   <Context  path ="businessChannel"  docBase ="/data/wwwroot/pcacce/businessChannel"  reloadable ="false"  crossContext ="true" />    <Valve  className ="org.apache.catalina.valves.AccessLogValve"  directory ="logs"       prefix ="localhost_access_log"  suffix =".txt"  pattern ="%h %l %u %t "%r" %s %b"  />   <Valve  className ="org.apache.catalina.valves.RemoteIpValve"  remoteIpHeader ="X-Forwarded-For"       protocolHeader ="X-Forwarded-Proto"  protocolHeaderHttpsValue ="https" /> </Host > 
tomcat日志切片 1 2 3 4 5 6 7 8 9 10 11 12 13 base_path=/Users/logs/pc_accelerator move_path=/home/data/wwwlogs/pc_accelerator log_file_name=accelerator_log.log #  mysite.com虚拟主机的日志存放路径 log_file_path=$base_path/$log_file_name #  创建目录 yesterday=$(date -d yesterday +%Y-%m-%d) old_dir=$move_path/${yesterday} if [ ! -d "$old_dir" ]; then         mkdir $old_dir fi cp $log_file_path $old_dir/$log_file_name echo "" > $log_file_path 
安装 java JDK JDK 的安装步骤,tar -zxvf jdk-8u251-linux-x64.tar.gz -C /usr/local/
修改 JDK 环境变量,
1 2 3 4 5 cp /etc/profile /etc/profile_bak vi /etc/profile export JAVA_HOME=/usr/local/jdk1.8.0_251 export PATH=$JAVA_HOME/bin:$PATH 
source /etc/profile
添加用户组 添加一个 test 租 将test组的名子改成test2 删除组test2 查看组 查看用户test所在组 查看所有组 添加用户(参考帮助文档进行用户配置) 1 2 useradd -g test2 -m  utest                       #添加utest到test2组并创建用户目录(要先创建test2组) useradd -g test2 -M -s /sbin/nologin  qtest      #添加qtest到test2组不创建用户目录,并且不可用于登录 
修改utest用户密码 修改用户(参考帮助文档进行用户配置) 1 2 3 id utest                                 #查看utest用户的UID和GID usermod -d /home/test -G test2 utest     #将utest用户的登录目录改成/home/test,并加入test2组,注意这里是大G。 usermod -s /bin/bash qtest               #修改qtest用户可登录 
删除用户 1 2 userdel qtest         #删除用户qtest userdel -r utest      #删除用户utest,同时删除他的工作目录 
扩展 查看所有用户 1 2 3 cat /etc/passwd             #查看所有用户的列表 w                           #查看当前活跃的用户列表 pkill -kill -t pts/1        #踢掉活跃用户(最后一个参数为需要踢掉用户的tty参数) 
查看登录日志 1 2 more /var/log/secure who /var/log/wtmp 
查看用户操作记录(使用root账号) 1 2 su utest    #切换到要查看的目录 history     #能看到这个用户历史命令,默认最近的1000条 
创建管理员权限的账号 1 2 useradd -o -u 0 -g 0 -M -d /root -s /bin/bash admin    #拥有root 一样的权限 passwd admin 
普通账号使用sudo 1 2 su -                            #切换到超级管理员(带 - 相当直接使用root登录) visudo 
添加要使用sudo权限的帐号
项目中需要添加的用户组和用户 1 2 /usr/sbin/groupadd -f www /usr/sbin/useradd -g www www 
监控流量
配置开机启动 ngnix tomcat 
1 2 3 4 5 6 export JAVA_HOME=**/usr/local/jdk1.8.0_251** /**tomcat_location**/bin/startup.sh sleep 20 /**tomcat1_location**/bin/startup.sh /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
修改权限 1 chmod +x /etc/rc.d/rc.local 
centos下使用iftop查看进程流量 1、安装编译组件
2、下载源码并编译安装http://www.androidstar.cn/pdw/iftop/download/iftop-0.17.tar.gz 
3、使用方法