基础
1、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。
2、安装Centos7.6操作系统,创建一个自己名字的用户名,并可以正常登录,将主要步骤截图。
3、配置环境变量,实现执行history的时候可以看到执行命令的时间。
4、总结Linux哲学思想。
5、总结Linux常用命令使用格式,并用实例说明。例如echo、screen、date、ifconfig、export等命令
1 按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。
1) Linux的发行版(distribution)
Debian、RedHat、SUSE
2) 联系
基于LINUX发展而来,基于公开的标准的POSIX标准重新编写而成,LINUXJ是自由软件,免费、公开源代码的
LINUX的思想源于UNIX
基于GPL协议
LINUX只是个内核,发行版本都是在此实现
3) 区别
按发行版本 一类是商业公司公司,如RedHat, 一类是以debian为代表,社区组织维护
Debian是包含Ubuntu的,遵循GNU规范,包管理工具 apt-get / dpkg
RedHat 是红帽公司研发, 包括Fedora、 Rhel、 Centos
2 安装Centos7.6操作系统,创建一个自己名字的用户名,并可以正常登录,将主要步骤截图。
安装忽略
ubuntu下
groupadd -g 1002 developer
useradd -u 1002 -g 1002 -d /home/zzw1 -s /bin/bash -m zzw1
passwd zzw1
id zzw1
uid=1002(zzw1) gid=1002(developer) groups=1002(developer)
3 配置环境变量,实现执行history的时候可以看到执行命令的时间。
vim ~/.bashrc
HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
. ~/.bashrc
4 总结Linux哲学思想
1) 一切皆文件
2)提供很多小型的单一用途的程序
3) 连接程序,共同完成复杂的功能
4)配置数据存储在文本中
5、总结Linux常用命令使用格式,并用实例说明。例如echo、screen、date、ifconfig、export等命令
分为内部命令和外部命令,使用type查看
内置命令 xxx is a shell builtin,如echo, export
外部命令 xxx is $PATH/xxx, 如 screen、date、ifconfig
内置命令查看
help echo
echo: echo [-neE] [arg ...]
Write arguments to the standard output.
Display the ARGs, separated by a single space character and followed by a
newline, on the standard output.
Options:
-n do not append a newline
-e enable interpretation of the following backslash escapes
-E explicitly suppress interpretation of backslash escapes
外部命令 xxx --help
screen --help
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty]
Options:
-4 Resolve hostnames only to IPv4 addresses.
-6 Resolve hostnames only to IPv6 addresses.
-a Force all capabilities into each window's termcap.
-A -[r|R] Adapt all windows to the new display width & height.
-c file Read configuration file instead of '.screenrc'.
-d (-r) Detach the elsewhere running screen (and reattach here).
-dmS name Start as daemon: Screen session in detached mode.
-D (-r) Detach and logout remote (and reattach here).
-D -RR Do whatever is needed to get a screen session.
-e xy Change command characters.
-f Flow control on, -fn = off, -fa = auto.
-h lines Set the size of the scrollback history buffer.
-i Interrupt output sooner when flow control is on.
外部命令还有man可以查看帮助手册
man手册的分类(一般分为九类,但是只有前八类比较常用)
1 普通的命令(外部程序或者shell命令)
2 系统调用(内核提供的函数)
3 库调用(库中提供的函数)
4 特殊文件(经常是/dev下的设备文件)
5 文件格式,在其中会说明配置文件的格式
6 游戏相关
7 杂项
8 管理员命令
9 内核程序(非标准)
可以通过man -f man查看哪类,也可以通过 whatis查看
一般格式
command [options] [arguments]
- command:命令
- options:--单词 或 -单字
- arguments:参数,有时候选项也带参数。
进阶
1、编译安装LNMP,配置自定义404页面,配置访问日志为json格式。
编译php
下载源文件
./configure --prefix=/opt/php74 --enable-fpm --with-libzip --with-openssl --with-freetype --with-jpeg --enable-bcmath --enable-pcntl
make
make install
配置
vim /lib/systemd/system/php74-fpm.service
[Unit]
Description=The PHP 7.4 FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/opt/php74/var/run/php-fpm.pid
ExecStart=/opt/php74/sbin/php-fpm --nodaemonize --fpm-config /opt/php74/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
systemctl start php74-fpm
编译openresty
./configure --prefix=/opt/openresty --with-luajit --with-http_iconv_module
gmake
gmake install
nginx 配置文件
自定义404 和 问日志为json格式
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format log_json '{ "@timestamp": "$time_local", '
'"remote_addr": "$remote_addr", '
'"referer": "$http_referer", '
'"request": "$request", '
'"status": $status, '
'"bytes": $body_bytes_sent, '
'"agent": "$http_user_agent", '
'"x_forwarded": "$http_x_forwarded_for", '
'"up_addr": "$upstream_addr",'
'"up_host": "$upstream_http_host",'
'"up_resp_time": "$upstream_response_time",'
'"request_time": "$request_time"'
' }';
access_log /var/run/access.log log_json;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name blog.chromev.com localhost;
root /var/www/php;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.html index.htm index.php;
}
error_page 404 404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location = /404.html {
root /var/www/html2;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
json格式
tail -f /var/run/access.log
{ "@timestamp": "19/Apr/2020:21:48:52 +0800", "remote_addr": "108.162.215.50", "referer": "http://blog.chromev.com/asd", "request": "GET /404.html HTTP/1.1", "status": 304, "bytes": 0, "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36", "x_forwarded": "36.57.145.226", "up_addr": "-","up_host": "-","up_resp_time": "-","request_time": "0.000" }
2、配置虚拟主机,实现https访问www.x.com(x.com为自己定义的域名)
基于OpenSSL自建CA和颁发SSL证书
CA服务器上操作
1 生成根证书
1) 配置文件
/etc/pki/tls/openssl.cnf
2)在CA目录下创建两个初始文件
cd /etc/pki/CA
touch index.txt serial
echo 01 > serial
3) 生成根密钥
cd /etc/pki/CA/
openssl genrsa -out private/cakey.pem 2048
为了安全起见,修改cakey.pem私钥文件权限为600或400,也可以使用子shell生成( umask 077; openssl genrsa -out private/cakey.pem 2048 )
,下面不再重复。
4) 生成根证书 (需要加入本机)
使用req命令生成自签证书
cd /etc/pki/CA/
openssl req -new -x509 -key private/cakey.pem -out cacert.pem
WEB服务器上
2 生成nginx web服务器生成ssl密钥
1) 生成私钥
cd /opt/openresty/nginx/ssl/
openssl genrsa -out nginx.key 2048
2) 为nginx生成证书签署请求
cd /opt/openresty/nginx/ssl/
openssl req -new -key nginx.key -out nginx.csr
...
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GD
Locality Name (eg, city) []:SZ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:COMPANY
Organizational Unit Name (eg, section) []:IT_SECTION
Common Name (e.g. server FQDN or YOUR name) []: blog.chroemv.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
...
同样会提示输入一些内容,其它随便,除了Commone Name
一定要是你要授予证书的服务器域名或主机名,challenge password不填。
3) 用 CA公钥加签
openssl ca -in nginx.csr -out nginx.crt
3 使用证书
1) Nginx 使用 ssl 证书
# HTTPS server
#
server {
listen 443 ssl;
server_name blog.chromev.com;
root /var/www/php/;
#ssl_certificate cert.pem;
#ssl_certificate_key cert.key;
ssl_certificate /opt/openresty/nginx/ssl/nginx.crt;
ssl_certificate_key /opt/openresty/nginx/ssl/nginx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
index index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2 添加 CA 根证书到操作系统获得信任
mac 添加
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /cacert.pem
除了用命令行管理证书,还可以在 钥匙串访问
中进行管理
Linux (CentOs 6)
#安装 ca-certificates package:
yum install ca-certificates
#启用dynamic CA configuration feature:
update-ca-trust force-enable
#将证书文件放到 /etc/pki/ca-trust/source/anchors/ 目录下
mv /cacert.pem /etc/pki/ca-trust/source/anchors/
#执行:
update-ca-trust extract
3 验证是否成功
curl -k https://blog.chromev.com
Hello World