当前位置: 首页 > Linux

LINUX笔记第一周4.13-4.19

时间:2023-04-07 00:46:42 Linux

基础1.按系列列出Linux发行版,并描述不同发行版之间的联系和区别。2、安装Centos7.6操作系统,用自己的名字创建用户名,并正常登录,主要步骤截图。3、配置环境变量,这样在执行history的时候可以看到命令的执行时间。4.总结Linux的哲学。5、总结Linux常用命令的使用格式,并举例说明。例如echo、screen、date、ifconfig、export1等命令按系列列出Linux发行版,描述不同发行版之间的联系和区别。1)Linuxreleases(distribution)Debian,RedHat,SUSE2)链接基于LINUX开发,基于开放标准POSIX标准改写。LINUXJ是自由软件,自由开源的LINUX思想来源于UNIX,基于GPL协议。LINUX只是一个内核,release版本在这里实现。3)差异基于发布版本。一种是商业公司,如RedHat,另一种以debian为代表。社区组织维护Debian,其中包括Ubuntu。GNU规范,包管理工具apt-get/dpkgRedHat由RedHat开发,包括Fedora、Rhel、Centos2安装Centos7.6操作系统,用自己的名字创建用户名,并正常登录,截图主要脚步。ubuntu下安装忽略groupadd-g1002developeruseradd-u1002-g1002-d/home/zzw1-s/bin/bash-mzzw1passwdzzw1idzzw1uid=1002(zzw1)gid=1002(developer)groups=1002(developer)3配置环境变量,这样在执行history的时候就可以看到命令的执行时间。vim~/.bashrcHISTTIMEFORMAT="%Y-%m-%d%H:%M:%S"。~/.bashrc4总结Linux哲学1)一切皆文件2)提供许多单一用途的小程序3)将程序连接起来共同完成复杂的功能4)配置数据以文本形式存储5.总结Linux常用命令和格式举例说明。例如。echo,screen,date,ifconfig,export等分内部命令和外部命令,使用type检查内部命令xxx是shellbuiltin,比如echo,export外部命令xxx是$PATH/xxx,比如screen,date,ifconfig查看帮助echoecho:echo[-neE][arg...]将参数写入标准输出。在标准输出上显示ARG,由一个空格字符分隔,后跟一个换行符。选项:-n不附加换行符-e启用对以下反斜杠转义的解释-E显式抑制对反斜杠转义的解释外部指令xxx--helpscreen--helpUse:screen[-opts][cmd[args]]或:screen-r[host.tty]选项:-4仅将主机名解析为IPv4地址。-6仅将主机名解析为IPv6地址。-a将所有功能强制纳入每个窗口的termcap。-A-[r|R]使所有窗口适应newdisplaywidth&height.-cfileReadconfigurationfileinsteadof'.screenrc'.-d(-r)分离别处运行ningscreen(并在此处重新连接)。-dmSnameStartasdaemon:Screensessionindetachedmode.-D(-r)分离并注销远程(并在此处重新连接)。-D-RR执行获得屏幕会话所需的任何操作.-exyChangecommandcharacters.-fFlowcontrolon,-fn=off,-fa=auto.-hlines设置回滚历史缓冲区的大小。-i当流量控制打开时,更快地中断输出。外部命令也有man的话可以查看man手册的分类(一般分为九大类,但比较常用的只有前八类)1.普通命令(外部程序或shell命令)2.系统调用(内核提供的函数)3.库调用(libraryFunctionsprovidedin)4特殊文件(通常是/dev下的设备文件)5文件格式,里面会解释配置文件的格式6游戏相关7杂项8管理员命令9内核程序(非标准)可以通过man-fman查看是什么类型,也可以通过whatiscommand[options][arguments]-command:command-options:--wordor-single-word查看通用格式-arguments:参数,有时options也有参数Advanced1.编译安装LNMP,配置自定义404页面,配置json格式的访问日志。编译php并下载源文件./configure--prefix=/opt/php74--enable-fpm--with-libzip--with-openssl--with-freetype--with-jpeg--enable-bcmath--enable-pcntlmakemakeinstallconfigurevim/lib/systemd/system/php74-fpm.service[Unit]Description=ThePHP7.4FastCGIProcessManagerAfter=network.target[Service]Type=simplePIDFile=/opt/php74/var/run/php-fpm.pidExecStart=/opt/php74/sbin/php-fpm--nodaemonize--fpm-config/opt/php74/etc/php-fpm.confExecReload=/bin/kill-USR2$MAINPID[Install]WantedBy=multi-user.targetsystemctlstartphp74-fpmcompileopenresty./configure--prefix=/opt/openresty--with-luajit--with-http_iconv_modulegmakegmake安装nginx配置文件自定义404并询问登录json格式#usernobody;worker_processes1;#error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;#pidlogs/nginx.pid;events{worker_connections1024;}http{includemime.types;default_type应用程序/八位字节流;log_formatmain'$remote_addr-$remote_user[$time_local]"$request"''$status$body_bytes_sent"$http_referer"''"$http_user_agent""$http_x_forwarded_for"';log_formatlog_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.loglog_json;发送文件;#tcp_nopush上;#keepalive_timeout0;keepalive_timeout65;#gzip上;服务器{听80;服务器名称blog.chromev.com本地主机;根/var/www/php;#charsetkoi8-r;#access_log日志/host.access.logmain;位置ation/{indexindex.htmlindex.htmindex.php;}error_page404404.html;#将服务器错误页面重定向到静态页面/50x.html#error_page500502503504/50x.html;location=/50x.html{根html;}location=/404.html{root/var/www/html2;}#将PHP脚本代理到侦听127.0.0.1:80的Apache##location~\.php${#proxy_passhttp://127.0.0.1;#}#将PHP脚本传递给侦听127.0.0.1:9000的FastCGI服务器#location~\.php${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;包括fastcgi_params;}#拒绝访问.htaccess文件,如果Apache的文档根#与nginx的一致##location~/\.ht{#全部拒绝;#}}#另一个混合使用基于IP、名称和端口的配置的虚拟主机##server{#listen8000;#听某个名字:8080;#server_namesomename别名another.alias;#位置/{#根html;#索引index.htmlindex.htm;#}#}#HTTPS服务器##server{#listen443ssl;#server_name本地主机;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;#ssl_session_cache共享:SSL:1m;#ssl_session_timeout5m;#ssl_ciphersHIGH:!aNULL:!MD5;#ssl_prefer_server_ciphers开启;#位置/{#根html;#索引index.htmlindex.htm;#}#}}json格式tail-f/var/run/access.log{"@timestamp":"19/Apr/2020:21:48:52+0800","remote_addr":"108.162.215.50",“推荐人”:“http://blog.chromev。com/asd","request":"GET/404.htmlHTTP/1.1","status":304,"bytes":0,"agent":"Mozilla/5.0(Macintosh;IntelMacOSX10_14_6)AppleWebKit/537.36(KHTML,likeGecko)Chrome/80.0.3987.163Safari/537.36","x_forwarded":"36.57.1??45.226","up_addr":"-","up_host":"-","up_resp_time":"-","re??quest_time":"0.000"}2、配置虚拟主机实现基于OpenSSL自建CA对www.x.com(x.com定义的域名)进行https访问,并在CA上颁发SSL证书server.Operation1生成根证书1)配置文件/etc/pki/tls/openssl.cnf2)在CA目录下创建两个初始文件cd/etc/pki/CAtouchindex.txtserialecho01>serial3)生成rootkeycd/etc/pki/CA/opensslgenrsa-outprivate/cakey.pem2048为了安全起见,修改cakey.pem私钥文件的权限为600或400,或者使用子shell生成(umask077;opensslgenrsa-outprivate/cakey.pem2048),下面不再重复4)生成根证书(需要添加到本机)使用req命令生成自签名证书cd/etc/pki/CA/opensslreq-new-x509-keyprivate/cakey.pem-outcacert.pemWEBserver2GeneratenginxwebServergeneratesslkey1)生成私钥cd/opt/openresty/nginx/ssl/opensslgenrsa-outnginx.key20482)为nginx生成证书签名请求cd/opt/openresty/nginx/ssl/opensslreq-new-keynginx.key-outnginx.csr...CountryName(2lettercode)[AU]:CNState或ProvinceName(fullname)[Some-State]:GDLocalityName(eg,city)[]:SZOrganizationName(eg,company)[InternetWidgitsPtyLtd]:COMPANYOrganizationalUnitName(eg,section)[]:IT_SECTIONCommonName(e.g.serverFQDNorYOURname)[]:blog.chroemv.com电子邮件地址[]:Pleaseenterthefollowing'extra'attributestobesentwithyourcertificaterequestAchallengepassword[]:Anoptionalcompanyname[]:...你还会被提示输入一些内容,其他的是可选的,除了Common名称必须是要授予证书的服务器的域名或主机名。挑战密码未填写。3)用CA公钥签名opensslca-innginx.csr-outnginx.crt3使用证书1)Nginx使用ssl证书#HTTPSserver#server{listen443ssl;服务器名称blog.chromev.com;根/var/www/php/;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;ssl_certificate/opt/openresty/nginx/ssl/nginx.crt;ssl_certificate_key/opt/openresty/nginx/ssl/nginx.key;ssl_session_cache共享:SSL:1m;ssl_session_timeout5m;ssl_ciphersHIGH:!aNULL:!MD5;ssl_prefer_server_ciphers开启;location/{indexindex.htmlindex.htm;}location~\.php${fastcgi_pass127.0.0.1:9000;文档根目录$fastcgi_script_name;包括fastcgi_params;}}2添加CA根证书到操作系统以获得信任macaddsudosecurityadd-trusted-cert-d-rtrustRoot-k/Library/Keychains/System.keychain/cacert.pem除了使用命令行管理证书外,还可以在keychainaccessLinux(CentOs6)中进行管理#安装ca-certificates包:yuminstallca-certificates#启用动态CA配置功能:update-ca-trustforce-enable#将证书文件放到/etc/pki/ca-trust/source/anchors/目录下mv/cacert.pem/etc/pki/ca-trust/source/anchors/#执行:update-ca-trustextract3验证成功curl-khttps://blog.chromev.com

HelloWorld