Latest Entries »

用OPENSSL生成自签名证书

1、生成服务器私钥(可以选择是否使用密码保护私钥,设置私钥密码的话,每次启动服务器搜需要输入该密码从而保证了私钥的安全性)
openssl genrsa -out client.key 4096

2、生成证书签名请求(CSR)。其中一个提示是 Common Name (e.g. YOUR name),这个非常重要,这一项应填入 FQDN(Fully Qualified Domain Name)完全合格域名/全称域名。例如*.test.com
openssl req -new -key client.key -out client.csr

3、使用上一步的证书签名请求签发证书
openssl x509 -req -days 365 -in client.csr -signkey client.key -out client.crt

4、以上三个步骤也可以通一个简单的方法,实现一步创建10年,无密码私钥(也能用-noenc替换-nodes)和证书:
openssl req -new -x509 -newkey rsa:4096 -keyout client.key -out client.crt -days 3650 -nodes

PS:
-new -x509:生成X509格式新证书
-newkey rsa:4096:使用长度为4096位的RSA密钥
-days 3650:有效期10年
-nodes(-noenc):不加密私钥

centos搭建http+https+svn服务

一、安装https+svn
yum install mod_dav_svn subversion mod_ssl

二、设置apache
# 生成有效期100年的证书:
cd /etc/httpd/conf/
openssl req -new -x509 -keyout server.key -out server.crt -days 36500 -nodes

# 修改https证书指向
vi /etc/httpd/conf.d/ssl.conf
ServerName SVN
SSLCertificateFile /etc/httpd/conf/server.crt
SSLCertificateKeyFile /etc/httpd/conf/server.key

# 加载mod_dav_svn,删除这两行的注释
vi /etc/httpd/conf.modules.d/10-subversion.conf
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

# 加载mod_ssl(启用SSL,取消/etc/httpd/conf/httpd.conf中SSL配置行的注释,不同LINUX版本,配置文件路径或文件名各不相同,请自行修改)
vi /etc/httpd/conf.modules.d/00-ssl.conf
#Include /etc/httpd/conf/extra/httpd-ssl.conf
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

vi /etc/httpd/conf.d/subversion.conf
# 在 Location 部份加入AuthzSVNAccessFile /home/svn/repositories/conf/authz来支持基本验证,并将 Apache 指向实际放置版本库的地方。

DAV svn
SVNParentPath /home/svn/repositories
AuthzSVNAccessFile /home/svn/repositories/conf/authz
AuthType Basic
AuthName “Subversion repos”
# Require SSL connection for password protection.如果未启用https服务,请注释掉SSLRequireSSL。加入了这行,也会导致http服务无法访问svn。
# SSLRequireSSL
AuthUserFile /home/svn/repositories/conf/passwd
# Satisfy Any
Require valid-user

三、创建版本库及目录
mkdir -p /home/svn/repositories/conf
svnadmin create /home/svn/repositories/p1
# 设置权限
chown -R apache.apache /home/svn/repositories/p1
service httpd restart

四、配置修改,使用统一的账户和权限去管控多个项目,可以将多个项目的authz和passwd文件统一放在一处,在多个项目的svnserve.conf文件中配置这两个文件的绝对路径,并在authz中对不同的项目设置用户访问权限。
cd /home/svn/repositories/p1/conf
cp authz passwd /home/svn/repositories/conf

五、设置p1版本库的访问策略,在[general]中取消以下行的注释或者添加:
vi /home/svn/repositories/p1/conf/svnserve.conf
# 禁止匿名访问。可以是read、write,none,默认为read
anon-access = none
#经过认证的用户有写权限
auth-access = write
#指定用户存放用户名与密码的文件,该文件位于conf目录下名为passwd
password-db = /home/svn/repositories/conf/passwd
#指定权限配置文件名,filename 是相对仓库中 conf 目录的位置,也可以设置为绝对路径,默认为authz
authz-db = /home/svn/repositories/conf/authz
#设置版本库域,如果两个版本库的认证域相同,他们将使用相同的密码数据。(指定仓库的认证域. 该选项主要被客户端使用, 用来关联缓存的认证证书和特定的某个或某些仓库, 正因为如此, 除非多个仓库使用了相同的密码数据库, 否则的话, 最好把每个仓库的认证域都设置 成独一无二的值. 仓库认证域的默认值是它的 UUID)
realm = p1

六、创建SVN应用的用户及密码
6.1、创建SHA-512加密的密码文件
# 首次创建用户要用 -c5 这个选项。它会创建文件并用SHA-512将口令加密。如果非首次添加用户,请只使用 -5 选项,而不包含初次创建时的 -c。
[svn@testhost ~] htpasswd -c5 /home/svn/repositories/conf/passwd yourusername
New password:
Re-type new password:
Adding password for user yourusername
[svn@testhost ~] htpasswd -5 /home/svn/repositories/conf/passwd anotherusername
New password:
Re-type new password:
Adding password for user anotherusername
6.2、修改用户密码及删除用户(就算用htpasswd -p选项创建了不加密的passwd文件,APACHE也无法识别直接编辑文件来创建的用户和密码)。
# 修改AAA用户密码(与创建新用户命令相同)
htpasswd -5 /home/svn/repositories/conf/passwd AAA
# 删除已有的BBB用户
htpasswd -D /home/svn/repositories/conf/passwd BBB

七、SVN用户权限管理,
vi /home/svn/repositories/conf/authz
[版本库名称:版本库路径]
用户 = 访问权
[groups]
staffs = joe,george
p1users = harry,sally

#未设置权限人员不能阅读版本库
[/]
@staffs = rw
* =

[p1:/]
john = r
@p1users = rw
* =

八、SVN的备份与还原
# 备份版本库
svnadmin dump /path/to/repo > /tmp/repo.dump

# 还原版本库时,先创建库
svnadmin create /path/to/repo
# 导入备份的库文件
svnadmin load /path/to/repo < /tmp/repo.dump
# 设置权限
chown -R svn:svnusers /path/to/repo
chmod -R g+w /path/to/repo/db/

九、访问项目p1 URL
http://IP/p1

https://IP/p1

svn://IP/p1

访问项目p2 URL
svn://IP:3690/p2 (iP地址为你linux的ip,p2为前文创建的版本库名称。3690为svn默认端口,默认端口可以省略不写)

一、下载配套版本的NGINX
wget http://nginx.org/download/nginx-1.7.8.tar.gz

二、下载依赖的MOD
git clone -b dev https://github.com/cuber/ngx_http_google_filter_module.git

git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

三、安装依赖的编译环境
yum install openssl-devel pcre-devel gcc

四、编译安装NGINX
1、解压缩
tar -xvzf nginx-1.7.8.tar.gz
2、进入目录
cd nginx-1.7.8
3、生成配置
./configure \
–prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –user=nginx –group=nginx –with-file-aio –with-http_addition_module –with-http_auth_request_module –with-http_dav_module –with-http_flv_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_mp4_module –with-http_random_index_module –with-http_realip_module –with-http_secure_link_module –with-http_ssl_module –with-http_stub_status_module –with-http_sub_module –with-mail –with-mail_ssl_module –with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong –param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC’ –with-ld-opt=’-Wl,-z,relro -Wl,-z,now -pie’ \
–add-module=../ngx_http_google_filter_module \
–add-module=../ngx_http_substitutions_filter_module
4、编译
make
5、安装
make install

五、修改NINGX配置

1、http配置方式
server {
server_name <你的域名> <服务器IP>;
listen 80;

resolver 8.8.8.8;
location / {
google on;
}
}

2、https配置方式
server {
server_name <你的域名> <服务器IP>;
listen 443;

ssl on;
ssl_certificate <你的证书>;
ssl_certificate_key <你的私钥>;

resolver 8.8.8.8;
location / {
google on;
}
}

ps:
https://github.com/cuber/ngx_http_google_filter_module/blob/dev/README.zh-CN.md
可以用域名,也能用IP访问。

先普及个少见的基础常识,本次故障的原因就是要理解这句话:

一些 UEFI 固件在显示 UEFI NVRAM 启动条目之前,需要在一个已知的位置上有一个可启动文件。如果是这种情况, grub-install 会说明 efibootmgr 添加了一个启动 GRUB 的条目,但这个条目不会在 VisualBIOS 启动顺序选择器中显示。解决方法是把 GRUB 安装到缺省/后备启动路径当中:
grub-install –target=x86_64-efi –efi-directory=esp –removable
或者你可以把已经安装好的 GRUB EFI 执行文件移动到缺省/后备路径中:(这都是后话,除非硬盘再接回原来的电脑上)
mv esp/EFI/grub esp/EFI/boot
mv esp/EFI/boot/grubx64.efi esp/EFI/boot/bootx64.efi

下面根据上文的理论开始实操:

一、用ARCH LINUX的U盘引导,进入UEFI SHELL菜单
#查看UEFI Shell 里找到的 EFI 分区
alias

#列出所有的EFI引导条目(看详情用-v参数)
bcfg boot dump

#查看fs1分区里的文件(因为我这是U盘引导启动,FS0是U盘)
ls fs1:
ls fs1:\efi

#进入对应的efi分区
fs1:

#创建文件夹及拷贝GRUB启动菜单文件
mkdir esp/EFI/boot
cp esp/EFI/grub/grubx64.efi esp/EFI/boot/bootx64.efi

到此为止可以reboot机器,就能够看到GRUB的启动菜单啦。

二、重新安装grub
#安装grub到/boot/grub/目录,并在UEFI的NVRAM里面创建一个名字叫GRUB的启动项。(如果你的启动项已满,这个命令会执行失败。你需要使用 uefi shell 来删除不必要的条目。)在配置完成后,记得grub-mkconfig -o /boot/grub/grub.cfg生成主配置文件。
#本次故障的起因就是老电脑上这样执行的命令,新电脑UEFI的nvram里面没GRUB的启动项。本次就注释掉,不再次执行此命令啦
#grub-install –target=x86_64-efi –efi-directory=esp –bootloader-id=GRUB

#–removable 选项,GRUB将被安装到 esp/EFI/boot/bootx64.efi。这样启动固件就可以在没有 UEFI 启动条目的的情况下找到。(即使 EFI 变量被重设或者你把这个驱动器接到其他电脑上,你仍可从这个驱动器上启动。)
#经过uefi shell的修改,引导系统后立刻重装grub,加入–removable参数
grub-install –target=x86_64-efi –efi-directory=esp –removable

#生成主配置文件
grub-mkconfig -o /boot/grub/grub.cfg

至此,本次黑屏无法显示启动菜单的故障解决完毕。

=======
PS:uefi shell的一些常用命令
#把第3个启动选项移动到第0 (也就是说第0个是 UEFI 启动菜单的默认启动选项):
bcfg boot mv 3 0

#在编号为X的位置插入一个EFI引导项,X是一个数字编号(手动添加的UEFI启动项在硬盘发生变动(换硬盘、分区变化)时候会这行丢失,需要重新添加)
bcfg boot add X fs0:\EFI\grub\grubx64.efi “grub”

#添加Windows的引导项命令
bcfg boot add 0 fs0:\EFI\Microsoft\Boot\bootmgfw.efi “Windows”

#删除第4个启动选项:
bcfg boot rm 3

#EDIT 命令提供了类似于 nano 界面的基本编辑器,但是功能略少一点。它以 UTF-8 编码并且行尾结束符兼容 LF 和 CRLF
edit FS0:\EFI\refind\refind.conf

#bcfg 帮助文档:
help bcfg -v -b

#退出UEFI Shell
exit

SVN服务搭建

一、安装svn服务器相关服务和依赖
yum -y install subversion

二、建立操作系统用户svn并设置密码,切换为svn用户
useradd svn; passwd svn
su – svn

三、创建版本库目录(此仅为目录,为后面创建版本库提供存放位置)
mkdir -p /home/svn/repositories/conf

四、创建多个svn版本库
cd /home/svn/repositories/
svnadmin create p1 (p1为你预期的版本库名称,可自定义)
svnadmin create p2 (创建第二个项目的版本库名称)

五、配置修改,使用统一的账户和权限去管控多个项目,可以将多个项目的authz和passwd文件统一放在一处,在多个项目的svnserve.conf文件中配置这两个文件的绝对路径,并在authz中对不同的项目设置用户访问权限。
cd /home/svn/repositories/p1/conf
cp authz passwd /home/svn/repositories/conf

六、conf目录下,一共存放三份重要的配置文件,
authz:负责账号权限的管理,控制账号是否读写权限
passwd:负责账号和密码的用户名单管理
svnserve.conf:svn服务器配置文件
db目录里面的包含我们上传到SVN服务器上面的文档、代码等数据的不同版本(有时需给db文件夹开放权限,否则客户端可能无法连接SVN服务器)
6.1、用户权限配置文件
vi authz
[groups]
#定义组,组成员有admin与root
admins = admin,root
p1users = a,b
p2users = c,d
#对版本库根路径设置权限,可以设置为你需要控制的路径,rw表示赋予此账号可读写的权限,请注意[]中的斜杠,需添加版本库名称在括号内
[/]
#admins组中的用户具有读写权限
@admins = rw
#其他所有人无权限。权限可以设置为只读(‘r’),读写(‘rw’),无权限(”)
* =

[p1:/] //p1的访问控制,c、d无法访问
@p1users = rw

[p2:/] //p2的访问控制,a、b无法访问
@p2users = rw

6.2、账号密码配置文件
vi passwd
[users]
admin = 123456
root = 123456
a = 123456
b = 123456
c = 123456
d = 123456

6.3项目1的配置文件
vi /home/svn/repositories/p1/conf/svnserve.conf
[general]
# force-username-case = none
# 禁止匿名访问。可以是read、write,none,默认为read
anon-access = none
#经过认证的用户有写权限
auth-access = write
#指定用户存放用户名与密码的文件,该文件位于conf目录下名为passwd
password-db = /home/svn/repositories/conf/passwd
#指定权限配置文件名,filename 是相对仓库中 conf 目录的位置,也可以设置为绝对路径,默认为authz
authz-db = /home/svn/repositories/conf/authz
#设置版本库域,如果两个版本库的认证域相同,他们将使用相同的密码数据。(指定仓库的认证域. 该选项主要被客户端使用, 用来关联缓存的认证证书和特定的某个或某些仓库, 正因为如此, 除非多个仓库使用了相同的密码数据库, 否则的话, 最好把每个仓库的认证域都设置 成独一无二的值. 仓库认证域的默认值是它的 UUID)
realm = p1

6.4项目2的配置文件
vi /home/svn/repositories/p2/conf/svnserve.conf
[general]
# force-username-case = none
# 禁止匿名访问。可以是read、write,none,默认为read
anon-access = none
#经过认证的用户有写权限
auth-access = write
#指定用户存放用户名与密码的文件,该文件位于conf目录下名为passwd
password-db = /home/svn/repositories/conf/passwd
#指定权限配置文件名,filename 是相对仓库中 conf 目录的位置,也可以设置为绝对路径,默认为authz
authz-db = /home/svn/repositories/conf/authz
#设置版本库域,如果两个版本库的认证域相同,他们将使用相同的密码数据。(指定仓库的认证域. 该选项主要被客户端使用, 用来关联缓存的认证证书和特定的某个或某些仓库, 正因为如此, 除非多个仓库使用了相同的密码数据库, 否则的话, 最好把每个仓库的认证域都设置 成独一无二的值. 仓库认证域的默认值是它的 UUID)
realm = p2

七、启动svn服务(-d:后台模式-r:服务的根目录)
svnserve -d -r /home/svn/repositories/

八、加入随操作系统启动
systemctl enable svnserve.service
#修改版本库路径
vi /etc/sysconfig/svnserve
OPTIONS=”-r /home/svn/repositories”

九、访问项目p1 URL
svn://IP/p1

访问项目p2 URL
svn://IP:3690/p2 (iP地址为你linux的ip,p2为前文创建的版本库名称。3690为svn默认端口,默认端口可以省略不写)

linux通过socks全局代理

方法一:安装proxychains-ng
配置
vi /etc/proxychains.conf
socks5 127.0.0.1 1080

通过proxychains-ng启动程序
proxychains xxx

方法二:安装tsocks
配置
vi /etc/tsocks.conf
server = 127.0.0.1
server_port = 1080
server_type = 5
default_user = “”
default_pass = “”

方法三:设置环境变量
export all_proxy=”socks5://127.0.0.1:1080″

PS:若报如下错误请安装python-pysocks软件
missing dependencies for SOCKS support
sudo pacman -S python-pysocks

一、安装打印服务及工具
pacman -S cups system-config-printer

二、启动打印服务
systemctl enable –now cups

三、安装DEB包转换工具
yay -S debtap

四、同步下各仓库信息
debtap -u

五、转换DEB包为ARCH可用的格式
debtap com.lanxum-ga30_1.0.0-21235_amd64.deb

六、安装GA3032dn驱动
pacman -U com.lanxum-ga30-1.0.0-1-x86_64.pkg.tar.zst

七、用system-config-printer添加网络打印机,或者http://localhost:631在administration页面添加

PS:立思辰A4激光黑白打印机GA3032dn驱动下载
https://www.cgprintech.com/product/348.html

@echo off

set /p KZM=请输入文件扩展名(以回车结束):
set /p XG=请输入要修改的文字(以回车结束):
set /p JG=请输入要改成的文字(若是删除则直接回车,以回车结束):

for /f “delims=” %%i in (‘dir /b /a-d “*.%KZM%”‘ ) do (
set tmp=%%i
setlocal EnableDelayedExpansion
set “tmp=!tmp:%XG%=%JG%!”
ren “%%i” “!tmp!”
endlocal
)

pause>nul

一、现象:
arch安装linux-lts和nvidia-lts后,若再次更新linux-lts则操作系统无法引导,启动引导在硬盘自检后卡住,只能进救援模式。卸载nvidia-lts驱动后,才能正常进入图形界面。

二、报错:
tail -f /var/log/Xorg.0.log
(EE) nvidia: failed to initialize the nvidia kernel module.
(EE) no devices detected
(EE) no screens foune(EE)

三、解决办法1:grub内核启动参数在KERNEL那一行的末尾加ibt=off。关闭CPU的安全特性Indirect Branch Tracking。

查看当前linux内核的启动参数:
cat /proc/cmdline

vi /etc/default/grub
# 将内核选项添加至 GRUB_CMDLINE_LINUX_DEFAULT 行
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash ibt=off”

然后重新生成 grub.cfg 文件:
grub-mkconfig -o /boot/grub/grub.cfg

四、解决办法2:安装nvidia-dkms驱动配合linux-lts更新,解决NV显卡驱动的问题。

@echo off
chcp 936 >nul 2>nul
sc config winmgmt start= auto >nul 2>nul
net start winmgmt >nul 2>nul
color 0a
echo 计算机名:
hostname
echo.
set URL=www.163.com
echo 电脑品牌是:
wmic csproduct get Vendor |findstr -v Vendor
echo 电脑型号是:
wmic csproduct get Name,version |findstr -v Name |findstr -v Version
echo 电脑序列号是:
rem wmic csproduct get IdentifyingNumber
wmic bios get serialnumber |findstr -v SerialNumber
echo CPU型号是:
wmic cpu get name |findstr -v Name
systeminfo | findstr -i 物理内存总量
echo.
echo 硬盘型号是:
wmic diskdrive get model |findstr -v Model
echo.
echo.
echo.
echo —===以下为网卡信息===—
rem for /f “tokens=4” %%a in (‘route print^|findstr 0.0.0.0.*0.0.0.0’) do (set IP=%%a)
for /f “tokens=16 delims= ” %%a in (‘ipconfig ^| find /i “IPv4″‘) do (set IP=%%a)
for /f “tokens=3” %%b in (‘route print^|findstr 0.0.0.0.*0.0.0.0’) do (set GW=%%b)
rem for /f “tokens=15 delims= ” %%b in (‘ipconfig /all ^| find /i “网关”‘) do (set GW=%%b)
for /f “tokens=15 delims= ” %%c in (‘ipconfig /all ^| find /i “掩码”‘) do (set SUB=%%c)
rem for /f “tokens=2 delims= ” %%c in (‘route print^|findstr /v 127.0.0.1^|findstr %IP%^|findstr /v 0.0.0.0^|findstr /v 240.0.0.0^|findstr /v 255.255.255.255’) do (set SUB=%%c)
for /f “tokens=15 delims= ” %%d in (‘ipconfig /all ^| find /i “dns”‘) do (set NS=%%d)
for /f “tokens=1 delims= ” %%e in (‘getmac /nh’) do (set MAC=%%e)
for /f “tokens=3* delims= ” %%f in (‘netsh interface show interface ^| findstr 已连接’) do (set card=%%g)
echo 接网线的网卡名是:
echo %card%
echo.
echo 局域网IP是:
echo %IP%
echo.
echo 网卡MAC是:
echo %MAC%
echo.
echo 子网掩码是:
echo %SUB%
echo.
echo 局域网网关是:
echo %GW%
echo.
rem echo 首选DNS是:
rem echo %NS%
echo 域名解析设置:
netsh interface ip show dnsservers|findstr “[0-9]*\.[0-9]*\.”
echo.
echo.
echo.
echo —===以下为网络连通性测试结果===—
echo.
ping %GW% -n 2 > nul
if %errorlevel% leq 0 (
echo 网关%GW%链接正常。
) else (
echo 网关%GW%访问异常,请检查IP和子网掩码或网关设置。
)
echo.
ping %URL% -n 2 > nul
if %errorlevel% leq 0 (
echo 网址%URL%访问正常。
) else (
echo 网址%URL%访问异常,请检查DNS设置。
)
echo.
echo.
echo.
echo 已检测完毕,按任意键关闭窗口。
pause>nul