BASMASER :
顶部导航栏:LIN -> DriverSelection -> PEAK USB -> 导入 ldf 文件
CAN 两根线之间连接一个电阻形成回路(短路电阻): 120 欧姆电阻
色环电阻对照表
棕 红 橙 黄 绿 蓝 紫 灰 白 黑 金 银
1 2 3 4 5 6 7 8 9 0 误差5% 误差 10%
倒数第二环: 最后一环金色 或 银色 的前1位色环位;倍率单位:欧姆
棕 红 橙 黄 绿 蓝 紫 灰 白 黑
10^1=10 10^2=100 10^3=1000 10^4 10^5 10^6 10^7 10^8 10^9 10^0=1
【四色环电阻】
1. 距离较大的一环为误差
2. 第1,2 环 两位有效阻值 第三环为倍率
案例:棕红棕 金
12x 10^1= 120欧姆
【5色环】
倒数第二环为倍率 增加倍率代表:金色 为 0.1倍,倒数1环(第5环)为误差
【3色环】
色环:第1位 十位数 ;第二位 个位数; 第三位 误差
1: VCC + 2: VCC
3: n/u 4: GND +
5: n/u 6: GND +
7: SWDIO + 8: GND
9: SWCLK + 10: GND
11: N/U 12: GND
13: SWO 14: GND
15: RESET + 16: GND
17: N/C 18: GND
19: N/C 20: GND
# + 号是需要接线的
#--- FS32K142H 电路图 ---#
烧录接口电路:
1: 5V 2: SWDIO
3: GND 4: SWDCLK
5: GND 6: RESET
FS32K142H 对应 J-link 接线
1 - 1
2 - 7
3 - 4
4 - 9
5 - 6
6 - 16
配置方法: 红色线正对面左第一个进行捆绑
#---------- TEST
板子竖着看,标有 J2 的一边方向向左 (串口针为分界线 短的一头向外,长的一头向内) 第一个引脚为正极,2和3 为接地。(用万用表二极管测试功能,测试连通性,联通的两端为接地)
j-link 问题:No Cortex-M SW Device Found 接口线接错了
注意: debug 调试不需要 boot ; 上位机烧录需要debug 孤注一掷 : https://www.rqsxbyc.com/yyetsp/77457-3-1/
环境配置nano /etc/profile#### jdk ####export JDK_HOME=/datadisk/eisc/server/path/jdk-20.0.2/binexport PATH=${JDK_HOME}:$PATH#### MVN ####export MVN_HOME=/datadisk/eisc/server/path/apache-maven-4.0.0-alpha-7/binexport PATH=${MVN_HOME}:$PATH# 目录根据实际修改reboot# 重启生效。或者: source /etc/profle ; bash 刷新1. jdkwget work.eisc.cn/ruanjian/ubuntu/deb/server/jdk-20_linux-x64_bin.tar.gz2.mavenwget work.eisc.cn/ruanjian/ubuntu/deb/bin//apache-maven-4.0.0-alpha-7-bin.tar.gzmvn archetype:generate -DgroupId=com.example -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false# 配置 mvn poxnano pom.xml# 在maven 根目录下 写入下面信息
4.0.0 com.example my-app 1.0-SNAPSHOT 1.8 1.8 mvn install ; mvn clean install#在maven 根目录下 执行命令
sudo apt-get install lutris# lutris 游戏模拟器需要 wine32:i386 支持sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install wine32:i386
https://github.com/lutris/dxvk/releases/download/v2.2/dxvk-2.2.tar.xz https://github.com/lutris/dxvk-nvapi/releases/download/v0.6.3/dxvk-nvapi-v0.6.3.tar.xz https://github.com/lutris/vkd3d/releases/download/v2.9/vkd3d-v2.9.tar.xzhttps://github.com/lutris/dgvoodoo2/releases/download/v2.8/dgvoodoo2-v2.8.tar.xzhttps://github.com/lutris/d3d_extras/releases/download/v2/v2.tar.xzgithub.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton8-13/wine-lutris-GE-Proton8-13-x86_64.tar.xzlutris-GE-Proton8-13-x86_64/bin/wine /home/eisc/下载/WeChatSetup.exe# 安装命令卸载 wine :sudo apt remove wine32:i386 -ysudo rm -rf ~/.wine/
MYSQL *conn; // MySQL连接
MYSQL_RES *res; // MySQL查询结果
MYSQL_ROW row; // MySQL行数据
conn = mysql_init(NULL);
// 连接到数据库
if (!mysql_real_connect(conn, DB_HOST, DB_USER, DB_PASS, DB_NAME, 0, NULL, 0)) {
fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(conn));
return 1;
// 查询数据
if (mysql_query(conn, "SELECT * FROM users")) {
fprintf(stderr, "Failed to query database: Error: %s\n", mysql_error(conn));
return 1;
res = mysql_use_result(conn);
// 输出查询结果
printf("ID\tName\n");
while ((row = mysql_fetch_row(res)) != NULL) {
printf("%s\t%s\n", row[0], row[1]);
// 插入数据
if (mysql_query(conn, "INSERT INTO users (id, name) VALUES (1, 'John')")) {
fprintf(stderr, "Failed to insert data: Error: %s\n", mysql_error(conn));
return 1;
// 更新数据
if (mysql_query(conn, "UPDATE users SET name='Tom' WHERE id=1")) {
fprintf(stderr, "Failed to update data: Error: %s\n", mysql_error(conn));
return 1;
// 删除数据
if (mysql_query(conn, "DELETE FROM users WHERE id=1")) {
fprintf(stderr, "Failed to delete data: Error: %s\n", mysql_error(conn));
return 1;
// 释放资源
mysql_free_result(res);
mysql_close(conn);
return 0;
如果你想在Ubuntu上搭建一个在线流程图的平台,你可以使用开源的项目来实现。其中一个流行的开源项目是draw.io,它提供了一个基于Web的流程图绘制工具。
要在Ubuntu上安装draw.io的源码,你可以按照以下步骤进行操作:
安装Java开发工具包(JDK):
sudo apt update
sudo apt install default-jdk
安装Apache Maven构建工具:
sudo apt install maven
克隆draw.io的源码仓库:
git clone https://github.com/jgraph/drawio.git
进入draw.io目录并使用Maven构建项目:
cd drawio
mvn clean package
构建完成后,在draw.io/target/目录下会生成war文件。将war文件部署到Tomcat或其他Java Web服务器中。
以上步骤会从draw.io的GitHub仓库克隆最新的源码,并使用Maven构建项目。你可以根据自己的需要进行修改和定制。
请注意,这只是一个基本的安装过程,你可能还需要进行其他配置和依赖项的安装,具体取决于你的环境和需求。你可以参考draw.io的官方文档和GitHub仓库以获取更详细的信息和指导。环境配置nano /etc/profile#### jdk ####export JDK_HOME=/datadisk/eisc/server/path/jdk-20.0.2/binexport PATH=${JDK_HOME}:$PATH#### MVN ####export MVN_HOME=/datadisk/eisc/server/path/apache-maven-4.0.0-alpha-7/binexport PATH=${MVN_HOME}:$PATH# 目录根据实际修改reboot# 重启生效。或者: source /etc/profle ; bash 刷新1. jdkwget work.eisc.cn/ruanjian/ubuntu/deb/server/jdk-20_linux-x64_bin.tar.gz2.mavenwget work.eisc.cn/ruanjian/ubuntu/deb/bin//apache-maven-4.0.0-alpha-7-bin.tar.gzmvn archetype:generate -DgroupId=com.example -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false# 配置 mvn poxnano pom.xml# 在maven 根目录下 写入下面信息
4.0.0 com.example my-app 1.0-SNAPSHOT 1.8 1.8 mvn install ; mvn clean install#在maven 根目录下 执行命令################ 安装在线流程图 ####################git clone https://github.com/jgraph/drawio.gitcd ./frawio/drawio/my-appmvn clean package在目录:./frawio/drawio/my-app/target 生成 tar包
以下情况下需要使用&操作符:
1. 指针类型: 定义 void foo(int* ptr) 调用 int num = 10; foo(&num);
2. 修改函数外部的变量 void modify(int* ptr){ *ptr = 20; } 调用:int num = 10; modify(&num); 最终将 ptr修改为 10
3. 输入 scanf 函数 int num; scanf("%d", &num);
传递的是基本类型的变量或者数组时,不需要使用&操作符,因为它们会被自动传递为值。例如,`void foo(int num)`,你可以直接传递变量的值来调用它,例如`int num = 10; foo(num);`。
需要注意的是,使用&操作符传递变量的地址时,需要确保接收参数的函数能够处理指针类型的参数。
如果要存储超长的文本数据,可以考虑使用动态内存分配来存储文本。在C语言中,可以使用malloc函数来动态分配内存空间,并使用char类型的指针来存储文本数据。
下面是一个示例代码,展示了如何使用动态内存分配来存储超长的文本数据:
#include
#include
int main() {
// 假设文本数据长度为10000
int length = 10000;
// 动态分配内存空间
char* text = (char*)malloc(length * sizeof(char));
// 检查内存分配是否成功
if (text == NULL) {
printf("Failed to allocate memory\n");
return 1;
// 读取文本数据到动态分配的内存空间中
// 这里使用fgets函数从文件中读取文本数据
FILE* file = fopen("text.txt", "r");
if (file == NULL) {
printf("Failed to open file\n");
free(text); // 释放动态分配的内存空间
return 1;
fgets(text, length, file);
// 关闭文件
fclose(file);
// 打印文本数据
printf("%s\n", text);
// 释放动态分配的内存空间
free(text);
return 0;
上述代码中,我们首先使用malloc函数动态分配了一个长度为length的字符数组,并将返回的指针赋值给text。然后,我们使用fgets函数从文件中读取文本数据并存储到动态分配的内存空间中。最后,我们使用printf函数打印出文本数据。
void process_packet(unsigned char *buffer, int size) {
struct iphdr *ip_header = (struct iphdr *)(buffer);
unsigned short ip_header_length = ip_header->ihl * 4;
struct tcphdr *tcp_header = (struct tcphdr *)(buffer + ip_header_length);
unsigned short tcp_header_length = tcp_header->doff * 4;
unsigned char *payload = buffer + ip_header_length + tcp_header_length;
int payload_length = size - ip_header_length - tcp_header_length;
// 在这里处理报文内容,可以打印报文信息或对报文进行其他操作
printf("Received packet with size: %d\n", size);
int main() {
int raw_socket;
unsigned char buffer[BUFFER_SIZE];
struct sockaddr_in server_address;
int data_size;
// 创建原始套接字
raw_socket = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
if (raw_socket < 0) {
perror("Failed to create socket");
return 1;
// 绑定地址
server_address.sin_family = AF_INET;
server_address.sin_port = 0;
server_address.sin_addr.s_addr = INADDR_ANY;
if (bind(raw_socket, (struct sockaddr *)&server_address, sizeof(server_address)) < 0) {
perror("Failed to bind");
return 1;
// 开始监听
while (1) {
data_size = recvfrom(raw_socket, buffer, BUFFER_SIZE, 0, NULL, NULL);
if (data_size < 0) {
perror("Failed to receive");
return 1;
process_packet(buffer, data_size);
return 0;
file_path = os.path.abspath(__file__) # 获取当前文件路径
dir_path = os.path.dirname(file_path) # 获取 文件的 路径
print("The current file is at: " + file_path)
print("The directory of the current file is at: " + dir_path)
#批量修改文件名
#批量修改图片文件名
zidir="1" # 定义子路径
DirPath = os.path.join(dir_path, zidir) # 拼接路径: 变量路径(当前路径)+子路径
print("#------------ 拼接路径: "+str(DirPath))
def renameall(): # 定义函数
fileList = os.listdir(DirPath) # listdir 函数 获取目录和文件
print("修改前:"+str(fileList)) # 输出文件夹中包含的文件
currentpath = os.getcwd() # 获取当前工作目录
os.chdir(DirPath) # chdir 改变当前工作路径
num=1 # 名称变量
for fileName in fileList: # 定义 fileName 是 fileList 数组的所有元素,并for 循环全部遍历
pat=".+\.(jpg|png|gif|py|txt)" # 匹配文件名(后缀文件)正则表达式
pattern = re.findall(pat,fileName) # 再列表 fileName 中查找 后缀名 pat 匹配的文件,最终成为一个列表
os.rename(fileName,(str("eiscSetOK_")+str(num)+'.'+pattern[0]))
# 文件重新命名函数
num = num+1 # 改变编号,继续下一项
print("------------------------- file --------------------------")
os.chdir(currentpath) # 改回程序运行前的工作目录
sys.stdin.flush() # 刷新
print("修改后:"+str(os.listdir(DirPath))) # 输出修改后文件夹中包含的文件
renameall() # 执行定义的函数
fileset=os.path.join(DirPath,file) # 定义需要修改的文件
def replace_line_with_keyword(file_name, keyword, new_line):
with open(file_name, 'r') as file:
lines = file.readlines()
with open(file_name, 'w') as file:
for line in lines:
if keyword in line:
file.write(new_line + '\n')
else:
file.write(line)
def main():
file_name = fileset
keyword = input("请输入要匹配的关键字:")
new_line = input("请输入新的行内容:")
replace_line_with_keyword(file_name, keyword, new_line)
print("文件内容替换成功!")
if __name__ == "__main__":
main()
def calculate_sum_and_product(a, b): # 定义运行函数,来调用上面两个函数
sum_result = calculate_sum(a, b) # 定义变量 的结果为 执行函数传入数值运行的结果
product_result = calculate_product(a, b)
# 返回计算得到的和与积
return sum_result, product_result # 反馈两个变量函数
# 调用calculate_sum_and_product函数,并获取它的返回值
sum_result, product_result = calculate_sum_and_product(5, 3)
# 定义两个变量 等于函数传入的数值结算结果
print("The sum is:", sum_result)
print("The product is:", product_result)
#--- 开启远程桌面 ---#sudo apt install -y xrdp# 方法一安装 xrdp 远程工具,缺点: 图像延迟#方法二: 缺点:锁屏下无法登陆设置 > 共享 > 远程桌面 > 开启远程桌面 和 远程控制, 认证 设置密码设置 > 共享 > 远程登陆 > 开启#--- 合盖不休眠 ---# NR=`cat -n /etc/systemd/logind.conf | grep -w HandleLidSwitch | awk -F" " '{print $1}'`if [ $NR -gt 0 ]; then sudo sed -i "$NR s/HandleLidSwitch.*/HandleLidSwitch=lock/g" /etc/systemd/logind.conf ; sudo sed -i "$NR s/#//g" /etc/systemd/logind.conf; echo "[ok] set file" ; else echo "[error] NR is null"; fi# 修改为 lock 锁屏# if 语句 为了避免错误修改,判断NR的数值大于0 才进行修改# 将 井 号替换为空cat -n /etc/systemd/logind.conf | grep HandleLidSwitch
B: Byte: 字节 8 位无符号数 范围 0-255
b: bit: 位 二进制中每个 0 或 1 就是一个位 bit
位说明: 从右 0 开始 向左数 最大为 7 即 0-7 表示 : 7 6 5 4 3 2 1 0 位置
#--- 编码:UTF8 ---#
1个汉字 = 3B = 3x8b = 24b
1个字母 = 1B = 1x8b = 8b
1个数字 = 1B = 1x8b = 8b
计算公式: 2^N - 1
uint8_t : 1 占用1位,0或1 最大 1 转换2进制 1
uint8_t : 2 占用2位,0到3之间的整数 最大 3 转换2进制 11
uint8_t : 3 占用3位,0到7 最大 7 转换2进制 111 = 2^3-1 = 8-1=7
uint8_t : 4 占用4位,0到15 最大 15 转换2进制 1111
uint8_t : 5 占用5位,0到31
uint8_t : 6 占用6位,0到63
uint8_t : 7 占用7位,0到127 在上一位的基础上 x2-1 最多只能表示 8 位二进制数 ,超过8位无效,可以换成 unit16_t 等
(由 10转2进制得来长度 如 7 转2 为 111 占3位)
data->name = (can2A5[2]&0x07); // 最大为 111 即 7 即 0x07 但是根据矩阵表 最大为 3 即 二进制 11 模式 为 0 1 2 3 对应吹面,吹面吹脚,吹脚,吹脚吹窗,吹窗
// can2A5报文中 的 第二个字节监听后 (0x07 是16进制 转换2进制为 111 占3位二进制内存 3bit) 三位二进制
data->name = (can2A5[3]&20)>>5 // 此处不是进行与计算,而 20 换算成二进制 0001 0100 占用5位二进制有效 向右移动五位,也就是去掉右边的5位,等于 第6位的结果,就是它的值
数据类型 占用空间 表示范围 说明
uint8_t 8b = 1B 0 到 255 占8位(单位 b) = 占1字节 (单位 B) 8 为由来: 255转二进制:1111 1111 为8 位
uint16_t 16b = 2B 0 到 65535 65535 转 二进制: 1111 1111 1111 1111 正好 16 位
uint32_t 32b = 4B 0 到 4294967295
uint64_t 64b = 8B 0 到 18446744073709551615 占 64 位 = 8 字节
#------- 结构体写入和读取方法 -----------#
uint8_t eisc2F1[7]; // 定义 数组为 uint8_t 是 8位类型,但数组有8个元素(从0开始),因此 有8个 8位的类型。 因为 8位=1字节,因此该数组有8个字节大小
typedef struct
uint8_t lock;
}eiscdataJGT; // 定义结构体 eiscdataJGT
extern eiscdataJGT eiscdata; // 将结构体 eiscdataJGT 写入到内存变量结构体 eiscdata ,可以通过 eiscdata.lock 读取和赋值
eiscdataJGT eiscdata; // 其他c文件声明结构体才能使用结构体变量
void eisc(eiscdataJGT *eisczz){ // 将结构体 继承给指针,可以通过指针方式进行读取和赋值到原结构体
eisczz->lock = (eisc2F1[4]&0x30)>>4;
// 最大3: 0x30=0011 0000 右移 4位 0000 0011=3 ,原信号在第五位开始有效。
// 并且 该信号占第5和第6 两位长度二进制 11 ,因此就在第五位。 第五位为1: 1 0000 (状态 1开 ,0关)
printf("信号的数值为:%d",eiscdata.lock);
// 读取结构体变量的数值
8位原始数据: 0000 0000 对应顺序:7 6 5 4 3 2 1 0; 右移:从右往左数; 左移:从左往右数 eisca[0]=0x20; // 内外循环:eiscdata->_fr = (eisca[0]&0x20)>>5; // 最大为1: 0x20=0010 0000 右移 5 位 0000 0001=1 目前在第6位上发送了最大值 1 表示开启: 0010 0000 = 0x20 按键按下是外循环 eiscf[3]=0x80; // 洗涤开 : eiscdata->xidi = (eiscf[3]&0x80)>>7; // 最大为1: 0x80=1000 0000 右移 7 位 0000 0001=1 目前在第7位上发送了最大值 1 表示开启: 1000 0000 = 0x80 eisc87[6]=0x3E; // 天窗开度 eiscdata->eisctc = (eisc87[6]&0xFE)>>1; // 最大为:0xFE=1111 1110 右移1位 0111 1111=127 目前在第2到7位上发送了 0x3E = 0011 1110 = 62; 62/2=31 结果除以为 31度 eisca[3]=0x34; // 蓝牙信号:eiscdata->eisctx = (eisca[3]&0x20)>>5; // 最大1: 0x20=0010 0000 右移5位 0000 0001 目前在第6位发送信号:0010 0000 + 下面设定温度20度组合 // eiscc_temp // 空调设定温度: eiscdata->eisc_temp = (eisctemp[3]&0x1F); // 最大为31: 0x1F=0001 1111=31 占用 1-5 位 ; 设定温度20度=0001 0100 与蓝牙信号 0010 0000 组合(相或)为:0011 0100=0x34 长度 信号位置eisctemp 1 4 第4位,占一位
$sudoc chmod 777 -R ./
./configure --prefix=./ --with-stream --with-http_stub_status_module
# nginx 开启 tcp 和 文件浏览模块: --with-stream --with-http_stub_status_module
NR=`cat -n ./src/os/unix/ngx_user.c | grep cd.current_salt | awk -F" " '{print $1}'` ; sleep 0.5
$sudoc sed -i "$NR d" ./src/os/unix/ngx_user.c ; sleep 0.5
$sudoc sed -i "s/-Werror/ /g" objs/Makefile ; sleep 0.5
# 先修改 c 文件,再修改make
$sudoc mkdir $setdir/logs ; $sudoc chmod 777 $setdir/logs
$sudoc make ; sleep 1 # make 会生成 新文件,新文件也需要修改才能编译
$sudoc sed -i "s/-Werror/ /g" objs/Makefile ; sleep 0.5
$sudoc make install
nginx_file_list
nginx_file_list()
echo "
sudo nano conf/nginx.conf
# http 模块外面写 tcp 配置路径: include /www/wwwconf/tcp/*.conf;
# http 模块 里面 http{} 写: include /www/wwwconf/http/*.conf;
sudo mkdir -p /www/wwwconf/tcp /www/wwwconf/http ; sudo chmod 777 -R /www/wwwconf/*
sudo nano /www/wwwconf/http/web.conf
# 开启文件浏览器功能
server{
listen 800;
#server_name eisc.cn
root /datadisk/eisc/download;
location / {
#root /mnt/software; #我们开始新建的目录
autoindex on; #以列表信息显示目录文件
index index.html index.htm;
charset utf-8;
sudo nano /www/wwwconf/tcp/tcp.conf
# tcp 转发
stream {
upstream eisc { server 8.219.134.200:1180; }
server { listen 1180; proxy_pass eisc; }
wget http://work.eisc.cn/ruanjian/ubuntu/gnome/Cupertino-Catalina.tar.gz
wget http://work.eisc.cn/ruanjian/ubuntu/gnome/Sierra-light.tar.gz
wget http://work.eisc.cn/ruanjian/ubuntu/gnome/Minimal-Conception.tar.gz
sudo tar -xzvf Cupertino-Catalina.tar.gz
sudo tar -xzvf Sierra-light.tar.gz
sudo tar -xzvf Minimal-Conception.tar.gz
sudo cp -R Sierra-light /usr/share/themes/
sudo cp -R Minimal-Conception /usr/share/themes/
# 主题+shell
sudo cp -R Cupertino-Catalina /usr/share/icons/
# 安装后,需要设置 扩展 运用软件 -> 下滑到 User Themes Load shell thems 打开这个功能
gnome-tweaks
# 点击外观 shell 选择 Minimal
# 点击运用程序 选择 Sierra-light
# 点击 图标 选择: Cupertino-Catalina
# 窗口标题栏 -> 标题栏按钮 -> 放置 -> 左
# 设置 -> 外观 -> dock -> 面板模式(关) -> 屏幕上的位置 (底部)
# 设置 -> Dock > 面板模式 : 将 Dock 延伸至屏幕边缘 -> 关闭
# 需要删除之前创建的 wifi : 光标选中 已创建的 点击 减 号
# 创建:点击 + 号 -> 选择连接类型 -> (硬件 wifi ) -> 创建 ->
# 连接名称: eisc -> SSID eisc -> 模式 : 热点wifi -> 频段 5G
# 设备:选择网卡 -> wi-Fi 安全性: WPA 及 WPA2 个人 -> 密码: aaaassss
# 常规:取消勾选: 自动以优先级连接
# 保存 (热点自动打开)
# 设置 -> wifi -> 右上角 三点多选 展开 -> 打开 wifi
教程: https://blog.csdn.net/weixin_48319333/article/details/129901969
在C语言中,一个文件可以使用不同的编码格式。如果您想将文件从其他编码格式转换为UTF-8编码格式,可以使用以下步骤:
确定原始文件的编码格式。可以使用文本编辑器或专门的编码检测工具来完成。
在C语言中打开原始文件,并使用适当的编码格式读取文件内容。
创建一个新的UTF-8编码格式的文件,并将读取的内容写入该文件中。在写入过程中,必须确保将原始编码格式转换为UTF-8编码格式。
关闭原始文件和新文件,完成文件转换。
下面是一个示例程序,用于将一个以GB2312编码格式保存的文件转换为UTF-8编码格式:
#include
#include
#include
int main()
// 设置本地化环境
setlocale(LC_ALL, "");
// 打开原始文件
FILE* fp_in = fopen("input.txt", "rb");
if (!fp_in)
printf("无法打开原始文件\n");
return 1;
// 打开新文件
FILE* fp_out = fopen("output.txt", "wb");
if (!fp_out)
printf("无法创建新文件\n");
return 1;
// 逐个读取原始文件中的字符,并将其转换为UTF-8格式写入新文件中
int ch;
while ((ch = fgetc(fp_in)) != EOF)
wchar_t wc = (wchar_t)ch;
char utf8[4];
int len = 0;
if (wc < 0x80)
utf8[0] = (char)wc;
len = 1;
else if (wc < 0x800)
utf8[0] = (char)(0xc0 | (wc >> 6));
utf8[1] = (char)(0x80 | (wc & 0x3f));
len = 2;
else if (wc < 0x10000)
utf8[0] = (char)(0xe0 | (wc >> 12));
utf8[1] = (char)(0x80 | ((wc >> 6) & 0x3f));
utf8[2] = (char)(0x80 | (wc & 0x3f));
len = 3;
else if (wc < 0x110000)
utf8[0] = (char)(0xf0 | (wc >> 18));
utf8[1] = (char)(0x80 | ((wc >> 12) & 0x3f));
utf8[2] = (char)(0x80 | ((wc >> 6) & 0x3f));
utf8[3] = (char)(0x80 | (wc & 0x3f));
len = 4;
fwrite(utf8, 1, len, fp_out);
// 关闭文件
fclose(fp_in);
fclose(fp_out);
printf("文件转换完成!\n");
return 0;
请注意,这只是一个示例程序,您需要根据您的具体需求进行修改和调整。同时,该程序只支持将单个字符从其他编码格式转换为UTF-8编码格式,如果文件中包含多字节字符或复杂字符集,您可能需要使用其他更加复杂的算法来完成转换。
}foo1, foo2; //define two structs with three different fields
void struct_assign(void)
foo2 = foo1; //structure directly assignment
int main()
foo1.a = "eisc is 结构体字符串 ";
foo1.b = 1;
foo1.c = 3.14;
struct_assign(); // 函数 将结构体 1 赋值 给 2
printf("%s %d %lf\n", foo2.a, foo2.b, foo2.c);
// 写入的是 1 读取的是 2 , 由于前赋值相等原因 1 和 2 相等
return 0;
算术运算符,关系运算符,逻辑运算符,位运算符,赋值运算符 #---- 算术运算符 ----#
+ - * / % ++ -- // 加减乘除, 取余,自增运算符整数增加1 在循环中使用普遍,减减 自减少
#---- 关系运算符 ----#
== != > < >= <= // 在 if 判断中: 相等,不相等,大于,小于,大等于,小等于 条件成立为真
#---- 逻辑运算符 ----#
&& || ! // 逻辑与 二进制位相乘以结果不为0 为真; 逻辑或 位相加的结果不为0 为真
// 逻辑非 逆转状态, 当为 0 的时候 逻辑非至反为 1
#---- 位运算符 ----#
& | ^ // 与 :换算成 2 进制,每一位进行相与(乘积)计算的结果; 或: 二进制相与(相加) 计算
// 异步: 二进制每一位对应位计算,如: 第一位: a 和 b 两个二进制变量。 全0 为0; 有1为1;全1为0: 1^1=0; 0^0=0; 1^1=0; 二进制每一位都按照这个规则计算
<< // 二进制 左移: A = 0011 1100 ; 操作 A << 2 整体左移两个位置为: 11 1100 右边补0为 : 1111 0000
>> // 二进制 右移: A = 0011 1100 ; 操作 A >> 2 整体右移两个位置为: 00 1111 左边补0为 : 0000 1111 正数补0 负数补1
#---- 赋值运算符 ----#
定义参数案例: int A=21; int B ;
= += -= // 变量等于值; 变量=变量本身+等于符号右边值; 变量=变量本身-等于符号右边值
// B += A 是两层运算:第一层运算为赋值: B=A=21; 第二层运算为 本身等于 本身和 等号右边 加法: B=B+A=21+21=42
*= /= // B *= A 是两层运算:第一层运算为赋值: B=A=21; 第二层运算为 B=B*A=441
%= // B %= A; B=B%A = 21%21 =0; 取余数, 被整除了。余数为0
<<= // 左移位 且赋值运算
>>= // 右移位 且赋值运算
&= // 按位 与 且赋值运算
^= // 按位异或 且 赋值
|= // 按位或 且赋值
scanf("%d", &x);
char arr[100] = { 0 }; //因为十六进制中会出现A\B\C\D\E\F等字符,所以保存余数的数组类型应定义为char
int i = 0, j = 0;
while (x)
arr[i++] = x % 16;
x /= 16;
for (j = 0; j < i; j++)
//将取出的余数转换为对应的字符
switch (arr[j])
case 10:arr[j] = 'A'; break;
case 11:arr[j] = 'B'; break;
case 12:arr[j] = 'C'; break;
case 13:arr[j] = 'D'; break;
case 14:arr[j] = 'E'; break;
case 15:arr[j] = 'F'; break;
default:arr[j] += 48;
for (j = i - 1; j >= 0; j--)
printf("%c", arr[j]);//逆序打印
printf("\n");
return 0;
void s16z10()
int a=0;
int i=0;
printf("请输入16进制数: ");
scanf("%x",&a);
printf("%d",a);
void s10z2()
int num;int temp;int i=0;
int arr[999];
printf("请输入一个十进制数:");
scanf("%d", &num);
temp=num%2;
num=num/2;
arr[i++]=temp;
while (num!=0);
for (int j = i-1; j>=0; j--)
printf("%d",arr[j]);
printf("\n");
int main()
int grade;
printf("请选择需要被转换的进制类型 1. 10转2进制; 2. 16转10进制; 3. 10转2进制 : ");
scanf("%d", &grade);
printf("当前输入的值为: %d \n",grade);
/* 局部变量定义 */
switch(grade)
case 1 :
printf("当前是十转十六进制\n" );
s10z16();
break;
case 2 :
printf("十六转十进制\n" );
s16z10();
break;
case 3 :
printf("十转二进制\n" );
s10z2();
break;
default :
printf("输入错误,请重新输入...\n" );
return 0;
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
# 设置编译器, 如果没有配置环境变量,可以改为gcc具体文件路径
include_directories(a)
include_directories(a)
include_directories(a)
# 添加 头文件搜索路径 (mysql.h 搜索路径)
#add_executable("xx" xx.c )
add_executable("xunhuan" xunhuan.c )
# 生成可执行文件: 将 test.cpp 编译成 test.exe 可执行文件
# rm -rf ./build ; cmake ./ -Bbuild -G "Unix Makefiles" ; cmake --build build
# rm -rf ./build ; cmake ./ -Bbuild ; cmake --build build
# 编译到当前目录下的 build 文件夹
# 也可以不用指定 -G
" > CMakeLists.txt
# 如果 echo 字符串中有 变量,需要加反斜线转义
autoINCPath(){
incList[0]="include_directories($dir/include/inc/)"
incList[1]="include_directories($dir/include/src/)"
incList[2]="include_directories($dir/include/)"
# 路径为绝对路径,相对路径会报错. 此数组个数与 CMakeLists.txt 中的 include_directories 个数对应
file="CMakeLists.txt"
incNumber=`cat -n $file | grep -w include_directories | wc -l` # wc -l 计算个数
if [ "${#incList[*]}" != "$incNumber" ]
echo "$file 文件 include_directories 定义个数 ${#incList[*]} 与 $incNumber 目标修改个数不相等,无法对应修改。"
echo "请在 touchCMake 和 autoINCPath 函数, 增加或者 删除 include_directories 关键字个数,以达到与目标修改个数一致。然后重新执行脚本"
incI=0;
while :
incNumberList=(`cat -n $file | grep -w include_directories | grep -v okset| awk -F" " '{print $1}' `)
Number=${#incNumberList[*]}
NR=${incNumberList[0]}
if [ "$Number" -lt "1" ]
echo "[ok] 当前绝对路径已经全部修正, 正在执行 CMakeLists.txt 自动化编译。 "
break
echo "[runing] 当前游标:$incI 当前修改行:$NR 当前剩余总修改次数: $Number 文件:$file 所有行:${incNumberList[*]} 目标内容:${incList[$incI]} "
sed -i "$NR a ${incList[$incI]} # [eisc.cn_okset]" $file
sed -i "$NR d " $file
# 始终修改第一个元素,然后由于循环再去查找行号
# 错误方式,删除一行后,其他内容行号会变,因此每次删除,需要重新扫描行号
# [okset] 修改了的地方做标记
let "incI++"
# 先获取 0 后,再自动增加。而不是 先增加: 0+1 第一次为 1
sleep 0.3
sleep 2
touchCMake ; autoINCPath
rm -rf ./build ; cmake ./ -Bbuild ; cmake --build build
./build/xunhuan
qqurl="http://work.eisc.cn/ruanjian/ubuntu/deb/work/qq/"
weixinurl="http://work.eisc.cn/ruanjian/ubuntu/deb/work/weixin/"
dir="/datadisk/eisc/download/weixin"
debList=(
linuxqq_3.1.1-11223_amd64.deb
ukylin-wine_70.6.3.25_amd64.deb
ukylin-wechat_3.0.0_amd64.deb
sudo mkdir -p $dir ; sudo chmod 777 $dir ; cd $dir
download_deb(){
for i in ${debList[*]}
debname=`echo $i | awk -F"_" '{print $1}'`
debnameInstalled=`sudo dpkg -l | grep $debname`
debnameInstalledLength=${#debnameInstalled}
if [ $debnameInstalledLength -gt 1 ]
echo "[ok] 该包 $i 已经安装,安装信息: $debnameInstalled"
echo "[runing] 正在检查是否下载安装包: $i"
if [ ! -e $i ]
echo "[runing] 当前没有下载,正在下载包:$i"
case "$i" in
"linuxqq_3.1.1-11223_amd64.deb") wget $qqurl/$i ;;
"ukylin-wine_70.6.3.25_amd64.deb") wget $weixinurl/$i ;;
"ukylin-wechat_3.0.0_amd64.deb") wget $weixinurl/$i ;;
*) echo "该包没有定义下载地址,包: $i"
echo "[ok] 已经下载: $i "
echo "正在安装: $i"
sudo apt install -y xdotool ; sudo apt --fix-broken install -y
# 安装依赖包
sudo dpkg -i $i
download_deb
# 一键安装:
# wget eisc.cn/file/ubuntu/shell/server/weixin.sh; sudo chmod +x weixin.sh ; ./weixin.sh
#define MAX
#define MAXIMUM(x,y)(x>y)?x:y
#define MINIMUM(x,y) (x>y)?y:x // 理解为: if ( x > y ) return y; else return x;
// 符号() 判断 ; 问号 ? 条件成立(then) 返回y的值; 冒号 : 条件不成立(else) 返回x
int main()
int a=10,b=20;
#ifdef MAX
printf("已经使用define 定义 MAX 宏 条件成立, 当前板块代码有效 %d\n",MAXIMUM(a,b));
#else
printf("没有定义 MAX 当前板块代码无效 %d\n",MINIMUM(a,b));
#endif
// endif 结束判断 宏
printf("ifndef 判断没有定义弘(多了一个n), 条件成立,该板块代码有效 MIN %d\n", MINIMUM(a,b));
#else
printf("已经定义 MIN 宏, 该板块代码无效 %d\n",MAXIMUM(a,b));
#endif
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
# 设置编译器, 如果没有配置环境变量,可以改为gcc具体文件路径
include_directories(/datadisk/eisc/server/mysql/mariadb1011/include/mysql/server/)
# include_directories(/datadisk/eisc/server/mysql/mariadb1011/include/mysql/)
# 添加 头文件搜索路径 (mysql.h 搜索路径)
#add_executable("set" set.cpp)
add_executable("sql" sql.cpp)
# 生成可执行文件: 将 test.cpp 编译成 test.exe 可执行文件
target_link_libraries(sql /datadisk/eisc/server/mysql/mariadb1011/lib/libmysqlclient.so)
# rm -rf ./build ; cmake ./ -Bbuild -G "Unix Makefiles" ; cmake --build build
# rm -rf ./build ; cmake ./ -Bbuild ; cmake --build build
# 编译到当前目录下的 build 文件夹
# 也可以不用指定 -G
c++ 代码#include
#include
#include
#include
#include "mysql.h"
using namespace std;
class MysqlDB
private: // private [ˈp raɪ vət] 私有
MYSQL mysql;
MYSQL_ROW row;
MYSQL_RES *result;
MYSQL_FIELD *field;
public:
MysqlDB()
if( mysql_init( &mysql ) == NULL ) // 判断数据库初始化
cout << "init error, line: " << __LINE__ << endl;
exit(-1);
~MysqlDB() // 波浪号是析构函数,删除创建的对象时执行。 不会返回任何值和带参数。作用:跳出程序释放资源
mysql_close( &mysql );
void connect( string host, string user, string passwd, string database )
//成功返回MYSQL指向的指针,失败返回NULL
if( !mysql_real_connect( &mysql, host.c_str(), user.c_str(), passwd.c_str(), database.c_str(), 0, NULL, 0 ) )
cout << "connect error, line: " << __LINE__ << endl;
exit(-1);
void createTB();
void add();
void del();
void update();
void print();
void MysqlDB::createTB()
string id, name, sex, birthday, CTtable;
cout << "请输入创建表信息:\n";
cin >> CTtable;
string sql = "create table "+ CTtable +"(id int, name varchar(10), sex varchar(20), birthday varchar(20));";
cout << sql << endl;
mysql_query( &mysql, sql.c_str() );
cout << "是否继续(y/n): ";
cin >> id;
} while( id == "y" );
void MysqlDB::add()
string id, name, sex, birthday,CTtable;
cout << "请输入写入信息:\n";
cin >> id >> name >> sex >> birthday;
string sql = "insert into stu(id,name,sex,birthday) values('" + id + "', '" + name + "', '" + sex + "', '" + birthday + "');";
cout << sql << endl;
mysql_query( &mysql, sql.c_str() );
void MysqlDB::del()
string id;
cout << "请输入删除信息的ID:\n";
cin >> id;
string sql = "delete from stu where id='" + id +"';";
cout << sql << endl;
mysql_query( &mysql, sql.c_str() );
cout << "是否继续(y/n): ";
cin >> id;
} while( id == "y" );
void MysqlDB::update()
string id, filed,value;
cout << "请输入修改信息ID,字段,值:\n";
cin >> id >> filed >> value;
string sql = "update stu set " + filed +"='" + value + "' where ID='" + id + "';";
cout << sql << endl;
mysql_query( &mysql, sql.c_str() );
cout << "是否继续(y/n): ";
cin >> id;
} while( id == "y" );
void MysqlDB::print()
string sql = "select * from stu;";
//成功返回0
mysql_query( &mysql, sql.c_str() );
//获取查询查询结果;成功返回result的指针,失败返回NULL
result = mysql_store_result( &mysql );
if( !result )
cout << "result error, line : " << __LINE__ << endl;
return ;
int num;
num = mysql_num_fields( result ); //返回字段个数
for( int i = 0; i < num; i++ )
field = mysql_fetch_field_direct( result, i ); //返回字段类型
cout << field->name << "\t\t"; //输出字段名
cout << endl;
while( row = mysql_fetch_row( result ), row != NULL )
for( int i = 0; i < num; i++ )
cout << row[i] << "\t\t";
cout << endl;
int main()
MysqlDB db; // 将 MysqlDB 继承给 db
db.connect( "127.0.0.1", "enchantment", "eisc.cn", "enchantment" );
db.print();
db.createTB();
db.print();
db.add();
db.print();
return 0;
# time: 2023.2.26
downdir="/datadisk/eisc/download" ; sudo mkdir -p $downdir ; sudo chmod 777 -R $downdir
installdir="/datadisk/eisc/server" ; sudo mkdir -p $installdir
# 安装路径不能将所有目录都为 777 , 如: mysql 的 /etc/my.cnf 不能为 777 否则mysql 无法启动
echo "
欢迎使用自动 shell 脚本自动配置 gitea git 仓库
server 源码下载路径:$downdir
server 安装路径:$installdir
C 2022.12.04 小绿叶技术博客 eisc.cn
sleep 2;
down_guanfang_url(){
giteaUrl="https://dl.gitea.com/gitea/1.18.5/gitea-1.18.5-linux-amd64"
down_eisc_url(){
giteaURL="http://work.eisc.cn/ruanjian/ubuntu/c/git/gitea"
down_select(){
read -p "选择下载安装包地址: 1 官方下载 2 小绿叶技术博客下载. 请输入: " selectURL
case $selectURL in
"1") echo "当前选择官方下载..." ; down_guanfang_url ;;
"2") echo "当前选择小绿叶技术博客下载..." ; down_eisc_url ;;
*) echo "输入错误,请重新执行脚本! " ; exit ;;
echo $gitea
gitea_install(){
sudo apt install git supervisor -y
git --version
if [ ! -e $downdir/gitea/gitea ]
sudo mkdir $downdir/gitea ; sudo chmod 777 $downdir/gitea
wget -O $downdir/gitea/gitea $giteaURL
echo "[ok] 已经下载包: $downdir/gitea/gitea "
if [ ! -e $installdir/gitea/gitea ]
sudo mkdir $installdir/gitea ; sudo chmod 777 $installdir/gitea
cp $downdir/gitea/gitea $installdir/gitea/gitea
echo "[ok] 已经安装包: $installdir/gitea/gitea "
gitea_user(){
# gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
# gpg --verify $installdir/gitea/gitea.asc $installdir/gitea/gitea
# gpg 签名密钥箱,防篡改
sudo adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
# 创建gitea用户
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea
# 创建工作路径
sudo chmod 750 /etc/gitea
sudo chmod 640 /etc/gitea/app.ini
# 写入权限
gitea_service(){
# ubuntu 以 systemd 服务方式,自动启动服务软件
# gitea_user
# 配置 gitea 用户和目录
sudo touch $systemdDir/$webname ; sudo chmod 777 $systemdDir/$webname
sudo chmod +x $giteaRun
sudo mkdir -p /var/lib/gitea/ ; sudo chmod 644 /var/lib/gitea/
sudo mkdir -p $installdir/shell ; sudo chmod 777 -R $installdir/shell
echo "#!/bin/bash
# bash 解释器 一定要在第一行 开头写,否则下面脚本不执行,开机启动不成功。 由于是 service服务,因此此脚本是 root 用户执行
$giteaRun &
" > $installdir/shell/gitea_start.sh
sudo chmod +x $installdir/shell/gitea_start.sh
sudo chown root:root $installdir/shell/gitea_start.sh $giteaRun
# 可执行文件 和 脚本属性是 root 用户才能开机启动
#----- 写入 start.service 服务 -----#
echo "
[Unit]
Description=gitea
[Service]
Type=forking
#ExecStart=$installdir/shell/gitea_start.sh
ExecStart=/bin/gitea
ExecReload=/bin/kill -SIGHUP \$MAINPID
ExecStop=/bin/kill -SIGINT \$MAINPID
[Install]
WantedBy=multi-user.target
" > $systemdDir/$webname
sudo apt install dos2unix -y
sudo dos2unix $systemdDir/$webname
# 转为 unix 格式,否则可能出现字符乱码
sudo chmod 644 $systemdDir/$webname
sudo systemctl daemon-reload
sudo systemctl disable $webname
sudo systemctl enable $webname
sudo systemctl start $webname
# 启动服务名称,不用加路径,配置了 service 相当于配置了环境变量,可以直接启动/停止服务名称
# 配置 gitea 开机启动
sudo mkdir -p /home/git/gitea/log/supervisor
# 配置日志服务
sudo chmod 777 /etc/supervisor/supervisord.conf
echo "
[program:gitea]
directory=/home/git/go/src/github.com/go-gitea/gitea/
command=/home/git/go/src/github.com/go-gitea/gitea/gitea web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gitea/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gitea/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
user = git
environment = HOME="/home/git", USER="git"
" > /etc/supervisor/supervisord.conf
sudo chmod 644 /etc/supervisor/supervisord.conf
sudo systemctl enable supervisor
sudo systemctl start supervisor
gitea_if_service(){
giteaRun="$installdir/gitea/gitea"
systemdDir="/usr/lib/systemd/system"
webname="gitea.service"
if [ ! -e $systemdDir/$webname ]
echo "[runing] 开始配置gitea.service 开机启动..."
gitea_service
echo "[ok] 已经配置 gitea.service 开机启动, 是否重新配置 开机启动?"
read -p "input y/n? : " xz
if [ "$xz" = "y" ]
echo "[runing] 开始配置gitea.service 开机启动..."
gitea_service
echo "[ok] 已经配置过gitea 开机启动,不需要重新配置!"
main(){
down_select
gitea_install
gitea_if_service
# echo "" > gitea.sh ; nano gitea.sh ; sudo chmod +x gitea.sh ; ./gitea.sh
dir="./" ; echo "当前目录: $dir"
sudo chmod 777 -R $dir/*
# FileList=(`du -ah $dir | awk -F" " '{print $2}'`)
# find ./ -type f | xargs dos2unix
# 列出所有文件和目录
# xargs 作用是将管道前面的结果内容(查找所有内容为 f 文件 ) 传递 给后面命令使用
apt_install()
linuxKernel=`cat /etc/os-release | grep -w ID | awk -F"=" '{print $2}'`
case "$linuxKernel" in
"ubuntu") sudo apt install -y dos2unix ; echo "[ok] 当前系统为: $linuxKernel 是 ubuntu..." ;;
"debian") sudo apt install -y dos2unix ; echo "[ok] 当前系统为: $linuxKernel 是 debian..." ;;
"centos") sudo yum install -y dos2unix ; echo "[ok] 当前系统为: $linuxKernel 是 centos..." ;;
"redhat") sudo yum install -y dos2unix ; echo "[ok] 当前系统为: $linuxKernel 是 redhat..." ;;
*) echo "未匹配到系统,你可以更换系统后再试试, 建议系统: ubuntu20 debian centos redhat" ;;
sleep 1
run_file()
destBM="GB2312"
# 定义转为 目标编码. 可以互相转换
fileTypeUtf8=`file $file | grep $destBM`
fileTypeUtf8Length=${#fileTypeUtf8}
case "$bm" in
"ISO-8859") bm="GB2312" ;;
"Non-ISO") bm="GB2312" ;;
if [ "$fileTypeUtf8Length" -lt "1" ]
echo "[runing] 编码 $bm 转为 $destBM $file 文件类类型: $fileType"
# sudo dos2unix $file
sudo iconv -c -f $bm -t $destBM $file -o $file.zhuanhuan
sudo mv $file.zhuanhuan $file
echo "[ok] 该文件:$file 已经是 $destBM 编码 该文件编码属性字符串长度为: $fileUtf8Length 文件类类型: $fileType"
Character_encoding()
for((i=0;i<${#FileList[*]};i++))
file=${FileList[$i]}
fileType=`file $file `
bmFileBZ=0
bmlist=( GB2312 ISO-8859 Non-ISO GBK UTF-8)
# GB2312 ISO-8859 GBK 三种编码是同类,填写
for bm in ${bmlist[*]}
bmFile=`file $file | grep $bm` ; bmFileLength=${#bmFile} ;
if [ "$bmFileLength" -gt 0 ]
echo "[runing] 当前文件 $file 编码是 $bm 开始处理 "
bmFileBZ=1
run_file
# if [ "$x"="0" ] && [ "$y" = "0" ] 多个条件判断
if [ "$bmFileBZ" = "0" ]
echo "[warning] 文件编码标记(0/1 未匹配/匹配编码): $bmFileBZ 当前文件 $file 编码非 ( ${bmlist[*]} ) 编码: `file $file`"
list_file()
szFile=( c h )
for szf in ${szFile[*]}
case "$szf" in
"c") echo "当前正在处理 .c 文件" ; FileList=(`find $dir -name "*.$szf"`) ; Character_encoding ;;
"h") echo "当前正在处理 .h 文件" ; FileList=(`find $dir -name "*.$szf"`) ; Character_encoding ;;
main(){
echo "ISO-8859 Non-ISO 编码等于 GB2312 编码; 重点: ASCI 在 utf8 和 gbk 中都存在,因此不要将 ASCI 编码进行转换 utf8 " ;
apt_install
list_file
# rm -rf ss11-a1; unzip ss11-a1.zip ; cp ~/cs/sh/utf8.sh ss11-a1/ ; chmod +x ss11-a1/utf8.sh ; ss11-a1/utf8.sh ; cat -n ss11-a1/src/APP/GetOutValue/GetOutValue.c | grep 1201
# iconv 编码转换脚本一键执行: wget eisc.cn/file/ubuntu/shell/tools/file/utf8.sh ; sudo chmod +x utf8.sh ; ./utf8.sh
######### windos配置 #############用户变量:--------------------------------------Path添加:%JAVA_HOME%\bin%JAVA_HOME%\jre\bin--------------------------------------JAVA_HOME添加包含JRE文件目录下的父文件夹为JDK目录-------------------------------------------系统配置:-------------------------------CLASSPATH配置.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;--------------------------------------JAVA_HOME添加包含JRE文件目录下的父文件夹为JDK目录-------------------------------------------Path添加:%JAVA_HOME%\bin%JAVA_HOME%\jre\bin--------------------------------------下载地址:jdk_1.8.0_151.zip########### ubuntu 配置 ##############下载地址:/datadisk/eisc/www/work/ruanjian/debian/jdk-8u321-linux-x64.tar.gz#debian 和ubuntu 通用tar -xzvf jdk-8u321-linux-x64.tar.gz -C ./# 解压到当前目录sudo nano /etc/profile#编辑环境变量export JAVA_HOME=/datadisk/eisc/server/jdk/jdk1.8.0_321export JRE_HOME=$JAVA_HOME/jreexport CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATHexport PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATHsource /etc/profile#生效环境变量
vscode:
官方: https://code.visualstudio.com/Download
其他下载: http://work.eisc.cn/ruanjian/windows/c/ruanjian/VSCodeUserSetup-x64-1.75.1.exe
ubuntu vscode: work.eisc.cn/ruanjian/ubuntu/deb/tools/vscode.debcmake:
官方: https://cmake.org/download/
其他下载: http://work.eisc.cn/ruanjian/windows/c/ruanjian/cmake-3.26.0-rc4.zip
gcc_g++:
其他下载: http://work.eisc.cn/ruanjian/windows/c/ruanjian/windos_mingw64.tar.gz
# 该文件中 目录 mingw64\bin\mingw32-make.exe 中的文件 已经重命名为 make.exe 为了解决下面 没有识别到make 命令 问题:
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!
################### vscode 基础配置 ###################
vscode 配置为中文:
1. 点击 vscode 左侧的扩展图标,打开侧边栏“EXTENSIONS”面板(魔方图标)
2. 点击搜索并安装 chinese 简体中文
3. 安装完成,点击右下角 Restart 重启 vscode
配置 gcc c++ :
1. 我的电脑-> 属性 -> 高级系统设置 -> 高级 -> 环境变量 -> 系统变量 -> Path -> 添加上面软件解压的路径,精确到bin目录 -> 重启电脑
2. 搜索安装 C/C++ Extension Pack (Popular extensions for C++ development in Visual Studio Code.) -> 重启电脑
3. 重启电脑后,可以看到 vscode 左下角的 状态栏 图标出现cmake 右边一个图标的扳手 No kit Selected ,点击它 -> 选择 GCC 8.1
如果 vscode 左下角还是没有出现 cmake 的功能,使用: Shift+Ctrl+p 弹出搜索 -> 输入cmake -> 点击 cmake 配置,自动弹出提示进行 选择 yes
################### cmake 基础使用 ###################
#--- 编译命令 ---#
点击 vscode 顶部状态栏 -> 终端 -> 新建终端 输入下面命令进行编译
mkdir build ; cd build
# 创建 build 编译目录, 并且进入
del * ; cmake ../ -Bbuild -G "Unix Makefiles" ; cmake --build build
# 删除build的目录所有文件
# cmake 构建命令
# cmake 编译
#--- cmake 案例 ---#
project(eisc)
cmake_minimum_required(VERSION 3.10)
# 编译要求:cmake 要大于最低版本 3.1
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
# 设置编译器, 如果没有配置环境变量,可以改为gcc具体文件路径
include_directories(../../test/include/)
include_directories(../../uds/)
include_directories(../../include/)
include_directories(../../driver/)
include_directories(../../core/)
# 添加 头文件搜索路径 (.h 搜索路径)
add_executable("test.exe" test.cpp)
# 生成可执行文件: 将 test.cpp 编译成 test.exe 可执行文件
# databases out save
# developer : eisc.cn
# 开发: 小绿叶技术博客; 功能:shell 自动导出数据库,将导出的格式为 : 数据库名+时间.sql
echo "linux user: $USER ; Enter the current user sudo password: " ; sudo date ; formatdate=`date +%Y.%m.%d-%H%M%S` ; echo "time year month day Hour branch second: $formatdate "
dir=/datadisk/eisc/back/sql
sudo mkdir -p $dir ; sudo chmod 777 $dir
# 数据库导出文件保存目录, 创建这个目录,和附加权限
DestDir=/datadisk/eisc/back/sql
DestDBName=(`ls $DestDir | grep "sql" | grep -vE "tar|gz|zip|sh"`)
# 目标服务器,需要导入的数据库文件。根据实际存放目录修改
# user=root
# passwd=eisc.cn
# dataip=127.0.0.1
# 脚本中配置 数据库用户名 和密码 和数据库链接地址
if [ "$user"="" ]
echo "请输入数据库管理员用户和密码以及ip, 案例:root eisc.cn 127.0.0.1
Please enter the database administrator user and password and ip, case: root eisc.cn 127.0.0.1
read -p "input: " inputuser
echo "[ok] 已经定义过 user 和 passwd 的值!"
inputuser=($inputuser)
user=${inputuser[0]}
passwd=${inputuser[1]}
dataip=${inputuser[2]}
export_databases(){
databases=(`mysql -u $user -p$passwd -e "show databases;"`)
NoOutDatabases=(Database information_schema mysql performance_schema sys )
# 这是系统库,不是项目中的数据库。只需要导出项目库
echo "databases is : ${databases[*]}
NoOutDatabases is : ${NoOutDatabases[*]}
sudo tar -czvf $dir/sqlback_$formatdate.tar.gz $dir ; sudo rm -rf $dir/*
for i in ${databases[*]}
echo "#-------- database $i -----------# "
for o in ${NoOutDatabases[*]}
case "$i" in
"$o") echo " [ok] $i : The current database does not need to be exported!" ; OutStatus=0 ; echo "" ;echo "" ;;
if [ "$OutStatus" = "1" ]
sql="sudo mysqldump --column-statistics=0 -h $dataip -u $user -p$passwd --databases $i"
echo "[runing] shell cmd: $sql" ; echo ""
$sql > $dir/$i-$formatdate.sql
# mysqldump 不支持有变量的数据库,因此赋值为字符串
# 因为新版的mysqldump默认启用了一个新标志,通过- -column-statistics=0来禁用他
echo "[ok] $i Database does not need to be saved"
OutStatus=1
# 状态 为 1 才进行导出数据,由于受到 NoOutDatabases 不导出影响,会被定义为 0. 最后再次将状态更新为正常 1
# 注意: shell if 判断的时候需要在变量和值加双引号,否则异常
echo "数据库导出保存目录: $dir 将目录 $dir 备份为:sqlback_$formatdate.tar.gz"
ls -alh $dir
mysql_database_tools(){
#!/bin/bash
# shell 自动创建数据库 用户和密码
sudo apt install libncurses*
# 解决mysql 命令报错,缺少库:Couldn't find any package by glob 'libncurses.so.5'
sudo apt install mysql-client -y
# 安装连接数据库工具
sudo mkdir /var/run/mysqld/
sudo ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock
# 解决 mysql 报错,无法进入mysql 。 mariadb 的启动sock 不一样
runmysql=`sudo netstat -nltp | grep 3306 | grep -w tcp | grep mariadb`
if [ ${#runmysql} -lt 1 ]
sudo /etc/init.d/mariadb1011 start
sudo $installdir/mysql/mariadb1011/bin/mysqladmin -u root password eisc.cn
# 启动数据库,重置数据库 root 用户密码为: eisc.cn
echo "#---------------- 数据库管理工具 ------------#
参考输入案例: create eisc.cn www www 000000 localhost
1 创建 or 删除,输入: create 或 drop
2 数据库 root 用户密码
3 子数据库名
4 子库用户名
5 子库密码
6 开放数据库方式:本地/远程 输入: localhost 或 %
用空格隔开,必须按照顺序输入6个参数!"
read -p "请输入:" in_buff
buff=( abcd $in_buff);
echo "你输入的信息为: ${buff[*]}";
case ${buff[1]} in
"create")
# mysql -uroot -p${buff[2]} -e "create database ${buff[3]} character set utf8 collate utf8_bin;"
mysql -uroot -p${buff[2]} -e "create database ${buff[3]} character set utf8;"
mysql -uroot -p${buff[2]} -e "grant all on ${buff[4]}.* to '${buff[4]}'@'${buff[6]}' identified by '${buff[5]}'"
mysql -uroot -p${buff[2]} -e "show databases;SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS ListUsername FROM mysql.user where User='${buff[4]}';"
"drop")
mysql -uroot -p${buff[2]} -e "drop database ${buff[3]}"
mysql -uroot -p${buff[2]} -e "drop user '${buff[4]}'@'${buff[6]}'"
mysql -uroot -p${buff[2]} -e "show databases;SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS ListUsername FROM mysql.user where User='${buff[4]}';"
import_databases(){
dipasswd=eisc.cn
# 定义 子库密码
echo "将从文件目录: $DestDir 导入数据库, 注意,不能出现重复的数据库文件。一个数据库保留一个sql 文件。列出该目录的文件,如下:" ; ls $DestDir
read -p "是否将文件放置在该目录?y/n:" fzfile
if [ "$fzfile" != "y" ]
echo "[ok] 退出! 将文件复制到该目录后,重新执行函数"
echo "如果遇到问题,你可以使用 mysql管理工具来创建数据库和用户, 不使用该工具,会自动创建数据库。"
for((s=0;s<${#DestDBName[*]};s++))
di=`echo ${DestDBName[$s]} | awk -F"-" '{print $1}'`
difile=${DestDBName[$s]}
ShowDBName=`mysql -h $dataip -u $user -p$passwd -e "show databases" | grep $di `
if [ "$ShowDBName" = "$di"]
echo "[error] Database exists $di "
echo "[ok] runing import data $di"
mysql -h $dataip -u $user -p$passwd -e "create database $di character set utf8;"
mysql -h $dataip -u $user -p$passwd -e "grant all on $di.* to '$di'@'localhost' identified by '$dipasswd'"
mysql -h $dataip -u $user -p$passwd -e "show databases;SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS ListUsername FROM mysql.user where User='$di';"
mysql -h $dataip -u $user -p$passwd -e "use $di ; source $DestDir/$difile ; show tables;"
echo "[ok] import databases $DestDir/$difile "
set_file_mysqlpasswd(){
webdir=(
"/datadisk/eisc/www/www/puyuetian/mysql/config.php"
"/datadisk/eisc/www/xibin/puyuetian/mysql/config.php"
for file in ${webdir[*]}
echo "set in $file"
NR=`cat -n $file | grep PASSWORD | grep -v MYSQL | awk -F" " '{print $1}'`
sed -i "$NR a \$_G['SQL']['PASSWORD'] = 'eisc.cn';" $file
sed -i "$NR d" $file
cat -n $file
main(){
echo "
欢迎使用,小绿叶技术博客 eisc.cn 数据库搬家,数据库导出与导入工具,提供工具功能:
1. 数据库导出
2. 数据库导入
3. 数据库管理工具,创建与删除数据库和用户
请输入功能序号:
Welcome to the small green leaf technology blog eisc.cn database move, database export and import tool, providing tool functions:
1. Database export
2. Database import
3. Database management tool, creating and deleting databases and users
Please enter the function serial number:
read -p "input number: " tnumber
case "$tnumber" in
"1") echo "[runing] 1. Database export" ; export_databases ;;
"2") echo "[runing] 2. Database import" ; import_databases ;;
"3") echo "[runing] 3. Database management tool" ; mysql_database_tools ;;
set_file_mysqlpasswd
# 一键下载使用: wget eisc.cn/file/ubuntu/shell/server/mysql_export_import.sh ; chmod +x mysql_export_import.sh ; ./mysql_export_import.sh
char DirServer[30]="/datadisk/eisc/server/";
char AnfangDir[99]="anfang";
char logname[20]="eisc_anfang_log.txt";
// 不给长度,系统默认会定义长度,会导致错误,因此需要给长度
char MkdirSh[99]="sudo mkdir -p ";
char ChmodSh[99]="sudo chmod 777 -R ";
//char eiscshuom[50]="this is eisc anfang xitong + - =";
char eiscshuom[50]="#---------- eisc ------------#";
/*---------- 创建所有服务安装文件夹 -----------*/
int log_run()
strcat( MkdirSh, DirServer);
strcat( ChmodSh, DirServer);
// 注意:前面定义了变量,需要再函数里面进行赋值追加字符串,否则错误
system(MkdirSh);
system(ChmodSh);
cout << "\n mkdirsh is : " << MkdirSh ;
cout << "\n chmodsh is : " << ChmodSh;
return 0; // 终止函数,并且反馈该函数的值为0; return 0 正常退出,return 1 异常退出 , return -1 函数失败
/*---------- 创建安防文件夹 -----------*/
void mkdir_path(char *p_cMkdir)
int isCreate = mkdir(p_cMkdir,S_IRUSR | S_IWUSR | S_IXUSR | S_IRWXG | S_IRWXO);
// 创建文件 指定权限
if( !isCreate )
cout << "\n [ok] create AnfangDir:" << p_cMkdir ;
cout << "\n [fall] create AnfangDir failed! error code: " << p_cMkdir ;
/*---------- 写入日志文件 -----------*/
int W_file()
FILE * fp;
fp = fopen (logname, "a+"); // w+ 覆盖并写入 ; a+ 末尾追加字符串
fprintf(fp, "%s %d", eiscshuom, 2023); // 格式化输出流到 fp 指针文件
fclose(fp); // 关闭指针
return(0);
/*---------- 读取日志文件 -----------*/
int R_file ( char *lognamea)
FILE *fp;
char c;
char buffer[9999];
fp=fopen(lognamea,"r+");
if(!fp)
cout << "[fail] 读取文件为空,或者没有读取到文件: ";
cout << "\n 即将退出 R_file 整个函数, 退出效果来源: return -1 \n \n \n ";
return -1;
cout << "\n [ok] fp 指针获取到文件 非 0 非空,值为: " << lognamea;
while(1)
c=fgetc(fp); // fgetc 从指定流fp 获取下一个字符. 由于循环一次读一个字符。一直读取字符到变量 c
if( feof(fp) ) // feof 判断文件是否结束:测试给定流的文件结束符标识 。 文件读完,就 break 退出循环
break;
cout << c; // 读取到一个字符,打印一个字符
fseek(fp, 5, SEEK_SET); // 查找 文件开头,指针初始化方向开头: 从 文件流 选择第几个字符位置
fread(buffer, strlen(eiscshuom)+5, 1, fp); // 从文件中读取字符串,读取一个元素,长度为 eiscshuom变量的长度
cout << " \n [ok] 变量 c 获取到fp指针流赋值的字符: \n " << "\n 变量 buffer 从 fp 读取元素个数和数量 结果为: " << buffer << "\n \n " ;
// strlen(c)+1 表示统计c 变量的长度还要加1
fclose(fp);
return status; // 终止函数,并且反回该函数的值为 0
/*------------ 判断 R_file 函数 -------------*/
int panduan_xuexi(){
int status=0;
if( !R_file(logname))
cout << "if 默认成立条件是 非0 非空, 感叹号 ! 是非运算 条件取反,相当于 结果为 是 0 是空 条件成立";
cout << "\n [ok] 函数 R_file 返回的值为0 " ;
cout << "\n [fall] 函数 R_file 返回的值不为0 ";
return 0;
int main()
log_run();
strcat(DirServer, AnfangDir );
strcpy(AnfangDir,DirServer);
cout << "\n AnfangDir 的值为:" << AnfangDir;
cout << "\n 我是main 函数 AnfangDir 接收到值:" << AnfangDir;
mkdir_path(AnfangDir);
W_file();
panduan_xuexi();
return 0;
// rm -rf file ; echo "" > file.cpp ; nano file.cpp ; g++ file.cpp -o file ; chmod +x file; ./file
// 软件流程 : 创建安装目录 -> 创建 log.txt 文件 -> 写入eisc -> 开始抓包 -> 等待时间结束抓包 ->读取日志文件 -> 判断 ip 是否大于预设值
#include
#include
int main()
FILE *fp;
char buffer[20];
fp = fopen("eisc_anfang_log.txt", "r+");
// fseek(fp, 0, SEEK_SET);
fread(buffer, 3, 1, fp);
printf("%s\n", buffer);
fclose(fp);
return(0);
// rm -rf cs ; echo "" > cs.c ; nano cs.c ; gcc cs.c -o cs ; ./cs
char DirServer[30]="/datadisk/eisc/server/";
char AnfangDir[99]="anfang";
char logname[20]="eisc_anfang_log.txt";
// 不给长度,系统默认会定义长度,会导致错误,因此需要给长度
char MkdirSh[99]="sudo mkdir -p ";
char ChmodSh[99]="sudo chmod 777 -R ";
int log_run()
strcat( MkdirSh, DirServer);
strcat( ChmodSh, DirServer);
// 注意:前面定义了变量,需要再函数里面进行赋值追加字符串,否则错误
system(MkdirSh);
system(ChmodSh);
cout << "\n mkdirsh is : " << MkdirSh ;
cout << "\n chmodsh is : " << ChmodSh;
// system("tcpdump -nn > /datadisk/eisc/server/anfang/sh/log/log.txt &");
return 0;
// 终止函数,并且反馈该函数的值为0
void mkdir_path(char *p_cMkdir)
int isCreate = mkdir(p_cMkdir,S_IRUSR | S_IWUSR | S_IXUSR | S_IRWXG | S_IRWXO);
if( !isCreate )
cout << "\n [ok] create AnfangDir:" << p_cMkdir ;
cout << "\n [fall] create AnfangDir failed! error code: " << p_cMkdir << "\n \n" ;
int W_file()
char shuoming[30]="this_is_eisc_anfang_tcpdump";
ofstream setfile;
setfile.open(logname);
setfile << shuoming;
setfile.close();
// 定义 setfile 变量为 ofsteram 输入文件流,它的值为打开文件。 将 字符串变量的值写入文件流变量; 关闭流
int R_file ( char *lognamea, int status)
char data[999];
ifstream catfile; // ifstream 以读模式打开文件, ofstream 是写模式。 将类型赋值给变量 infile
catfile.open(lognamea); // 变量打开文件
cout << "\n Reading_from_the_file: " << lognamea ;
catfile >> data; // 将文件流,输入到 变量 data
cout << "\n data 变量 获得文件内容: " << data << "\n \n \n 获取到 status 的值为: " << status << "\n \n";
catfile.close(); // 关闭打开的文件
return status; // 终止函数,并且反回该函数的值为0
int panduan_xuexi(){
int status=0;
if( !R_file(logname,status))
cout << "if 默认成立条件是 非0 非空, 感叹号 ! 是非运算 条件取反,相当于 结果为 是 0 是空 条件成立";
cout << "\n [ok] 函数 R_file 返回的值为0 " ;
cout << "\n [fall] 函数 R_file 返回的值不为0 ";
int main()
log_run();
strcat(DirServer, AnfangDir );
strcpy(AnfangDir,DirServer);
cout << "\n AnfangDir 的值为:" << AnfangDir;
// memcpy( path, DirServer,99);
cout << "\n 我是main 函数 AnfangDir 接收到值:" << AnfangDir;
mkdir_path(AnfangDir);
W_file();
panduan_xuexi();
// int const Mask = Bits1_GetMsk(bit);
if (val){
printf("c 中的 if 默认条件:当前 val 的值不为空,或者不为0 条件成立 ; 我的值是:%d 等于接收都控制信号" , val);
} else {
printf("val 为 0 或者 为空, if 的默认条件就不成立");
void shanshuo(void)
if (flag == 0)
test(0,1);
flag=1;
// 因为需要实现 闪灯,一会关一会开,因此开启后关闭,实现闪烁
printf(" \n \n 【当前控制灯为 开】 \n 当前 flag 的值为 0 , 我执行函数 写入 1 开启灯 ; 函数控制硬件后,我将其 设置为1 进行变换 \n \n ");
test(0,0);
flag=0;
// 因为 flag 的值不为 0 ,因此将其赋值为 0 ,等于将 1 变换成 0 ,实现开关作用,闪烁
printf(" \n \n 【当前控制灯为 关】 \n 当前 flag 的值不为 0 , 我执行函数 写入 0 关闭灯 ; 函数控制硬件后,我将其 设置为0 进行变换 \n \n ");
int main()
while(1)
printf("测试无限循环打印");
usleep(200000);
cishu++;
printf("当前 得到 次数 :%d \n" , cishu);
shanshuo();
if (cishu > jhcs )
printf("当前循环执行闪烁次数:%d 已经超过计划次数: %d 现在退出 闪烁功能 \n " , cishu, jhcs);
break ; // 退出本函数,或者退出循环
} else {
printf("当前已经执行次数: %d \n", cishu);
printf("循环函数 停止运行了! ");
1.转换说明符
%a(%A) 浮点数、十六进制数字和p-(P-)记数法(C99)
%c 字符
%d 有符号十进制整数
%f 浮点数(包括float和double)
%e(%E) 浮点数指数输出[e-(E-)记数法]
%g(%G) 浮点数不显无意义的零"0"
%i 有符号十进制整数(与%d相同)
%u 无符号十进制整数
%o 八进制整数 e.g. 0123
%x(%X) 十六进制整数() e.g. 0x1234
%p 指针
%s 字符串
%% "%"
参考:https://blog.csdn.net/qq_29874741/article/details/94626531
0 0x0f 0xf0 0x08 --> 0000 1000
#define clrSetReg8Bits(RegName, ClrMask, SetMask) f0 08 (RegName = (RegName & ((byte)(~(byte)(ClrMask)))) | (byte)(SetMask))
存储器: 当前是与非或计算: 由于前面函数传入:参数 0xf0 0x08u
(~(byte)(ClrMask)) : f0 非运算: 原值为1 则非计算 为0 ; 再与 0 与计算 有0 为0 ; 再与 | (byte)(SetMask) 或计算
ifstream infile;
infile.open("1.txt",ios::in);
// ios::app 追加模式,写入到文件末尾 ; ios::ate 打开文件定位到末尾 ;ios::in 打开文件用于读取; ios::out 打开文件用于写入 ; ios::trunc 打开文件,存在就被截断,长度为 0
cout << "Reading from the file" << endl;
infile >> data;
// 在屏幕上写入数据
cout << data << endl;
// 再次从文件读取数据,并显示它
infile >> data;
cout << data << endl;
// 关闭打开的文件
infile.close();
return 0;
wget -O gitea https://dl.gitea.io/gitea/1.17.4/gitea-1.17.4-linux-amd64chmod +x gitea ; ./gitea web参考连接:https://docs.gitea.io/zh-cn/install-from-binary/ Jenkins: https://www.jenkins.io/zh/doc/book/installing/物联网网关平台:http://www.ithingsboard.com/docs/reference/http-api/node-red: https://nodered.org/
// c++ 类 访问控制和继承,能访问的类型:
// 同一个类: public protected [prəˈtektɪd] 受保护 private [ˈpraɪvət] 私有
// 派生类:public protected
// 外部类:public
class A{
public:
// 定义类 A 的公共函数 A 和 fun
int a;
a1 = 1;
a2 = 2;
a3 = 3;
a = 4;
void fun(){
cout << a << endl; //正确
cout << a1 << endl; //正确
cout << a2 << endl; //正确
cout << a3 << endl; //正确
public:
int a1;
protected:
int a2;
private:
int a3;
class B : public A{
public:
// 派生类
int a;
B(int i){
a = i;
void fun(){
cout << a << endl; //正确,public成员
cout << a1 << endl; //正确,基类的public成员,在派生类中仍是public成员。
cout << a2 << endl; //正确,基类的protected成员,在派生类中仍是protected可以被派生类访问。
// cout << a3 << endl; //错误,基类的private成员不能被派生类访问。
int main(){
B b(10);
//外部类,只能访问 public
cout << b.a << endl;
cout << b.a1 << endl; //正确
// cout << b.a2 << endl; //错误,类外不能访问protected成员
// cout << b.a3 << endl; //错误,类外不能访问private成员
return 0;
tongjifile="tongji.txt"
charulog=("`n="0x1" ; cat $i | grep "nEventType" |grep -v JT | awk -v awknr="$n" '$NF==awknr' | awk -F"," '{print $4 "," $5}' |uniq -c | sort -n`")
charu=(` n="0x1" ; cat $i | grep "nEventType" |grep -v JT | awk -v awknr="$n" '$NF==awknr' | awk -F"," '{print $4 "," $5}' |uniq -c | sort -n | awk -F" " '{print $1}' `)
charu=`echo ${charu[*]} | sed "s/ /+/g"` ; charu=$[charu]
charulv=`echo "" | awk -v charu="$charu" -v cishu="$cishu" '{printf "%0.2f",charu/cishu*100}'` ; charulv=${charulv:0:4}
lablelist=$(n="0x1" ; cat $i | grep "nEventType" |grep -v JT | grep "labelNum = $lable" | awk -v awknr="$n" '$NF==awknr' | awk -F"," '{print $4 "," $5}' |uniq -c | sort -n)
lablegs=$(echo $lablelist | awk -F" " '{print $1}') ; lablegs=`echo "" | awk -v lablegs="$lablegs" -v cishu="$cishu" '{printf "%0.2f",lablegs/cishu*100}'` ; lablegs=${lablegs:0:4}
bachulog=("`n="0x2" ; cat $i | grep "nEventType" |grep -v JT | awk -v awknr="$n" '$NF==awknr' | awk -F"," '{print $4 "," $5}' |uniq -c | sort -n`")
bachu=(` n="0x2" ; cat $i | grep "nEventType" |grep -v JT | awk -v awknr="$n" '$NF==awknr' | awk -F"," '{print $4 "," $5}' |uniq -c | sort -n | awk -F" " '{print $1}' `)
bachu=`echo ${bachu[*]} | sed "s/ /+/g"` ; bachu=$[bachu]
bachulv=`echo "" | awk -v bachu="$bachu" -v cishu="$cishu" '{printf "%0.2f",bachu/cishu*100}' ` ; bachulv=${bachulv:0:4}
echo "#-------------- $i ---------------# " >> $tongjifile
echo " 测试次数:$cishu 识别插入次数: $charu 识别插入正确率: $charulv % 识别拔出次数: $bachu 识别拔出识别率:$bachulv % 贴标签个数: $lable 正确识别标签率:$lablegs % " >> $jieguofile
echo " 测试次数:$cishu 识别插入次数: $charu 识别插入正确率: $charulv % 识别拔出次数: $bachu 识别拔出识别率:$bachulv % 贴标签个数: $lable 正确识别标签率:$lablegs % " >> $tongjifile
echo " " >> $tongjifile
echo "
#----------- 识别插入日志 -------------#
${charulog[*]}
#----------- 识别拔出日志 ------------#
${bachulog[*]}
#---------- 识别标签正确日志 ------------#
$lablelist
" >> $jieguofile
runset(){
file=(`ls | grep log | grep -v tongji`)
for i in ${file[*]}
set_config_log
runset
#include
#include
// 字符串操作函数 :1 strcpy 2 memcpy 3 strncpy 4 memset 5 strcat 6 strlen 7 strcmp
// 1 和 2 复制并且替换原变量,1 仅支持字符串; 3 替换字符串开头多少位; 4 将变量二的多少位添加到 变量一的尾部
// 5 字符串末尾追加; 6 计算字符串长度; 7 比较两个字符串,= > < 返回 0 1 -1
int zifu (char aa[],char bb[])
char str1[99];
memcpy(str1,aa,strlen(aa)); printf("memcpy 函数 将 aa 数组字符串, 长度为 aa 大小 到 str1 得到的值:%s \n \n", str1);
// 数组不能直接赋值,只能 cpy 复制。 strcpy 只能复制字符串 遇到符"\0" 结束 。
// memcpy 可以复制任何内容: 如数组。 包含“\0” 可以复制
strncpy(str1,bb,2); printf("strncpy 函数 将 bb 中的 前两位追加到 str1 末尾,值:%s \n \n", str1);
memset(str1,aa, strlen(aa)); printf("memset 替换前面 aa 变量数 位为:%s \n aa 的值: %s \n ",str1,aa);
char str2[40];
char str3[99];
strcpy (str3,"copy successful"); printf(" strcpy 复制并且覆盖目前 str3 的值: %s \n ",str3);
strcpy (str3,str1); printf ("str1: %s\nstr2: %s\n 覆盖函数 strcpy 用str1覆盖后 str3: %s\n",str1,str2,str3);
return 0;
void main()
char a[20]="aaaaaaaaaa" ; char b[20]="bbbbbbbbb"; zifu(a,b);
// 先定义参数,按照顺序传值给函数并且执行
1.nginx 开启 tcp 转发 2. 配置nginx负载均衡# nginx 做负载均衡是基于 nginx 的tcp 转发,转发多个目标地址来实现的 # 1. nginx 配置tcpyum install nginx-mod-stream -y # 安装动态模块ll /usr/lib64/nginx/modules # 查看动态模块文件vi /etc/nginx/nginx.conf # 设置配置文件重点:需要注释掉动态模块冲突引用:# include /usr/share/nginx/modules/*.conf;# 添加配置:nginx 主配置文件最外层添加,可以第一行顶部顶部添加load_module /usr/lib64/nginx/modules/ngx_stream_module.so;include /www/www/tcp/*.conf;# 设置动态模块的配置文件路径 # 2. 配置nginx负载均衡 stream { upstream eisc { ip_hash; # 会话保持 server 192.168.0.14:8080 weight=3; server 192.168.0.15:8080 weight=7; # 权重越高,在被访问的概率越大,分别是30%,70%。 # 如吧不需要配置权重,可以取消weight 参数 } server { listen 80; proxy_pass eisc; # 添加web服务 80 端口,请求转发到 eisc 规则 }}#---------- 案例 2 -----------# stream {
upstream eisc { server 8.219.134.200:1180; }
server { listen 1180; proxy_pass eisc; }
} # 3 nginx 配置站点显示文件
server{
listen 800;
#server_name kbash.cn www.kbash
root /datadisk/eisc/download;
location / {
#root /mnt/software; #我们开始新建的目录
autoindex on; #以列表信息显示目录文件
index index.html index.htm;
charset utf-8;
前提条件:nginx 开启tcp 端口转发:https://www.eisc.cn/index.php?c=read&id=978&page=1
# 系统服务cd /usr/lib/systemd/system/sudo nano web_start.service# 进入目录,编辑文件写入服务, unit 服务器说明, ExecStart 启动的内容[Unit]
Description=start web
[Service]
Type=forking
ExecStart=/datadisk/eisc/server/shell/start.sh
ExecReload=/bin/kill -SIGHUP $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target sudo systemctl daemon-reload sudo systemctl disable web_start.service sudo systemctl enable web_start.service# 重载配置, 先删web除开机启动 ,再添加 服务sudo mkdir -p /datadisk/eisc/server/shell/ ; cd /datadisk/eisc/server/shell/ sudo chown root:root start.sh ; sudo chmod 777 start.shsudo nano /datadisk/eisc/server/shell/start.sh#!/bin/bash
# bash 解释器 一定要在第一行 开头写,否则下面脚本不执行,开机启动不成功。 由于是 service服务,因此此脚本是 root 用户执行
/bin/nginx
/bin/php-fpm
# 可以后台启动: /bin/php-fpm ---------------------------------------------- 其他备份 忽略 ------------------------------------------------------## 重启服务器生效[root@wwweisccn ~]# cat /usr/lib/systemd/system/eisc-logdata.service[Unit]# 服务描述Description=eisc logdate# 在网络初始化之后启动After=network.target[Service]# 服务类型Type=forking# 类型1:oneshot:程序执行完成就自动结束了,没有后台进程,比如执行一个shell# 类型2:forking:需要一个后台守护进程一直在运行,比如运行nginx、apache、sshd# https://blog.csdn.net/seaship/article/details/108235858# 守护进程:http://www.gosanye.com/post/3755.html# 进程退出立即重启Restart=alwaysRestartSec=5# 服务每5秒重新启动一次StartLimitInterval=0# 工作目录WoringDirectory=/root/eisc# 启动命令ExecStart=/root/eisc/date.sh[Install]# 当系统以多用户方式启动时,这个服务需要被自动运行WantedBy=multi-user.target # 小绿叶技术博客 安防系统 cat /usr/lib/systemd/system/eisc-anfang.service[Unit]# 服务描述Description=eisc anfang# 在网络初始化之后启动#After=network.target remote-fs.target nss-lookup.targetAfter=auditd.service systemd-user-sessions.service time-sync.target[Service]#Type=forking# 保留一个守护进程,持续运行,会报错,不加这个参数。#PrivateTmp=true# 工作目录WoringDirectory=/eisc/anfang# 启动命令ExecStart=/eisc/anfang/ip.shRestartSec=30s# 重启服务, 无效,# 需要在脚本里面自己加 无限循环,保持运行生命[Install]# 当系统以多用户方式启动时,这个服务需要被自动运行WantedBy=multi-user.target#----------- 加入开机启动 ------#sudo systemctl enable eisc-anfang.service # 其他说明systemctl start eisc-logdata.service # 启动服务systemctl enable eisc-logdata.service # 加入开机启动systemctl disable eisc-logdata # 取消开机启动systemctl status eisc-logdata # 查看改服务的状态#--------------------------------- nginx 服务案例 --------------------------------------#[Unit]Description=The nginx HTTP and reverse proxy serverAfter=network-online.target remote-fs.target nss-lookup.targetWants=network-online.target[Service]Type=forkingPIDFile=/run/nginx.pid# Nginx will fail to start if /run/nginx.pid already exists but has the wrong# SELinux context. This might happen when running `nginx -t` from the cmdline.# https://bugzilla.redhat.com/show_bug.cgi?id=1268621ExecStartPre=/usr/bin/rm -f /run/nginx.pidExecStartPre=/usr/sbin/nginx -tExecStart=/usr/sbin/nginxExecReload=/usr/sbin/nginx -s reloadKillSignal=SIGQUITTimeoutStopSec=5KillMode=processPrivateTmp=true[Install]WantedBy=multi-user.target#-------------------------------------------------------------------------------------#开机启动服务编写进入目录 cd /etc/systemd/system/1:编写属于自己的unit文件,命令为mybash.service,整个文件如下这边以mybash开机运行为例:1.建立服务文件1、vim /lib/systemd/system/mybash.service文件内容如下:[Unit]Description=mybash# [dɪ ˈs k rɪ p ʃn] di s k lui p xin 服务的简单描述 After=network.target# 依赖,仅当依赖的服务启动之后再启动自定义的服务单元# Documentation : 服务文档[Service]Type=forking# Type : 启动类型simple、forking、oneshot、notify、dbus# Type=forking 以 fork 方式从父进程创建子进程,创建后父进程会立即退出ExecStart=/etc/nginx start# 启动当前服务的命令ExecReload=/etc/nginx restart# 重启当前服务的命令ExecStop=/etc/nginx stop# 停止服务PrivateTmp=true#ExecStart # 启动当前服务的命令#ExecStartPre # 启动当前服务之前执行的命令#ExecStartPost # 启动当前服务之后执行的命令#ExecReload # 重启当前服务时执行的命令#ExecStop # 停止当前服务时执行的命令#ExecStopPost # 停止当其服务之后执行的命令[Install]WantedBy=multi-user.target################################# 参考资料和说明 ###################################---------- [Unit] ----------## 配置文件的第一个区块Description # 简短描述Documentation # 文档地址Requires # 当前 Unit 依赖的其他 Unit,如果它们没有运行,当前 Unit 会启动失败Wants # 与当前 Unit 配合的其他 Unit,如果它们没有运行,当前 Unit 不会启动失败BindsTo # 与Requires类似,它指定的 Unit 如果退出,会导致当前 Unit 停止运行Before # 如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之后启动After # 如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之前启动Conflicts # 这里指定的 Unit 不能与当前 Unit 同时运行Condition... # 当前 Unit 运行必须满足的条件,否则不会运行Assert... # 当前 Unit 运行必须满足的条件,否则会报启动失败[Install]通常是配置文件的最后一个区块,用来定义如何启动,以及是否开机启动。它的主要字段如下。WantedBy:它的值是一个或多个 Target,当前 Unit 激活时(enable)符号链接会放入/etc/systemd/system目录下面以 Target 名 + .wants后缀构成的子目录中RequiredBy:它的值是一个或多个 Target,当前 Unit 激活时,符号链接会放入/etc/systemd/system目录下面以 Target 名 + .required后缀构成的子目录中Alias:当前 Unit 可用于启动的别名Also:当前 Unit 激活(enable)时,会被同时激活的其他 Unit[Service]区块用来 Service 的配置,只有 Service 类型的 Unit 才有这个区块。它的主要字段如下。Type:定义启动时的进程行为。它有以下几种值。Type=simple:默认值,执行ExecStart指定的命令,启动主进程Type=forking:以 fork 方式从父进程创建子进程,创建后父进程会立即退出Type=oneshot:一次性进程,Systemd 会等当前服务退出,再继续往下执行Type=dbus:当前服务通过D-Bus启动Type=notify:当前服务启动完毕,会通知Systemd,再继续往下执行Type=idle:若有其他任务执行完毕,当前服务才会运行ExecStart:启动当前服务的命令ExecStartPre:启动当前服务之前执行的命令ExecStartPost:启动当前服务之后执行的命令ExecReload:重启当前服务时执行的命令ExecStop:停止当前服务时执行的命令ExecStopPost:停止当其服务之后执行的命令RestartSec:自动重启当前服务间隔的秒数Restart:定义何种情况 Systemd 会自动重启当前服务,可能的值包括always(总是重启)、on-success、on-failure、on-abnormal、on-abort、on-watchdogTimeoutSec:定义 Systemd 停止当前服务之前等待的秒数Environment:指定环境变量# https://www.cnblogs.com/aaronLinux/p/6861425.html
printf(" \n %s \n",qlist);
// 由 popen 函数去执行 shell 命令获取虚拟机
// 读取函数: 1.内存块指针; 2.读取每个元素的大小,字节;3.元素个数; 指针文件或流
// pclose 关闭 和 打印
struct myIN dy[3]={
{"rv1126","工程编译主机"},{"win2012","办公windos桌面"},{"www","开发网站"}
// 结构体直接传值:数组dy 继承结构体 myIN ,有两个成员,数组两个元素对应成员
//---------- 结构体赋值 -----------#
struct myIN *csp;
csp = &dy;
printf(" csp 结构体取出 dy 数据,结构体赋值。 目前只打印第一个名字:%s \n ", csp[0].name );
// 结构体 -> 含义 重新赋值
// dy[1]->name = "0";
// 如果符号前是指针类型,那么用 -> 否则用 .
//------------------------
for(int i=0;i<3;i++){
printf("列出主机名称: %s 说明: %s\n", dy[i].name,dy[i].suzhi );
// dy[i]->name 表示:i 是数数数组角标,结构体数组 第一组成员 中的name 的值
printf("\n \n您需要控制主机:%s 状态为:%s \n 格式:virsh start/shutdown www \n", qname, qstatus);
memcpy(temp64,"virsh ",10);
strcat(temp64,qstatus);
strcat(temp64,qname);
printf("\n 复制字符串的结果为:%s \n",temp64);
system(temp64);
qemu_img()
char qcow2[99] = {0};
char status[99] = {0};
char qemuml[]={"qemu-img snapshot -"};
FILE *fp=NULL;
char qlist[999];
printf("\n \n #----------- 镜像快照管理 ------------# \n \
请输入管理方式 和镜像 : l 查看 a 恢复 c 创建 d 删除 , 案例: l www.qcow2 \n");
printf("请输入两个参数,用空格隔开: ");
scanf("%s %s", status , qcow2 ); // scanf 方式获取键盘输入
printf("控制状态: %s 主机名称:%s 镜像字符长度: %d \n",status,qcow2 );
// scanf 中的 %s 不能有逗号,否则无法接收完全
strcat(qemuml,status);
memcpy(qcow2,qemuml,strlen(qemuml));
printf("操作的快照指令为:%s \n", qemuml);
// memcpy 替换复制到字符串前面,但是 本身字符被替换
fp=popen(qemuml,"r");
fread(qlist, 999,1,fp );
pclose(fp);
printf(" \n 查看当前镜像下的快照:\n %s \n",qlist);
// 定义变量 a b c d 为:数组第 1234 个元素的值
printf("输入的第一个参数a : %s\n 输入的第二个参数b : %s \n 第三个参数: %s \n" ,a,b,c);
char qstatus[20];
char qname[20];
memset(qname,' ',2);
memset(qstatus,' ',2);
strcat(qstatus,b);
strcat(qname,c);
printf("传递两个参数: qname: %s ; qstatus: %s \n \n", qname,qstatus);
kvmlist(qstatus,qname);
qemu_img();
return 0;
fwrite(c, strlen(c) + 1, 1, fp);
// write [ raɪ t ] 写;定义写入规则, 将数组 c 中的内容写入到 fp 文件中
// 第1个:被写入的内容;2.写入的元素大小:strlen 计算字符串长度;3.元素个数; 4.指针文件
printf("字符串长度 %d\n", strlen(c)+1);
// strlen 计算变量字符串的长度 再 +1
fseek(fp, 0, SEEK_SET);
// 写入文件的位置:1.指针文件,2.偏移字节量(0 不偏移),3. 开始偏移写入位置:SEEK_SET 文件开头,SEEK_CUR 指针当前位置, SEEK_END 文件末尾
fread(dp, strlen(c)+1, 1, fp);
// 读取函数: 1.内存块指针; 2.读取每个元素的大小,字节;3.元素个数; 指针文件
printf(" 再次读取文件查看内容: %s\n", dp);
fclose(fp);
// 关闭文件指针
return(0);
while (fgets(buf, BUF_SIZE, p) != NULL) {
// fgets 读取并存储: 1.储存到数组 buf; 2.读取最大字符数 1024 字; 3.对象指针字符流
fprintf(stdout, "%s", buf);
// 打印:发送格式化输出流到 stdout
pclose(p);
// 关闭文件指针
return 0;
int timehs ()
time_t curtime;
time(&curtime);
printf("当前时间 = %s", ctime(&curtime));
return(0);
// 结构体数组指针
void zhizhenjiegou ()
struct jiegou
// 定义结构体名 jg; 成员: sum ,name长度20 ,sex, score 相似于数据库建表
int num;
char name[20];
char sex;
int age;
struct jiegou stu[3] = {{10101, "Li Lin", 'M', 18},
{10102, "Zhang Fun", 'M', 19},
{10103, "Wang Min", 'F', 20}};
// 定义结构体 jg 的数组变量 stu 简称:结构体变量 ; 类似于数据库 jg 中的表 stu
// 结构体变量 stu 有三组数据,相似于数据库表有三个人的学号,名字等等
struct jiegou *p;
// 定义指针p为:结构体(数据库); 三个等价 stu.num 和 (*p).num 和 p->num
// p = &stu; 这个是读取内存地址,符号 &
printf("No. name sex age\n");
for(p=stu; pnum, p->name, p->sex, p->age);
// %-12s 左对齐输出字符串, %-2c 左对其输出单个字符
// c 结构体:https://www.runoob.com/w3cnote/c-structures-intro.html
void main()
// 定义任意类型 main 函数
shuzu();
// 执行数组函数
char a[]="开始执行 zhizhen 写入文件函数,前提需要创建 file.txt";
printf(" 字符数组赋值中文 格式 a[] \n %s", a);
zhizhen();
// 执行指针函数
popencs();
timehs();
zhizhenjiegou();
#!/bin/bash
# ubuntu20 shell 脚本自动编译web安装网站环境 nginx199 php7/8 mariadb1011 以 systemd 方式设置开机启动
# mysql 重置 root 密码,创建 或删除 mysql 子库和子用户
downdir="/datadisk/eisc/download" ; sudo mkdir -p $downdir ; sudo chmod 777 -R $downdir
installdir="/datadisk/eisc/server" ; sudo mkdir -p $installdir
# 安装路径不能将所有目录都为 777 , 如: mysql 的 /etc/my.cnf 不能为 777 否则mysql 无法启动
www="/datadisk/eisc/www"
wwwconf="/datadisk/eisc/www/wwwconf"
# 设置web 网站路径 和 nginx conf 子站点路径
echo "
欢迎使用自动安装 网站web 环境shell 脚本, nginx199 php-fpm mariadb10.11
当前需要更新 apt upgrade , 如果遇到弹窗选择包,请回车跳过。不要按 Esc 退出. 建议选择 ubuntu20.04
安装完成重启服务器后,启动web服务命令: sudo nginx199 ; sudo php-fpm743 ; sudo /etc/init.d/mariadb1011 restart
数据库默认登陆: mysql -u root -peisc.cn
server 源码下载路径:$downdir
server 安装路径:$installdir
www 网站路径:$www
www nginx conf 子站点路径:$wwwconf
C 2022.12.04 小绿叶技术博客 eisc.cn
sleep 3;
if [ ! -e /etc/init.d/mariadb1011 ]
sudo apt update ; sudo apt upgrade -y
down_guanfang_url(){
downNginxUrl="http://nginx.org/download/nginx-1.9.9.tar.gz"
downPHPurl="https://www.php.net/distributions"
downMariadbUrl="https://archive.mariadb.org//mariadb-10.11.0/bintar-linux-systemd-x86_64/mariadb-10.11.0-linux-systemd-x86_64.tar.gz"
# 手动下载数据库:https://mariadb.org/download/
downcgiccURL="http://ftp.gnu.org/gnu/cgicc/cgicc-3.2.19.tar.gz"
down_eisc_url(){
url="http://work.eisc.cn/ruanjian"
downNginxUrl="$url/ubuntu/server/nginx-1.9.9.tar.gz"
downPHPurl="$url/ubuntu/server/php"
downMariadbUrl="$url/ubuntu/server/mariadb-10.11.0-linux-systemd-x86_64.tar.gz"
downcgiccURL="$url/ubuntu/server/cgicc-3.2.19.tar.gz"
down_select(){
read -p "选择下载安装包地址: 1 官方下载 2 小绿叶技术博客下载. 请输入: " selectURL
case $selectURL in
"1") echo "当前选择官方下载..." ; down_guanfang_url ;;
"2") echo "当前选择小绿叶技术博客下载..." ; down_eisc_url ;;
*) echo "输入错误,请重新执行脚本! " ; exit ;;
echo $downNginxUrl
echo $downPHPurl
echo $downMariadbUrl
down_select
nginx_install(){
cd $downdir
if [ ! -e /bin/nginx199 ]
echo "开始安装nginx 1.9.9"
sudo apt install -y build-essential libtool \
libpcre3 libpcre3-dev \
zlib1g-dev openssl libgd-dev \
geoip-database libgeoip-dev
# 安装gcc c++ ; pcre ; zlib ssl GD ; GeoIP 依赖库
if [ ! -e $downdir/nginx-1.9.9.tar.gz ]
wget $downNginxUrl
if [ ! -e $downdir/nginx-1.9.9/configure ]
tar -xzvf nginx-1.9.9.tar.gz
cd nginx-1.9.9
sudo mkdir -p $installdir/nginx/nginx1.9.9 ; sudo chmod 777 -R mkdir -p $installdir/nginx/nginx1.9.9
./configure --prefix=$installdir/nginx/nginx1.9.9
sed -i "s/-Werror/ /g" objs/Makefile
NR=`cat -n ./src/os/unix/ngx_user.c | grep cd.current_salt | awk -F" " '{print $1}'`
sed -i "$NR d" ./src/os/unix/ngx_user.c
sudo make && sudo make install
sudo ln -s $installdir/nginx/nginx1.9.9/sbin/nginx /bin/nginx199
sudo killall nginx199 ; sudo nginx199
# 重新启动nginx
sudo nginx199 ; nginx199 -V
echo "[ok]nginx 1.9.9 已经安装"
php_aptupdate(){
sudo apt install -y gcc make openssl curl libssl-dev libxml2-dev libzip-dev libcurl4-openssl-dev \
libpng-dev libjpeg-dev libwebp-dev libonig-dev libsqlite3-dev libsodium-dev libargon2-dev \
libkrb5-dev libbz2-dev libxslt-dev php-mbstring \
build-essential libtool libpcre3 libpcre3-dev zlib1g-dev libgd-dev geoip-database libgeoip-dev
# 安装包: No package 'krb5-gssapi' found ; Please reinstall the BZip2 distribution ; No package 'libxslt' found
# 报错解决参考:http://t.zoukankan.com/architectforest-p-15714248.html
sudo groupadd www ; sudo useradd -g www www -s /bin/false
# sudo groupadd www-data ; sudo useradd -g www-data www-data -s /bin/false
# 重建用户,并且不允许用户登陆系统
echo "
linux nginx + php-fpm 安装参考:
https://www.php.net/manual/zh/install.unix.nginx.php
php_release721(){
phpreleaseMl="php-7.2.1"
phpreleaseInstall="php721"
phpreleaseBin="php-fpm721"
downPHPurl="$downPHPurl/$phpreleaseMl.tar.gz"
echo "php 下载地址重新定义为:$downPHPurl"
php_release7433(){
phpreleaseMl="php-7.4.33"
phpreleaseInstall="php743"
phpreleaseBin="php-fpm743"
downPHPurl="$downPHPurl/$phpreleaseMl.tar.gz"
echo "php 下载地址重新定义为:$downPHPurl"
php_release811(){
phpreleaseMl="php-8.1.13"
phpreleaseInstall="php811"
phpreleaseBin="php-fpm811"
downPHPurl="$downPHPurl/$phpreleaseMl.tar.gz"
echo "php 下载地址重新定义为:$downPHPurl"
php_install(){
cd $downdir
if [ ! -e /bin/$phpreleaseBin ]
echo "开始安装 $phpreleaseInstall "
php_aptupdate
if [ ! -e $downdir/$phpreleaseMl.tar.gz ]
wget $downPHPurl
if [ ! -e $downdir/$phpreleasedown/configure ]
tar -xzvf $phpreleaseMl.tar.gz
cd $phpreleaseMl
sudo mkdir -p $installdir/php/$phpreleaseInstall ; sudo chmod 777 -R $installdir/php/$phpreleaseInstall
./configure --prefix=$installdir/php/$phpreleaseInstall --with-config-file-path=$installdir/php/$phpreleaseInstall/etc \
--enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-iconv-dir --with-freetype --with-jpeg --with-zlib \
--enable-zip \
--with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl \
--enable-ftp --enable-gd --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-webp
# --with-openssl
# 第一行 指定安装路径,和 php.ini 路径为 $installdir/php/php72/etc
# 第二行 开启php 的 php-fpm web功能。启动用户名和组 和 重要 开启php 的mysql connect() 函数 功能。
# 第三行 压缩解码工具 否则 php WordPress 无法无法正常启动 报错: is not a valid libtool object
# 后面行,暂时没有研究. --with-openssl ubuntu22 编译不过
sudo make ; sudo make install
#----------------------- 说明 -------------------#
# 安装说明:https://www.php.net/manual/zh/install.php
#--with-fpm-user - 设置 FPM 运行的用户身份(默认 - nobody)。
#--with-fpm-group - 设置 FPM 运行时的用户组(默认 - nobody)。
#--with-fpm-systemd - 启用 systemd 集成 (默认 - no)。
#--with-fpm-acl - 使用 POSIX 访问控制列表 (默认 - no)。
#--with-fpm-apparmor - 激活 AppArmor 集成 (默认 - no)。
#--with-fpm-selinux - 激活 SELinux 集成(默认 - no)。
#---------------------- php config ---------------#
sudo cp $downdir/$phpreleaseMl/sapi/fpm/php-fpm.service.in /etc/systemd/system/php-fpm.service
sudo cp $downdir/$phpreleaseMl/php.ini-development $installdir/php/$phpreleaseInstall/etc/php.ini
sudo cp $installdir/php/$phpreleaseInstall/etc/php-fpm.conf.default $installdir/php/$phpreleaseInstall/etc/php-fpm.conf
sudo cp $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf.default $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf
#---------- 更改用户
NR=`cat -n $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf | grep -w user | grep nobody | awk -F" " '{print $1}'`
sudo sed -i "$NR s/nobody/www/g" $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf
NR=`cat -n $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf | grep -w group | grep -v listen | grep nobody | awk -F" " '{print $1}'`
sudo sed -i "$NR s/nobody/www/g" $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf
NR=`cat -n /etc/systemd/system/php-fpm.service | grep ProtectSystem | awk -F" " '{print $1}'`
sudo sed -i "$NR s/full/false/g" /etc/systemd/system/php-fpm.service
#---------- 解决 No input file specified
NR=`cat -n $installdir/php/$phpreleaseInstall/etc/php.ini | grep fix_pathinfo | grep -v provides| awk -F" " '{print $1}'`
sudo sed -i "$NR a cgi.fix_pathinfo=1" $installdir/php/$phpreleaseInstall/etc/php.ini
sudo sed -i "$NR d" $installdir/php/$phpreleaseInstall/etc/php.ini
NR=`cat -n $installdir/php/$phpreleaseInstall/etc/php.ini | grep force_redirect | grep 1| awk -F" " '{print $1}'`
sudo sed -i "$NR a cgi.force_redirect=0" $installdir/php/$phpreleaseInstall/etc/php.ini
sudo sed -i "$NR d" $installdir/php/$phpreleaseInstall/etc/php.ini
#-----------
NR=`cat -n $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf | grep "127.0.0.1:9000" | awk -F" " '{print $1}'`
# sudo sed -i "$NR a listen = /var/run/$phpreleaseBin.sock" $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf
sudo sed -i "$NR a listen = 127.0.0.1:9000" $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf
sudo sed -i "$NR d" $installdir/php/$phpreleaseInstall/etc/php-fpm.d/www.conf
sudo cp $installdir/php/$phpreleaseInstall/sbin/php-fpm /bin/$phpreleaseBin
sudo sudo chmod +x /bin/$phpreleaseBin ; sudo $phpreleaseBin
# 重载配置,并且启动php
echo "php 安装完成,启动与停止php : sudo killall $phpreleaseBin ; sudo sudo chmod +x /bin/$phpreleaseBin ; sudo $phpreleaseBin "
#sudo sed -i "778 s/;//g" /etc/php/7.4/fpm/php.ini
#sudo sed -i "778 s/1/0/g" /etc/php/7.4/fpm/php.ini
#sudo sed -i "798 s/;//g" /etc/php/7.4/fpm/php.ini
# 解决 No input file specified
echo "php 已经安装"
php_select(){
echo "请输入您要安装php 的版本: 提供版本: 1. php7.2.1 2. php7.4.33 3. php8.1.13 任意按键取消安装php 并且往下执行... "
read -p "请输入版本编号:" selectxh
case $selectxh in
"1") echo "当前选择php版本 $phpreleaseMl 启动文件为: /bin/$phpreleaseBin " ; php_release721 ; php_install ;;
"2") echo "当前选择php版本 $phpreleaseMl 启动文件为: /bin/$phpreleaseBin " ; php_release7433 ; php_install ;;
"3") echo "当前选择php版本 $phpreleaseMl 启动文件为: /bin/$phpreleaseBin " ; php_release811 ; php_install ;;
*) echo "[ok]退出安装 php "
nginx_web_config(){
sudo mkdir -p $wwwconf $www ; sudo chmod 777 -R $www
setconf=`cat $installdir/nginx/nginx1.9.9/conf/nginx.conf | grep "$wwwconf" `
if [ ${#setconf} -gt 10 ]
echo "[ok]nginx 已经配置, 子站点目录: $wwwconf/www.conf"
NR=`cat -n $installdir/nginx/nginx1.9.9/conf/nginx.conf | grep http | grep "{" | awk -F" " '{print $1}'`
sudo sed -i "$NR a include $wwwconf/*.conf; " $installdir/nginx/nginx1.9.9/conf/nginx.conf
echo "" > $www/www/p.php
sudo nginx199 -s stop ; sudo nginx199
# 修改php 后重新启动nginx
create_www_conf(){
echo "案例: eisc.cn 114.114.114.114 62000"
read -p " 请输入三个参数:" peizhi
buff=( $peizhi )
yuming=${buff[0]}
# 前端域名,增加到nginx 消息头部
ip=${buff[1]}
# 后端服务器ip
portmin=${buff[2]}
portmin=$[portmin-1]
# 设置最小端口,后面网站按照顺序自动加1
declare -A port
port["www"]="62010"
port["work"]="62011"
port["sou"]="62012"
port["enchantment"]="62013"
port["guzheng"]="62014"
port["zhoubao"]="62015"
port["xibin"]="62100"
cd $wwwconf; sudo chmod 777 -R $wwwconf $wwwconf/*
if [ ! -e eiscwwwconf.tar.gz ]
sudo tar -czvf eiscwwwconf.tar.gz *
sudo rm -rf `ls | grep -v eiscwwwconf.tar.gz`
sudo rm -rf `ls | grep -v eiscwwwconf.tar.gz`
file=(`ls $www | grep -vE "ssl|wwwconf|wwwroot|*.sh"`)
for i in ${file[*]}
((a++))
b=$[portmin+a] ; portlist[$c]=$b ; ((c++))
# 打印一次变量,接收一个元素存入数组: portlist
if [ ! -e $www/$i/cgi-bin ]
sudo mkdir $www/$i/cgi-bin
case $i in
"www") b=${port[www]} ; echo "#------- www 被手动指定固定端口 $b -------#" ;;
"work") b=${port[work]} ; echo "#------- work 被手动指定固定端口 $b -------#" ;;
"sou") b=${port[sou]} ; echo "#------- sou 被手动指定固定端口 $b -------#";;
"enchantment") b=${port[enchantment]} ; echo "#------- enchantment 被手动指定固定端口 $b -------#";;
"guzheng") b=${port[guzheng]} ; echo "#------- guzheng 被手动指定固定端口 $b -------#";;
"zhoubao") b=${port[zhoubao]} ; echo "#------- zhoubao 被手动指定固定端口 $b -------#";;
"xibin") b=${port[xibin]} ; echo "#------- xibin 被手动指定固定端口 $b -------#";;
echo " $i 创建web网站 的端口: $b 前端域名 + $i.$yuming + 后端ip port + $ip:$b + c++ cgi 解析目录: $i/cgi-bin"
echo " $i 创建web网站 的端口: $b 前端域名 + $i.$yuming + 后端ip port + $ip:$b + c++ cgi 解析目录: $i/cgi-bin" >> log_www_conf.txt
#--------- 生成前端转发 子站点文件 -----------#
sudo mkdir -p $wwwconf/nginxzhuanfa ; sudo chmod 777 $wwwconf/nginxzhuanfa
echo "
server{
listen 80;
server_name $i.$yuming;
location / {
proxy_pass http://$ip:$b;
" > $wwwconf/nginxzhuanfa/$i-$b.conf
if [ "$i" = "www" ]
echo "
server{
listen 80;
server_name $i.$yuming $yuming;
location / {
proxy_pass http://$ip:$b;
" > $wwwconf/nginxzhuanfa/$i-$b.conf
#---------- 后端转发子站点 ----------#
echo "
server {
listen $b;
root $www/$i;
index index.php index.html index.htm index;
add_header 'yuming is ' '$i.$yuming';
add_header 'ipport is ' '$ip:$b';
location ~ \.php {
# fastcgi_pass unix:/var/run/php-fpm811.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
location /cgi-bin {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include fastcgi.conf;
" > $wwwconf/$b.$i.conf
echo "[ok]创建网站日志存放在: $wwwconf/log_www_conf.txt"
echo "[ok]前端转发 nginx 子文件目录: $wwwconf/nginxzhuanfa"
sudo nginx199 -s reload
cgi_install_config(){
cd $downdir
dir="$installdir/aspnet" ; sudo mkdir -p $dir; sudo chmod 777 -R $dir ;
mkdir -p $dir/conf $dir/www/www
sudo apt install -y build-essential libfcgi-dev autoconf libtool automake libtool spawn-fcgi fcgiwrap
cgiport=10000
psnet=`sudo netstat -ntlp | grep -w $cgiport `
if [ ${#psnet} -lt 1 ]
spawn-fcgi -f /usr/sbin/fcgiwrap -a 127.0.0.1 -p $cgiport -F 32 -P /tmp/fastcgi-c.pid -u nobody -g nobody
echo "[ok]访问: 127.0.0.1/p.php 查看 效果, 子站点目录:$wwwconf/www.conf "
#--- 安装cgicc web模块 ---#
if [ ! -e cgicc-3.2.19.tar.gz ]
wget $downcgiccURL
if [ ! -e $installdir/cgicc/bin/cgicc-config ]
sudo tar -xzvf cgicc-3.2.19.tar.gz ; cd cgicc-3.2.19
./configure --prefix=/usr
sudo make ; sudo make install
sudo cp /usr/lib/libcgicc.* /usr/lib64/
# g++ -o get get.cpp -lcgicc
# 使用 cgicc 编译c++ 方法: g++ 编译c++ 程序; gcc 编译c语言; -o 生成可执行文件 get 被编译的文件:get.cpp 指定库 cgicc
nginx_config_if(){
echo "
#----------- 配置子站点nginx ------------#
请输入 前端转发服务器域名,后端服务器公网ip 和 第一个网站端口。有多个网站,端口自动计数加1 。
如果没有域名 和前端服务器,随意输入三个参数,但端口一定为 65536 以内。脚本可以重复执行,重新配置
read -p "是否进行配置: y 需要配置, 任意按键并回车跳过, 请输入: " ifa
if [ "$ifa" = "y" ]
echo "正在进行配置 子站点..."
create_www_conf ; cgi_install_config
# 配置子站点
echo "[ok]已经跳过nginx配置子站点!"
mariadb_install(){
cd $downdir
if [ ! -e /etc/init.d/mariadb1011 ]
echo "开始安装 mariadb-10.11"
sudo apt install -y libncurses5
sudo groupadd mysql ; sudo useradd -g mysql mysql -s /bin/false
# 创建mysql用户组和用户,不允许登陆系统
if [ ! -e $downdir/mariadb-10.11.0-linux-systemd-x86_64.tar.gz ]
wget $downMariadbUrl
if [ ! -e $installdir/mysql/mariadb1011/README.md ]
sudo mkdir -p $installdir/mysql ; sudo chmod 777 -R $installdir/mysql
sudo tar -xzvf mariadb-10.11.0-linux-systemd-x86_64.tar.gz -C $installdir/mysql/
sudo mv $installdir/mysql/mariadb-10.11.0-linux-systemd-x86_64 $installdir/mysql/mariadb1011
# sudo chown -R mysql mariadb-10.11 ; cd mariadb-10.11
# 更改文件属性为mysql组,mysql 用户
cd $installdir/mysql/mariadb1011
sudo mkdir -p $installdir/sqldata ; sudo chmod 777 -R $installdir/sqldata
sudo chown -R mysql:mysql $installdir/sqldata ; sudo chmod 777 -R $installdir/sqldata
sudo $installdir/mysql/mariadb1011/scripts/mysql_install_db --user=mysql --basedir=$installdir/mysql/mariadb1011 --datadir=$installdir/sqldata
# 初始化mariadb
sudo cp $installdir/mysql/mariadb1011/support-files/wsrep.cnf /etc/my.cnf
sudo chmod 777 /etc/my.cnf
echo "
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
#添加以下配置
basedir=$installdir/mysql/mariadb1011
datadir=$installdir/sqldata
" > /etc/my.cnf
sudo chmod 644 /etc/my.cnf
# my.cnf 权限为 777 不安全,所以mysql无法启动。
sudo cp $installdir/mysql/mariadb1011/support-files/mysql.server /etc/init.d/mysql
sudo cp $installdir/mysql/mariadb1011/bin/mysqld /etc/init.d/mysqld
sudo ln -s $installdir/mysql/mariadb1011/support-files/mysql.server /etc/init.d/mariadb1011
sudo chmod +x /etc/init.d/mysqld
sudo chmod 777 /etc/profile
echo "
#MARIADB
export MARIADB_HOME=$installdir/mysql/mariadb1011
export PATH=$PATH:${MARIADB_HOME}/bin
" >> /etc/profile
# 设置环境变量,等于:添加执行文件的路径。 先定义 MARIADB_HOME 变量的路径,再引用
sudo chmod 644 /etc/profile
source /etc/profile ; bash
#---------- 重置 mysql root 密码也是该流程 ---------#
sudo killall mariadbd mysqld_safe
runmysql=`sudo netstat -nltp | grep 3306 | grep -w tcp | grep mariadb`
if [ ${#runmysql} -lt 1 ]
sudo /etc/init.d/mariadb1011 start
# 重新启动mysql 服务, mysql 启动时候才能进行 mysqladmin 命令 重置密码
sleep 1;
sudo $installdir/mysql/mariadb1011/bin/mysqladmin -u root password eisc.cn
echo "数据库root 密码为: eisc.cn 使用命令更改密码: "
echo "sudo $installdir/mysql/mariadb1011/bin/mysqladmin -u root password eisc.cn"
sudo mkdir -p $installdir/back/sql/ ; sudo chmod 777 $installdir/back/sql/
echo "[ok] mariadb1011 已经安装"
mysql_data(){
#------ 修改mysql data 数据目录 -----#
sudo chmod 777 /eisc/
mkdir /eisc/data/
sudo chown -R mysql:mysql /eisc/data/
sudo chmod 777 /usr/local/mariadb-10.9.2/data/
sudo cp -r /usr/local/mariadb-10.9.2/data/* /eisc/data/
sudo /usr/local/mariadb-10.9.2/support-files/mysql.server stop
sudo /usr/local/mariadb-10.9.2/support-files/mysql.server start
mysql_database(){
#!/bin/bash
# shell 自动创建数据库 用户和密码
sudo apt install libncurses*
# 解决mysql 命令报错,缺少库:Couldn't find any package by glob 'libncurses.so.5'
sudo apt install mysql-client -y
# 安装连接数据库工具
sudo mkdir /var/run/mysqld/
sudo ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock
# 解决 mysql 报错,无法进入mysql 。 mariadb 的启动sock 不一样
runmysql=`sudo netstat -nltp | grep 3306 | grep -w tcp | grep mariadb`
if [ ${#runmysql} -lt 1 ]
sudo /etc/init.d/mariadb1011 start
sudo $installdir/mysql/mariadb1011/bin/mysqladmin -u root password eisc.cn
# 启动数据库,重置数据库 root 用户密码为: eisc.cn
echo "#---------------- 数据库管理工具 ------------#
参考输入案例: create eisc.cn www www 000000 localhost
1 创建 or 删除,输入: create 或 drop
2 数据库 root 用户密码
3 子数据库名
4 子库用户名
5 子库密码
6 开放数据库方式:本地/远程 输入: localhost 或 %
用空格隔开,必须按照顺序输入6个参数!"
read -p "请输入:" in_buff
buff=( abcd $in_buff);
echo "你输入的信息为: ${buff[*]}";
case ${buff[1]} in
"create")
# mysql -uroot -p${buff[2]} -e "create database ${buff[3]} character set utf8 collate utf8_bin;"
mysql -uroot -p${buff[2]} -e "create database ${buff[3]} character set utf8;"
mysql -uroot -p${buff[2]} -e "grant all on ${buff[4]}.* to '${buff[4]}'@'${buff[6]}' identified by '${buff[5]}'"
mysql -uroot -p${buff[2]} -e "show databases;SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS ListUsername FROM mysql.user where User='${buff[4]}';"
"drop")
mysql -uroot -p${buff[2]} -e "drop database ${buff[3]}"
mysql -uroot -p${buff[2]} -e "drop user '${buff[4]}'@'${buff[6]}'"
mysql -uroot -p${buff[2]} -e "show databases;SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS ListUsername FROM mysql.user where User='${buff[4]}';"
mysql_contor(){
runmysql=`sudo netstat -nltp | grep 3306 | grep -w tcp | grep mariadb`
if [ ${#runmysql} -lt 1 ]
sudo /etc/init.d/mariadb1011 start
# 启动数据库
echo "#---- 数据库 root 密码始终被重置为 eisc.cn ----#
如果需要手动重置为自己想要的密码,命令行手动执行命令:
sudo $installdir/mysql/mariadb1011/bin/mysqladmin -u root password eisc.cn
将 eisc.cn 改为自己的密码
read -p "是否进行数据库管理工作,创建数据库和用户,输入: y/n ? " ins
if [ "$ins" = "y" ]
echo "开始管理数据库 ..."
mysql_database
echo "[ok]退出数据库管理!"
kaiji_web_service(){
# ubuntu 以 systemd 服务方式,自动启动服务软件
systemdDir="/usr/lib/systemd/system"
webname="eisc_web_start.service"
cd $systemdDir ; sudo touch $webname ; sudo chmod 777 $webname
#----- 写入 start.service 服务 -----#
echo "
[Unit]
Description=start web
[Service]
Type=forking
ExecStart=$installdir/shell/start.sh
ExecReload=/bin/kill -SIGHUP \$MAINPID
ExecStop=/bin/kill -SIGINT \$MAINPID
[Install]
WantedBy=multi-user.target
" > $webname
sudo apt install dos2unix -y
sudo dos2unix $webname
# 转为 unix 格式,否则可能出现字符乱码
sudo chmod 644 $webname
sudo systemctl daemon-reload
sudo systemctl disable $webname
sudo systemctl enable $webname
kaiji_start_web_sh(){
read -p "是否继续进行配置 systemd 开机启动? y/n: " kaijisz
if [ "$kaijisz" = "y" ]
kaiji_web_service
# 启动这个函数
sudo mkdir -p $installdir/shell ; sudo chmod 777 -R $installdir/shell
# 将脚本授权给 root 用户
echo "#!/bin/bash
# bash 解释器 一定要在第一行 开头写,否则下面脚本不执行,开机启动不成功。 由于是 service服务,因此此脚本是 root 用户执行
$installdir/nginx/nginx1.9.9/sbin/nginx &
$installdir/php/php743/sbin/php-fpm &
/etc/init.d/mariadb1011 start &
/bin/spawn-fcgi -f /usr/sbin/fcgiwrap -a 127.0.0.1 -p 10000 -F 32 -P /tmp/fastcgi-c.pid &
touch \$HOME/log_start_web.txt ; chmod 777 \$HOME/log_start_web.txt
echo \"服务已经自动自动,时间 \`date \`\" > \$HOME/log_start_web.txt
" > $installdir/shell/start.sh
echo "#----------------- 查看写入的开机启动脚本 -------------------#"
cat $installdir/shell/start.sh
sudo chmod +x $installdir/shell/start.sh $installdir/nginx/nginx1.9.9/sbin/nginx $installdir/php/php743/sbin/php-fpm
sudo chown root:root $installdir/shell/start.sh ; sudo chmod 777 $installdir/shell/start.sh
echo "[ok]目前不配置systemd "
main(){
php_select
nginx_install
nginx_web_config
nginx_config_if
# 包含创建 www 子站点 和 c++ cgi
mariadb_install
# 数据库初始化 ,会中断退出脚本,所以放到最后安装
mysql_contor
kaiji_start_web_sh
# ubuntu20/21/22 一键部署 web 环境: wget eisc.cn/file/ubuntu/shell/server/web.sh ; chmod +x web.sh ; ./web.sh
#!/bin/bash
# ubuntu 22/21/20/18/16/14 自动切换 apt 阿里云/清华/腾讯/华为/网易163 源; update 更新,自动部署可 kvm 虚拟化,安装google 浏览器;安装 mp4 播放器
# 执行脚本选择对应的 apt 源码,下面 aptubuntu22 为apt 源 内容修改写入到:/etc/apt/sources.list 然后执行 sudo apt update 进行更新
echo "当前需要输入当前用户的密码,需要执行 sudo 命令" ; sudo date
aptupdateqinghua(){
# 清华 apt 源手动选择 ubuntu 版本链接:http://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
# 注意:定义变量的时候引号需要换行,否则原本的换行将被替换为空格
aptubuntu23="
# ubuntu23
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-security main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-proposed main restricted universe multiverse
aptubuntu22="
# ubuntu22
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
aptubuntu21="
# ubuntu21
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish-updates main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish-backports main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish-security main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish-proposed main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ impish-proposed main restricted universe multiverse
aptubuntu20="
# ubuntu20
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
aptubuntu18="
# ubuntu18
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
aptubuntu16="
# ubuntu16
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
aptubuntu14="
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse
ubuntu_ntpdate(){
# 更新时间
sudo apt install ntpdate -y
sudo timedatectl set-timezone Asia/Shanghai
sudo ntpdate -u cn.pool.ntp.org
sudo apt-get --fix-broken install -y
# 问题:Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution)
ubuntu_release_setApt(){
releaseApt=0;
models=`cat /etc/os-release | grep -w NAME | awk -F"\"" '{print $2}'`
version=`cat /etc/os-release | grep VERSION_ID | awk -F"\"" '{print $2}' | awk -F"." '{print $1}'`
echo "当前机型为:$models 系统版本: $version "
echo "select apt update: 1.qinghua 2.Alibaba 3.tencent 4.huawei 5.163 5.exit" ; read -p "select number : " readset
case $readset in
"1") echo "当前切换到清华源,较慢" ; aptupdateqinghua ;;
"2") echo "当前切换到阿里云源" ; aptupdateqinghua ; releaseApt=1 ; destAptUrl="mirrors.aliyun.com" ;;
"3") echo "当前切换到腾讯云源" ; aptupdateqinghua ; releaseApt=1 ; destAptUrl="mirrors.tencent.com" ;;
"4") echo "当前切换到华为云源" ; aptupdateqinghua ; releaseApt=1 ; destAptUrl="repo.huaweicloud.com" ;;
"5") echo "当前切换到网易163源" ; aptupdateqinghua ; releaseApt=1 ; destAptUrl="mirrors.163.com" ;;
*) echo "我已经配置 apt 源。正在继续下面任务... " ;;
case $version in
"23") echo "$aptubuntu23" > /etc/apt/sources.list ; echo "当前机型: $models $version 已经写入 aptubuntu22 apt源 " ;;
"22") echo "$aptubuntu22" > /etc/apt/sources.list ; echo "当前机型: $models $version 已经写入 aptubuntu22 apt源 " ;;
"21") echo "$aptubuntu21" > /etc/apt/sources.list ; echo "当前机型: $models $version 已经写入 aptubuntu21 apt源 " ;;
"20") echo "$aptubuntu20" > /etc/apt/sources.list ; echo "当前机型: $models $version 已经写入 aptubuntu20 apt源 " ;;
"18") echo "$aptubuntu18" > /etc/apt/sources.list ; echo "当前机型: $models $version 已经写入 aptubuntu18 apt源 " ;;
"16") echo "$aptubuntu16" > /etc/apt/sources.list ; echo "当前机型: $models $version 已经写入 aptubuntu16 apt源 " ;;
"14") echo "$aptubuntu14" > /etc/apt/sources.list ; echo "当前机型: $models $version 已经写入 aptubuntu14 apt源 " ;;
if [ $releaseApt = 1 ]
sudo sed -i "s/mirrors.tuna.tsinghua.edu.cn/$destAptUrl/g" /etc/apt/sources.list
sudo_install(){
if [ `id -un` != "root" ]
echo "当前不是 root 用户,需要检测 sudo 工具是否安装,并且 获取 sudo "
a=`sudo apt list --installed | grep sudo | grep now`
if [ ${#a} -lt 1 ]
echo " 当前检测到 您没有安装 sudo 超级权限工具,并且当前也不是 root 用户,没有权限更改apt 源,请切换到root 用户执行本shell 按照操作添加用户的sudo 权限"
echo "[ ok ] 当前用户 $USER 已经安装 sudo 工具,并且已经配置获得 sudo 超级权限,继续往下配置..."
sudo touch /etc/apt/sources.list
sudo chmod 777 -R /etc/apt/*
if [ ! -e /etc/apt/sources.list.bak ]
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
echo "备份文件 在: /etc/apt/sources.list.bak"
echo "已经存在备份文件:/etc/apt/sources.list.bak"
echo "" > /etc/apt/sources.list ; ubuntu_release_setApt
# 文件已经附加了权限,删除后文件权限为默认,而不为 777 。如果删除重写,记得重新附加权限 777
sudo rm -rf /var/lib/dpkg/updates/*
# 解决 sudo dpkg --configure -a # to correct the problem
ubuntu_ntpdate
sudo apt update ; sudo apt update ; sudo apt upgrade -y ; sudo apt list --upgradable
echo "切换 apt update 源,更新软件包,和 查看可升级软件包完成"
echo "[ok] 当前是 root 用户"
if [ ! -e /etc/apt/sources.list.bak ]
cp /etc/apt/sources.list /etc/apt/sources.list.bak
echo "备份文件 在: /etc/apt/sources.list.bak"
echo "已经存在备份文件:/etc/apt/sources.list.bak"
sudo rm -rf /var/lib/dpkg/updates/*
# 解决 sudo dpkg --configure -a # to correct the problem
ubuntu_release_setApt ; ubuntu_ntpdate ; apt update ; apt install -y sudo
if [ ! -e /etc/sudoers.d/stack ]
touch /etc/sudoers.d/stack
echo "为其他用户添加sudo 权限,多个用户空格个开!"
read -p "输入:" readuser
userlist=( root $readuser)
for i in ${userlist[*]}
catsudo=`cat /etc/sudoers.d/stack | grep $i`
if [ ${#catsudo} -lt 27 ]
echo "$i ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack
echo "[ok] 已经添加过用户 $i 的 sudo 权限"
if [ $i != root ]
echo "useradd $i Please set the password $i: "
useradd -m -d /home/$i -s /bin/bash $i; passwd $i
sudo apt update ; sudo apt update ; sudo apt upgrade -y ; sudo apt list --upgradable
echo "切换 apt update 源,更新软件包,和 查看可升级软件包完成"
install_kvm(){
installedkvm=` apt list --installed | grep virtinst` ; Length=${#installedkvm}
if [ $Length -gt 1 ]
echo "kvm 已经安装。"
echo "正在安装kvm ... "
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager -y
sudo systemctl is-active libvirtd
# 验证安装,注意:qemu-kvm 更名为:qemu-system-x86 卸载软件命令:sudo apt autoremove namepackage
echo "$USER ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack
# 授予当前用户sudo超级权限。
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER
# $USER 当前用户名,加入组,能够创建和管理虚拟机,否则无权限。然后注销重新登陆
ubuntu_aptupdate(){
echo "select: 1.config ubuntu apt update 2.install kvm qemu 3 exit"
read -p "input number: " selectRun
case $selectRun in
"1") sudo_install ;;
"2") install_kvm ;;
*) echo "已经跳过此步骤!" ;;
apt_install(){
echo "install google , qq , wecat, vscode ?"
read -p "input: y/n ?: " ifapt
if [ $ifapt = y ]
echo "[runing] install..."
wget eisc.cn/file/ubuntu/shell/server/vscode.sh; sudo chmod +x vscode.sh ; ./vscode.sh
wget eisc.cn/file/ubuntu/shell/server/weixin.sh; sudo chmod +x weixin.sh ; ./weixin.sh
echo "[ok] 取消安装必备软件! "
main(){
ubuntu_aptupdate
apt_install
# 一键部署:wget http://eisc.cn/file/ubuntu/shell/server/ubuntu_aptupdate.sh ; chmod +x ubuntu_aptupdate.sh; ./ubuntu_aptupdate.sh
if [ ! -e todesk_4.0.0b_amd64.deb ]
wget https://dl.todesk.com/linux/todesk_4.0.0b_amd64.deb
sudo dpkg -i todesk_4.0.0b_amd64.deb
echo "已经安装 todesk"
id=`cat /opt/todesk/config/todeskd.conf | grep -E "id" | awk -F"=" '{print $2}' ` ;
passwd=`cat /opt/todesk/config/todeskd.conf | grep -E "temppassword" | awk -F"=" '{print $2}' ` ;
echo "windows 控制端下载地址:https://www.todesk.com/download.html?dt=4"
echo "id 为: $id"
echo "passwd 为: $passwd"
echo "转明文密码为:"
echo -n $passwd | base64 -d
echo ""
nano todesk.shsudo todesk ; sudo chmod +x todesk.sh ; ./todesk.sh#------------------ dns 检查 --------------------#ifconfig enp1s0sudo netplan apply sudo shutdown -r now
./aptUpdate_ubuntu.sh
# 更新切换apt 源
sudo dpkg --configure -a ; sudo apt --fix-broken install -y
# 解决无法安装软件
sudo apt install $i -y
echo "[ok] $i 已经安装"
ftp_home(){
sudo touch /etc/vsftpd.user_list
# 解决 500
CreateUser=`ls -alh /var/ftp | awk -F" " 'NR==2{print $3}'`
if [ "$CreateUser" == "ftpvload" ]
echo "[ok] ftp 用户已经创建!"
sudo mkdir -p /var/ftp # -p 自动创建父目录文件夹:
sudo useradd vsftpd -M -s /sbin/nologin # 创建 vsftpd 用户: ,如果此目录不存在,则同时使用-m选项,可以创建主目录。
# -s Shell文件 指定用户的登录Shell。
sudo mkdir /etc/vsftpd/ ; sudo chmod 700 /etc/vsftpd
sudo touch /etc/vsftpd.user_list
sudo useradd ftpvload -d /var/ftp/ -s /sbin/nologin # -d 目录 指定用户主目录
sudo chown -R ftpvload.ftpvload /var/ftp/ # -R 目录拥有者ftpvload:ftpvload 其中 . 可以换成
ftp_conf(){
# 修改ftp主配置文件
userConfig="/etc/vsftpd/vconf"
file="/etc/vsftpd.conf"
sudo chown -R root:root $userConfig
# 重点 ftp 子用户配置目录必须是 root 用户所有; 否则:500 OOPS: config file not owned by correct user, or not a file
if [ ! -e $file.bak ]
sudo cp $file $file.bak ; sudo chmod 777 $file
sudo chmod 777 $file
echo "
pasv_promiscuous=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
chown_uploads=NO
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
async_abor_enable=no
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to FTP Server
chroot_local_user=YES
ls_recurse_enable=NO
listen=YES
hide_ids=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=NO
guest_enable=YES
guest_username=ftpvload
virtual_use_local_privs=YES
user_config_dir=$userConfig
pasv_enable=YES
pasv_min_port=63000
pasv_max_port=65535
" > $file
ftp_user_so(){
# 开启虚拟用户功能
pamfile="/etc/pam.d/vsftpd"
sudo cp $pamfile $pamfile.bak ; sudo chmod 777 $pamfile
echo "注意: 重要子用户配置文件:$pamfile 只需要保留两行, 否则添加子用户无法登陆
auth sufficient /usr/lib/x86_64-linux-gnu/security/pam_userdb.so db=/etc/vsftpd/virtusers
account sufficient /usr/lib/x86_64-linux-gnu/security/pam_userdb.so db=/etc/vsftpd/virtusers
当前库文件路径:"
sudo find /usr/lib/ -name pam_userdb.so | grep -v "snap"
buff=`cat $pamfile | grep /usr/lib/x86_64-linux-gnu/security/pam_userdb.so ` ; buffLength=${#buff}
if [ $buffLength -lt 100 ]
if [ ! -e $pamfile.bak ]
sudo cp $pamfile $pamfile.bak
sudo chmod 777 $pamfile
sudo sed -i "s/^/#/g" $pamfile # 在开头添加 # 号全部注释
# sudo find / -name pam_userdb.so | grep lib | grep -v snap
sudo echo "auth sufficient /usr/lib/x86_64-linux-gnu/security/pam_userdb.so db=/etc/vsftpd/virtusers
account sufficient /usr/lib/x86_64-linux-gnu/security/pam_userdb.so db=/etc/vsftpd/virtusers" > $pamfile
userfile="/etc/vsftpd"
sudo touch /var/log/vsftpd.log
sudo chown vsftpd.vsftpd /var/log/vsftpd.log
sudo mkdir $userfile ; sudo chmod 777 $userfile ; sudo mkdir -p $userfile/vconf/
pamfile="/etc/pam.d/vsftpd"
echo "[ok] vsftpd 用户新增配置功能已经设置,设置文件: $pamfile"
ftp_user_add(){
ftp_conf ; userConfig=$userConfig
# 执行函数,获取ftp 子用户配置目录
sudo touch /etc/vsftpd/vsftpd.user_list
sudo chmod 777 -R /etc/vsftpd
echo ""
echo "创建 ftp 登陆子用户,请输入 ftp 用户和密码,空格个开: "
read -p "输入:" userRead
buff=($userRead) ; echo "[ok] 正在创建信息为: ${buff[*]} 家目录自动分配到:$userFile/${buff[0]}"
if [ ${#buff[*]} == 2 ]
if [ ! -e $userFile/${buff[0]} ]
sudo mkdir $userFile/${buff[0]}
sudo chown -R ftpvload.ftpvload $userFile/${buff[0]}
echo "[error] 用户存在,请重新输入! 当前存在的路径:$userFile/${buff[0]} "
echo "[error] 输入的参数错误,需要输入两个参数,用户 和 密码,如: eisc 123456"
sudo touch /etc/vsftpd/virtusers
sudo chmod 777 /etc/vsftpd/virtusers
echo -e "${buff[0]}\n${buff[1]}" >> /etc/vsftpd/virtusers
sudo chown -R $USER:$USER /etc/vsftpd/virtusers
sudo db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db
# 使用库,对新增用户生效
sudo chmod 777 $userConfig
sudo mkdir -p $userFile/${buff[0]} ; sudo chmod 777 $userFile/${buff[0]}
echo "
# 允许可写
allow_writeable_chroot=YES
#设定支持ASCII模式的上传和下载功能
ascii_upload_enable=YES
ascii_download_enable=YES
local_root=$userFile/${buff[0]}
#指定虚拟用户的具体主路径
anonymous_enable=NO
#设定不允许匿名用户访问
write_enable=YES
#设定允许写操作
local_umask=022
#设定上传文件权限掩码
anon_upload_enable=NO
#设定不允许匿名用户上传
anon_mkdir_write_enable=NO
#设定不允许匿名用户建立目录
idle_session_timeout=600
#设定空闲连接超时时间
data_connection_timeout=120
#设定单次连续传输最大时间
max_clients=10
#设定并发客户端访问个数
max_per_ip=5
#设定单个客户端的最大线程数,这个配置主要来照顾Flashget、迅雷等多线程下载软件
#local_max_rate=50000
#设定该用户的最大传输速率,单位b/s" >> $userConfig/${buff[0]}
protlist=(
"20:21"
"63000:65535"
for i in ${protlist[*]}
onport=`sudo iptables -L -n --line-numbers | grep ACCEPT | grep -v Chain | grep $i` ; onportLength=${#onport}
if [ $onportLength -lt 10 ]
sudo iptables -A INPUT -p tcp --dport $i -j ACCEPT
echo "[ok] 正在添加 ftp 主动 和 被动 模式端口:$i "
echo "[ok] 已经添加过端口 $i "
sudo iptables -L -n --line-numbers | grep ACCEPT
sudo systemctl restart vsftpd
ftp_drop(){
read -p "清输入用户:" readu
sudo rm -rf /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db /datadisk/eisc/ftp/* /etc/vsftpd/vconf/*
main(){
ftp_install ; ftp_home ; ftp_conf ; ftp_user_so ; ftp_user_add
sudo chown -R root:root $userConfig
# 子用户配置文件目录,需要归 root 用户所有
# sudo apt install -y lftp
# lftp 192.168.122.1 -u rv11xx,000000
# 登陆ftp -u 跟上账户和密码
# wget -nH -m ftp://eisc:[email protected]/*
# 下载ftp 根目录下的所有文件,并且检查本地是否为最新,不是就覆盖
# http://eisc.cn/index.php?c=read&id=430&page=1ubuntu20/21/22 一键部署 vsftpd 服务 wget eisc.cn/file/ubuntu/shell/server/vsftpd.sh ; chmod +x vsftpd.sh ; ./vsftpd.sh
// 共享内存 4 函数定义;
// shmget() 创建共享内存,返回内存 shmid; 参数: 1.起名 2.内存地址大小 3.为0 是读取内存。创建内存要 填写权限 。
// 共享内存参数: IPC_CREAT 区别 IPC_EXCL 都是不存在就创建共享内存,区别 creat 是存在共享就打开, excl是存在就产生错误
// shmat() 返回内存空间地址并挂载, 1. 挂载到内存上的id 2.填0/null 自动找位置,3.标志位
// shmdt 删除挂载 参数:shmat 返回值。 成功返回0,失败返回-1
// shmctrl 删除内存
int gongxiang() {
signal(2, Handle); // signal.h是C标准函数库中的信号处理部分 ,按ctrl+c键退出时会处理这个消息,进行共享内存卸载、删除操作,最后exit(0)退出程序
key_t key = ftok(".", 0x1); // ftok 生成key数值,参数1 路径,参数2数字 1-255 之间,数字会加在key数值的前面
printf(" \n key 获取的数值:%x \n", key); // x 以16进制打印。 d 十进制; o 八进制
shmid = shmget(key, 100, IPC_CREAT | IPC_EXCL | 0666); // key 为 ftok 的返回值 ; 字节大小 100 ; shmflg:文件权限
// 创建共享内存,成功返回共享内存的ID,出错返回-1
// IPC_CREAT | IPC_EXCL则可以创建一个新的,唯一的共享内存,如果共享内存已存在,返回一个错误。*/
pshm = shmat(shmid, 0, 0); // shmat 附加好的内存地址,出错返回-1
// 共享内存标识符 ID 号; 映射到地址; 0 可读写, SHM_RDONLY 只读
if (*(int *)pshm == -1) { // 查看挂接是否成功如果出错返回-1,报错
printf("shmat error!\n");
exit(0);
memset(pshm, 0, 100); //初始化: 替换 0 的位置 为 100
struct Msg *msg = (struct Msg *)pshm;
msg->flag = 1; // 定义msg 结构体中的变量 flag 成员的数值 为1 是写入
while (1) {
if (msg->flag == 1) { //当为1时写消息,此时读文件中不能操作此共享内存
printf("请输入内容至共享内存:");
scanf("%s", msg->content);
msg->flag = 0; //当写消息后flag置为0,让读文件开始执行读操作,此时写文件不能进行写操作
else {
sleep(1);
return 0;
int main(){
gongxiang();
// ftok 说明:https://wenku.baidu.com/view/eac76f2e5b1b6bd97f192279168884868762b804.html?_wkts_=1667455715129&bdQuery=c+ftok+%E5%87%BD%E6%95%B0
// 参考案例:https://blog.csdn.net/arv002/article/details/109830080
// 共享内存函数说明:https://blog.csdn.net/weixin_35710880/article/details/117180126
// 共享内存 4 函数定义;
// shmget() 创建共享内存,返回内存 shmid; 参数: 1.起名 2.内存地址大小 3.为0 是读取内存。创建内存要 填写权限 。
// 共享内存参数: IPC_CREAT 区别 IPC_EXCL 都是不存在就创建共享内存,区别 creat 是存在共享就打开, excl是存在就产生错误
// shmat() 返回内存空间地址并挂载, 1. 挂载到内存上的id 2.填0/null 自动找位置,3.标志位
// shmdt 删除挂载 参数:shmat 返回值。 成功返回0,失败返回-1
// shmctrl 删除内存
struct Msg {
int flag;
char content[104];
}; // 定义结构体,下次引用不用定义变量类型
int main() {
key_t key = ftok(".", 2);
int shmid = shmget(key, 0, 0); // 参数3 为0 是读取共享内存
void *pshm = shmat(shmid, 0, 0); //挂接操作,成功返回指向共享存储段的指针,出错返回-1
if (*(int *)pshm == -1) { //查看挂接是否成功如果出错返回-1,报错
printf("shmat error!\n");
exit(0);
struct Msg * msg = (struct Msg *)pshm;
while (1) {
if (msg->flag == 0) { //当为0时读消息,此时写文件中不能操作此共享内存
printf("从共享内存收到 : %s\n", msg->content);
msg->flag = 1;
else {
sleep(1);
return 0;
#!/bin/bashread -p "套餐一:写字+看书套餐二:玩游戏+写程序代码强哥请选择您的套餐:" taocan a1="套餐一:写字+看书"b1="套餐二:玩游戏+写程序代码"site=$taocan # 给变量赋值case "$site" in # case [ke?s] 情况;处理变量 $site in 是下面的值 "1") echo "===========================您选择了:$a1" # 值为r 就打印字符串 ;; # 字句结束,往下匹配 "2") echo "===========================您选择了:$b1" ;; *) echo "===========================输入错误请重新输入!" ;;esac
expect [ɪkˈspɛkt] 预期;自动化插件与linux交互命令 spawn启动指定进程---expect获取指定关键字---send向指定程序发送指定字符---执行完成退出.1. expect 常用命令spawn 交互程序开始后面跟命令或者指定程序expect 获取匹配信息匹配成功则执行expect后面的程序动作send exp_send 用于发送指定的字符串信息exp_continue 在expect中多次匹配就需要用到send_user 用来打印输出 相当于shell中的echoexit 退出expect脚本eof expect执行结束 退出set 定义变量puts 输出变量set timeout 设置超时时间interact 允许用户交互2. ssh登录远程主机并且执行命令#!/bin/bashyum install -y expect # 安装交互工具包set timeout 30 # 设置匹配字符的等待时间/usr/bin/expect << EOF # 执行交互程序,通过EOF 打包给程序spawn ssh [email protected] # 进行远程连接服务器expect "password:" # 匹配密码提示send "000000\r" # 输入密码并换行expect "#" # 登录成功后匹配符号 #send "echo '登录成功' \r" # 执行打印命令并换行expect eof # 匹配结束# exit # 退出EOF # 总打包结束3. ssh远程登录主机执行命令,在shell脚本中执行expect命令,执行方法sh 2.sh、bash 2.sh 或./2.sh都可以执行#!/bin/bashpasswd='tytyt123456' # 定义一个变量为字符串 # -EOF 输入多行命令 # 调用命令的路径:/usr/bin/expect <<-EOF /usr/bin/expect <<-EOF spawn ssh [email protected] df -Th # 执行两个命令 # 定义一个函数,名字为: expectexpect { "*yes/no" { send "yes\r"; exp_continue }"*password:" { send "$passwd\r" }}expect eof # 将函数名字放出来执行,并结束匹配EOF # 总结束4. expect执行多条命令#!/usr/bin/expect -fset timeout 10spawn sudo su - root # 切换用户expect "*password*" # 匹配包含字符password后send "123456\r" # 输入123456 并 /r 确定 也可以 \n 换行确定 # 新增用户命令: useradd eiscexpect "#*"send "ls\r"send "exit\r"expect eof5. 创建ssh key,将id_rsa和id_rsa.pub文件分发到各台主机上面。1.创建主机配置文件[root@localhost script]# cat host 192.168.1.10 root 123456192.168.1.20 root 123456192.168.1.30 root 123456[root@localhost script]# lscopykey.sh hosts2.编写copykey.sh脚本,自动生成密钥并分发key.[root@localhost script]# vim copykey.sh#!/bin/bash# 判断id_rsa密钥文件是否存在if [ ! -f ~/.ssh/id_rsa ];then ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsaelse echo "id_rsa has created ..."fi#分发到各个节点,这里分发到host文件中的主机中.while read line do user=`echo $line | cut -d " " -f 2` ip=`echo $line | cut -d " " -f 1` passwd=`echo $line | cut -d " " -f 3` expect < Region & Languge ---> input source ---> 点击 + 号 ---> 点击 Chinese ---> Chinese (intelligent Pinyin)# --------- 安装中文语言 ----------#设置为中文:ubuntu 右上角 电源右边的 三角形图标 【设置/settings】 ---> Region & Languge ---> Manage installed Languwges ---> 点击进入:第一个方框:运用到整个系统第二个方框:勾选需要安装的语言,没有勾选的会被删除第三方方框:键盘输入系统:选择 Ibus如果输入法无法正常切换: apt remove -y ubuntu-desktop && apt install -y ubuntu-desktop# 使用root 用户重新安装桌面
l # 安装c 语言环境sudo apt-get install g++ # 安装C语言环境 ,或者 # apt install -y gcc-arm-linux-gnueabihf gcc gcc-aarch64-linux-gnu mtools lib32gcc-7-dev g++-7 libstdc++-7-devgcc -v # 验证安装的 C 语言是否成功vi eisc.c # 编写C语言程序#includeint main(){ int num; printf("输入一个数字 : "); scanf("%d",&num); (num%2==0)?printf("偶数"):printf("奇数");}gcc eisc.c -o eisc.o # 编译C语言为输出后的 eisc.o 文件./eisc.o # 执行编译后的C语言 C 语言基础:http://c.biancheng.net/c/
l # ubuntu 安装 kvmsudo apt-get update# 更新yum sudo apt-get upgrade# 更新内核软件# ubuntu清华 apt 源:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/rebootsudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager -y# 以普通用户安装kvmsudo systemctl is-active libvirtd# 验证echo "eisc ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack # 切换到root用户 授予eisc用户sudo超级权限。如果是其他用户,可以将eisc改为实际用户sudo usermod -aG libvirt $USERsudo usermod -aG kvm $USER# $USER 当前用户名,加入组,能够创建和管理虚拟机,否则无权限。然后注销重新登陆#--------- 网络设置 -----------#brctl show # 列出网桥和接口,“ virbr0”网桥未添加任何物理接口。“ virbr0-nic”是虚拟设备,没有流量通过该虚拟设备。该设备的唯一目的是避免更改“ virbr0”网桥的MAC地址#---------- 安装桌面和远程桌面 ------#apt-get install xrdp ubuntu-desktopapt-get install dconf-editorsudo apt install -y openssh-server# ssh登录 # 相关说明qemu-kvm -为KVM管理程序提供硬件仿真的软件。libvirt-daemon-system -用于将libvirt守护程序作为系统服务运行的配置文件。libvirt-clients -用于管理虚拟化平台的软件。bridge-utils -一组用于配置以太网桥的命令行工具。virtinst -一组用于创建虚拟机的命令行工具。virt-manager -易于使用的GUI界面和支持命令行工具,用于通过libvirt管理虚拟
1. ubuntu 配置静态 ip ; 2. 修改为 动态ip ; 3. ubuntu20 阿里云 apt 源 ; 4. ubuntu20 清华 apt 源。 apt update 与 apt upgrade 区别:只查看更新,和 更新软件包 # 修改为静态指定ipip a # 通过ip a 查看网卡名字,然后再下面配置中将 eth0 改为正确的网卡名【ubuntu20 版本配置】nano /etc/netplan/01-network-manager-all.yamlnetwork:
ethernets:
enp1s0:
addresses: [192.168.122.80/24]
dhcp4: no
optional: true
gateway4: 192.168.122.1
nameservers:
addresses: [192.168.122.1,223.5.5.5]
version: 2
renderer: NetworkManager【ubuntu22 版本配置】解决报错: Ubuntu 22.10 netplan `gateway4` has been deprecatednetwork:
ethernets:
enp1s0:
addresses:
- 192.168.122.80/24
dhcp4: false
gateway4: 192.168.122.1
nameservers:
addresses:
- 192.168.122.1
search: []
version: 2
# renderer 可不加,部分服务器加上这个参数网卡无法启动 # 223.5.5.5 网络速度慢只有1M/s 速度,建议dns 修改为网关一个ipsudo netplan apply # 生效配置 # 修改动态获取ipvi /etc/netplan/01-network-manager-all.yaml network: ethernets: eth0: dhcp4: true version: 2sudo netplan apply # 生效配置 # ubuntu20 阿里云 apt 源阿里云源 选择系统版本, 镜像仓库:https://developer.aliyun.com/mirror/vi /etc/apt/sources.listdeb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse # ubuntu20 清华 apt 源清华apt 源选择版本:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/vi /etc/apt/sources.list# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse# 预发布软件源,不建议启用# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverseapt update # 命令更新软件源(只检查不更新)apt upgrade # 更新已安装的软件包
debian 安装docker 网段 仓库地址, 拉取 nacos # 安装dockerapt updateapt install ca-certificates curl software-properties-common gnupg2 curl -y# 安装docker 依赖echo "deb [arch=amd64] http://mirrors.ustc.edu.cn/docker-ce/linux/debian buster stable" >> /etc/apt/sources.list# docker 的源 ,不能有空格curl -fsSL http://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | apt-key add -# 添加gpg密匙apt-get install docker-ce# 安装dockersystemctl start docker# 启动docker#-------- docker 修改网段 -----#echo "{"registry-mirrors": ["https://hub-mirror.c.163.com"],"bip": "111.111.111.1/24"}" > /etc/docker/daemon.jsonsystemctl daemon-reload ; systemctl restart docker # 重启docker# bip 指定网段为:网段掩码位,如 24 错误将会导致docker无法重启 # 拉取,并配置nacosdocker拉取nacos镜像 docker search nacos # 搜索nacos源docker pull nacos/nacos-server # 拉取nacos镜像mkdir -p /mydata/nacos/logs/# 新建logs目录mkdir -p /mydata/nacos/init.d/docker run --name nacos -p 8848:8848 \--privileged=true \--restart=always \-e JVM_XMS=256m \-e JVM_XMX=256m \-e MODE=standalone \-e PREFER_HOST_MODE=hostname \-v /mydata/nacos/logs:/home/nacos/logs \-d nacos/nacos-serverdebian安装docker:https://www.cnblogs.com/surplus/p/11367556.htmldocker 拉取nacos:https://www.cnblogs.com/leasing/p/15410095.html安装 nacos 集群:https://nacos.io/zh-cn/docs/cluster-mode-quick-start.htmlnacos 集群配置:https://blog.51cto.com/u_10950710/3157514nacos 默认登录信息:http://tx.kbash.cn:8848/nacos/#/login账户/密码:nacos/nacos# nacos 的数据库是集成的,不需要改数据库
date +%Y-%m-%d-%H:%M:%S # 获取当前年月日时分秒date -d "-1 day" +%Y-%m-%d # 获取时间并再当前时间减去一天,格式化时间为 年月日date -d '2 days ago' # 显示2天前的时间date -d '3 month 1 day' # 显示3月零1天以后的时间date -d '25 Dec' +%j # 显示12月25日在当年的哪一天date -d '30 second ago' # 显示30秒前的时间date -d "-3 month" # 前三个月date -d "+3 year" # 三年后date -d `date +%y%m01` # 本月第一天#--------------------- 其他说明 -----------------------#%% 一个文字的 % %a 当前locale 的星期名缩写(例如: 日,代表星期日) %A 当前locale 的星期名全称 (如:星期日) %b 当前locale 的月名缩写 (如:一,代表一月) %B 当前locale 的月名全称 (如:一月) %c 当前locale 的日期和时间 (如:2005年3月3日 星期四 23:05:25) %C 世纪;比如 %Y,通常为省略当前年份的后两位数字(例如:20) %d 按月计的日期(例如:01) %D 按月计的日期;等于%m/%d/%y %e 按月计的日期,添加空格,等于%_d %F 完整日期格式,等价于 %Y-%m-%d %g ISO-8601 格式年份的最后两位 (参见%G) %G ISO-8601 格式年份 (参见%V),一般只和 %V 结合使用 %h 等于%b %H 小时(00-23) %I 小时(00-12) %j 按年计的日期(001-366) %k hour, space padded ( 0..23); same as %_H %l hour, space padded ( 1..12); same as %_I %m month (01..12) %M minute (00..59) %n 换行 %N 纳秒(000000000-999999999) %p 当前locale 下的"上午"或者"下午",未知时输出为空 %P 与%p 类似,但是输出小写字母 %r 当前locale 下的 12 小时时钟时间 (如:11:11:04 下午) %R 24 小时时间的时和分,等价于 %H:%M %s 自UTC 时间 1970-01-01 00:00:00 以来所经过的秒数 %S 秒(00-60) %t 输出制表符 Tab %T 时间,等于%H:%M:%S %u 星期,1 代表星期一 %U 一年中的第几周,以周日为每星期第一天(00-53) %V ISO-8601 格式规范下的一年中第几周,以周一为每星期第一天(01-53) %w 一星期中的第几日(0-6),0 代表周一 %W 一年中的第几周,以周一为每星期第一天(00-53) %x 当前locale 下的日期描述 (如:12/31/99) %X 当前locale 下的时间描述 (如:23:13:48) %y 年份最后两位数位 (00-99) %Y 年份 %z +hhmm 数字时区(例如,-0400) %:z +hh:mm 数字时区(例如,-04:00) %::z +hh:mm:ss 数字时区(例如,-04:00:00) %:::z 数字时区带有必要的精度 (例如,-04,+05:30) %Z 按字母表排序的时区缩写 (例如,EDT)
nginx 自动ssl证书配置 # 1. 安装ssl 证书软件yum install -y snapdapt install snapd# 1.安装snapd yum reinstall -y snapd# 重新安装 snapd,确保您的 snapd 版本是最新的systemctl enable --now snapd.socket# 安装后,需要启用管理主 snap 通信套接字的systemd单元snap install core;# 安装核心如果报错请检查第一步snap refresh core # 刷新核心 snap install --classic certbot# 安装证书机器人# sudo apt-get remove certbot、sudo dnf remove certbot或sudo yum remove certbot。# 如果您使用apt、dnf或yum等操作系统包管理器安装了任何 Certbot 包 ,则应在安装 Certbot snap 之前将其删除,以确保在运行命令 certbot 时使用的是 snap,而不是从您的操作系统包安装经理。 ln -s /var/lib/snapd/snap /snap# 软连接(快捷方式)已经安装的软件 snap 到 要求的路径snap :经典限制要求在/snap或symlink下使用快照snap install --classic certbot# 安装证书机器人ln -s /snap/bin/certbot /usr/bin/certbot# 将证书机器人安装目录创建快捷方式到 运行目录 /usr/bin/certbot (软连接)# 删除快捷方式,删除软连接 rm -rf /usr/bin/certbot # 2. ubuntu 证书#!/bin/bash
# 自动申请ssl 证书
InstallSnapd()
sudo apt install snapd -y
sudo systemctl enable --now snapd.socket
sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /var/lib/snapd/snap /snap
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
RequestSSL()
certbot certonly --nginx
# 只获取证书
# 2. 申请ssl 证书# certbot --nginx# 自动配置nginx ssl 证书,会修改nginx 配置文件,输入电子邮箱,后回车确认# 运行此命令以获取证书并让 Certbot 自动编辑您的 Nginx 配置以提供服务,只需一步即可打开 HTTPS 访问certbot certonly --nginx# 我们选择只获得nginx 证书,手动配置,将来源的ssl 证书删除,然后将自动下载的ssl 创建软链接(快捷方式)到原来的ssl 文件# 1: Keep the existing certificate for now# 暂时保留现有证书# 2: Renew & replace the certificate (may be subject to CA rate limits)# 更新和更换证书(可能受CA费率限制) 2# agree in order to register with the ACME server. Do you agree?# 同意在ACME服务器上注册。你同意吗? y# Would you be willing, once your first certificate is successfully issued, toshare your email address with the Electronic Frontier Foundation,# 一旦您的第一份证书成功颁发,您是否愿意分享你的电子邮件地址与电子前沿基金会,成立Let's Encrypt项目的合作伙伴和机器人 no# Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel):# 选择以逗号和/或空格分隔的适当数字,或保留输入 空白选择显示的所有选项(输入“c”取消):# Successfully received certificate.# Certificate is saved at: /etc/letsencrypt/live/www.eisc.cn/fullchain.pem# Key is saved at: /etc/letsencrypt/live/www.eisc.cn/privkey.pem# 证书的位置如上图,自动修改nginx 子站点的 ssl 路径,每三个月自动更新ssl # 由于是链接的国外 R3 证书颁发机构,可能存在失败的情况,需要重试 rm -rf /eisc/www/ssl/eisc/eisc.pemrm -rf /eisc/www/ssl/eisc/eisc.key# 删除原有ssl 证书文件ln -s /etc/letsencrypt/live/www.eisc.cn/fullchain.pem /eisc/www/ssl/eisc/eisc.pemln -s /etc/letsencrypt/live/www.eisc.cn/privkey.pem /eisc/www/ssl/eisc/eisc.keynginx -s reload# 重载nginx 配置文件教程来源:https://www.cnblogs.com/hushuning/p/14842251.html # 查看 nginx 配置信息server{listen 443 ssl;server_name www.eisc.cn eisc.cn; ssl_certificate /etc/letsencrypt/live/eisc.cn/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/eisc.cn/privkey.pem; # managed by Certbot #ssl on; 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 / {proxy_pass https://eisc.cn;index index.php index.html;#------------- 可见ip ------------# proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}server{ if ($host = eisc.cn) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = www.eisc.cn) { return 301 https://$host$request_uri; } # managed by Certbotlisten 80;server_name www.eisc.cn eisc.cn; return 404; # managed by Certbot
yum install nginx-mod-stream -y # 安装动态模块ll /usr/lib64/nginx/modules # 查看动态模块文件vi /etc/nginx/nginx.conf # 设置配置文件重点:需要注释掉动态模块冲突引用:# include /usr/share/nginx/modules/*.conf;# 添加配置:nginx 主配置文件最外层添加, 在 nginx 的 http 板块外面添加,不能写到首行load_module /usr/lib64/nginx/modules/ngx_stream_module.so;include /www/www/tcp/*.conf;# 设置动态模块的配置文件路径 在 nginx 的 http 板块外面添加#------------------------- tcp 转发 ---------------------------#vi /www/www/tcp/8000.conf # 编辑配置文件stream { upstream bt { server 10.111.111.2:8888; } # 设置函数 tcp 转发名称:bt # 转发目的地端口:10.111.111.2:8888; server { listen 8000; server_name eisc.cn; proxy_pass bt; }} # web 配置
#--- 代理服务器(外层nginx) ---#nginx 子站点配置文件: /www/www/wwwconf/www.conf#分站子站转发配置,再server 板块的 location 方法里面server{listen 80;server_name work.eisc.cn;location / { proxy_pass http://work.eisc.cn; #--- 将ip 记录下来,传递给后端服务器 ---# proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}nginx -s reload # nginx 配置生效,或者重启nginx #--- web 服务器(后端 nginx)---#nginx 主配置文件,非子站点:# 再 http 板块:案例下面位置处: 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 256k; fastcgi_intercept_errors on;#--------- 配置可见ip ---------# set_real_ip_from 10.111.111.1; real_ip_header X-Forwarded-For;# 填写实际的内网请求来源 ip # 作用: 将内网ip 进行替换成客户端实际 ip#------------------------------# #--- nginx 主配置文件案例 ---#user www www;worker_processes auto;error_log /www/wwwlogs/nginx_error.log crit;pid /www/server/nginx/logs/nginx.pid;worker_rlimit_nofile 51200;events { use epoll; worker_connections 51200; multi_accept on; }http { include mime.types; #include luawaf.conf; include proxy.conf; default_type application/octet-stream; server_names_hash_bucket_size 512; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; sendfile on; tcp_nopush on; keepalive_timeout 60; 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 256k; fastcgi_intercept_errors on; #--------- 配置可见ip ---------# set_real_ip_from 10.111.111.1; real_ip_header X-Forwarded-For;#--------------- 开启gzip 压缩 ---------------# gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; limit_conn_zone $binary_remote_addr zone=perip:10m; limit_conn_zone $server_name zone=perserver:10m;#---------------------------------------------------# server_tokens off; access_log off; # 关闭日志include /www/wwwroot/wwwconf/*.conf;}阿里云配置教程: https://help.aliyun.com/document_detail/54007.html第三方教程:https://www.cnblogs.com/wangxu01/articles/11243496.html
#!/bin/bash# centos7 重装yumcatlogdata="/eisc/yum"mkdir -p $catlogdata ; rm -rf $catlogdata/*; # 创建下载目录,并清空目录curldown="http://mirrors.163.com/centos/7/os/x86_64/Packages" # 定义下载连接变量rpm -aq|grep yum|xargs rpm -e --nodeps # 卸载yumwgetrun(){curl $curldown/wget-1.14-18.el7_6.1.x86_64.rpm > wget.rpmrpm -ivh wget.rpm}; wgetrun # 解决wget 问题rpmb=("python-iniparse-0.4-9.el7.noarch.rpm ""python-pycurl-7.19.0-19.el7.x86_64.rpm""python-2.7.5-89.el7.x86_64.rpm" "python-urlgrabber-3.10-10.el7.noarch.rpm""python-libs-2.7.5-89.el7.x86_64.rpm" "yum-metadata-parser-1.1.4-10.el7.x86_64.rpm" "yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm""yum-3.4.3-168.el7.centos.noarch.rpm"); # 定义数组变量要下载的包for i in ${rpmb[*]} do wget $curldown/$i -O $catlogdata/$i echo "下载文件:$curldown/$i 到: $catlogdata/$i" donerpm -ivh $catlogdata/yum-metadata-parser-1.1.4-10.el7.x86_64.rpmrpm -ivh $catlogdata/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpmrpm -ivh $catlogdata/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm $catlogdata/yum-3.4.3-168.el7.centos.noarch.rpm # 两个包要一起安装相互依赖 # centos7 重装yum:https://www.cnblogs.com/DiZhang/p/12544744.htmlwget eisc.cn/file/shell/centos-yum.sh ; sh centos-yum.sh # centos 切换yum 源 yum install yum-utils -y # 解决:发现 XX 个已存在的 RPM 数据库问题
#---ssl 301 转跳 ---# if ($server_port = 80){ rewrite ^(/2.php)$ http://www.eisc.cn$1 permanent; }#--- 目录301 转跳 ---#设置 301 转跳, location /ccb/ { return 301 http://work.eisc.cn; proxy_pass http://eisc.cn/cs; index index.html index.htm;}# 说明:讲不带www 转到带www的,需要将不带www 的单独一个server 子站点配置转跳到 https://wwwreturn 301 https://www.eisc.cn$request_uri;# 设置 302 重定向 location /ccb/ { rewrite /ccb/activity(.*)$ https://www.baidu.com break; proxy_pass http://192.168.118.14/; index index.html index.htm;}#---------------------------- nginx 转发 反向代理 -----------------------------# # nginx 子站点tcp转发server{listen 80 ;listen 443;server_name kbash.cn www.kbash.cn;location / { proxy_pass http://82.157.148.144:80; index index.php index.html; }}#------------- nginx https 转发 -------------## 注意如果需要配置ssl 需要再nginx 主配置http 模块文件加入ssl 证书配置,否则子站点无法设置ssl ,将会报错ssl_certificate /www/www/ssl/www/eisc.pem; ssl_certificate_key /www/www/ssl/www/eisc.key; # 需要已经存在的任意证书文件#------------- https 站点 ----------#server{listen 443 ssl;server_name eisc.cn www.eisc.cn;#---------------- ssl 证书 ----------------------ssl_certificate /www/www/ssl/www/eisc.pem; ssl_certificate_key /www/www/ssl/www/eisc.key; #ssl on; 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; add_header jiedian "eisc.cn-ceshi"; add_header "开发商" "小绿叶技术博客eisc.cn"; add_header "节点" "小绿叶总站--总部";location / { proxy_pass http://eisc.cn; }}#---------------------------------------------------------------------#1 nginx修改root映射修改root映射实现nginx目录访问重定向是最简单的方式, 推荐采用这一种.location /image { root /folderName;}2 通过nginx rewrite内部跳转实现访问重定向nginx配置代码示例:location /image { rewrite ^/image/(.*)$ /folderName/image/$1 last;}3 nginx设置别名alias映射实现配置示例:location /image { alias /folderName/image; #这里写绝对路径}4 通过nginx的permanent 301绝对跳转实现配置示例:location /image { rewrite ^/image/(.*)$ http://dashidan.com/folderName/image/$1;}5 通过判断uri实现页面跳转配置示例:if ( $request_uri ~* ^(/image)){ rewrite ^/image/(.*)$ /folderName/image/$1 last;}原文链接:https://blog.csdn.net/sinbadfreedom/article/details/79494702tcp 转发:https://www.cnblogs.com/baolin2200/p/7803511.html
忘记登陆密码,重置密码,安装教程-网卡多ip配置============ centos 6 和 7重置密码 =================== centos 6.8 =====1.开机按Esc 或者 e 按键进入启动选择,再按 e 进入选择修改,然后出现 root kernel initrd 这三行开头的选择信息2.光标指向 kernel 这一行,按 e 进入修改 将 rhgb quiet 修改添加空格和1 为 rhgb quiet 1 或者 修改为: rhgb quiet single3.Esc 返回上一级,按 b 键启动系统系统4. 命令 passwd 进行修改密码,然后 reboot 重启======= centos 7 ======1.重启系统进入 提示等待几秒后启动系统的这个界面,按e键修改2.进入修改面板,有几行开头为:if else fi initrd16; 有两行开头为:linux16 和 initrd16; 我们修改linux16 行中的: 删除 rhgb quiet 和后面的内容如:UTF什么的,(也有些用户没有后面的UTF) 删除之后在其后添加 rd.break enforcing=0 再然后按Ctrl 加 X 保存,就进入命令窗口3. 输入命令: mount -o remount,rw /sysroot #重新挂载系统为写入 chroot /sysroot #改变文件系统的root # 进入用户界面下修改文件 passwd # 设置密码touch /.autorelabel # 引导前重新标记所有文件exit # 退出# mount -o remount,ro / # 不需要执行:重新挂载为只读exit # 退出后会重启#------------- 中毒后无法修改密码error: ------------#linux_pe挂载后进入系统,或者开机启动时按e修改,进入破解页面mount /dev/vda1 /mnt # 挂载系统盘chroot /mnt # 进入系统passwd root # 修改密码,无法修改报错 errorchattr -i /etc/*shadow /etc/passwd /etc/groupchattr -a /etc/*shadow /etc/passwd /etc/group # 设置权限lsattr /etc/*shadow /etc/passwd /etc/group # 查看权限 # 权限全部显示为横杠 ------------- /etc/gshadowpasswd root # 再次修改--------------------------- centos 安装教程 ---------------------------centos分区方案策略:http://eisc.cn/index.php?c=read&id=153&page=1安装时磁盘:勾选 l will configure partitioning 我要自己分区,删除原有的 LVM 分区后将LVM更换为 Standard partition 标准分区,Dbne 再回来分区Accept Changes [əkˈsept ˈtʃeɪndʒɪz] 接受更改在安装时:config 配置网卡,右上角的开关打开,配置网卡ipv4将DHCP更改为Manual(手动) add添加多个IPliunx多个ip:以配置DNS一样似:DNS1和DNS2样式;IPADDR1=IPADDR2=NETMASK1=NETMASK2=GATEWAY1=GATEWAY2=DNS1=8.8.8.8# dns 禁止出现dns0 需要大等于0,否则网卡不通================ ubuntu ================----------- 重置密码 ---------1. 开机时:按ESC 后按键 e或者进入下面启动选项,选择removable device进入修改启动removable devices [rɪˈmuːvəbl dɪˈvaɪsɪz] 可移动设备或者Shift 按键选择第二个是高级选项:ubuntu 高级选项然后选择第三个,括号里有:recovery mode再然后按键e 进入启动编辑或者重启系统进入选择界面 ,按键 e 直接进入编辑不同机器有不同方式,可以三种都试一下2. 已经进入了修改界面之后在行:linux /boot/ 行末 先删除 ro 和后面的内容 添加内容 quiet splash rw init=/bin/bash3. Crtl + X 重启后箭头向下选择括号里有(recovery mode)为高级选项然后即可自动进入超级管理界面4. 输入passwd 更新密码出现password updates successfully即更改成功,输入shutdown 或直接重启虚拟机即可。若出现下面的问题 passwd: Authentication token manipulation error passwd: password unchanged 网上说是因为recovery mode下的根分区是以只读的方式挂载的,所以需要重新挂载,输入下面的指令即可: #> mount -rw -o remount /到此,问题解决了,重启即可ubuntu server 16 安装教程: https://blog.csdn.net/weixin_43397326/article/details/83186427ubuntu 安装教程:https://blog.csdn.net/zhengchaooo/article/details/80145744如果无法分区:返回上一级,选择选择: 27.您的时区对吗?(Is this time zone correct?):Yes * (卸载正在使用的分区)unmount partitions that are in use? : Yes * (删除现有的逻辑卷数据)Remove existing logical volume data:Yes * (用于引导分区的卷组的数量)amount of volume group to use for guided partitioning: ?-------- ubuntu vi 编辑: -------(1)下面介绍一下几种光标的控制和移动(在一般模式下操作)k 向上移动 h 向左移动j 向下移动 l 向右移动h :左移一个字符 l :光标右移一个字符space:右移一个字符 Backspace:光标左移一个字符k:光标上移一行 j:光标下移一行Enter :光标下移一行w或W :光标右移一个字至字首b或B :光标左移一个字至字首e或E :光标右移一个字至字尾x 删除当前光标下的字符X 删除光标前面的字符dw 删除从当前光标到单词结尾的字符d^ 删除从当前光标到行首的字符d$ 删除从当前光标到行尾的字符D 删除从当前光标到行尾的字符dd 删除当前光标所在的行其它常用命令;ndw或ndW:删除光标处开始及其后的n-1个字do:删至行首d$:删至行尾ndd:删除当前行及其后n-1行x或X:删除一个字符,x删除光标后的,而X删除光标前的Ctrl+u:删除输入方式下所输入的文本配置网卡多个ip地址:在vi 模式下可以按 Delete 键,删除字符vi /etc/network/interfaces # ubuntu 16 路径# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).source /etc/network/interfaces.d/*# The loopback network interfaceauto loiface lo inet loopback# The primary network interfaceauto enp6s0f0iface enp6s0f0 inet static address 192.168.1.9 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.254 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 8.8.8.8iface enp6s0f0 inet static address 192.168.1.10iface enp6s0f0 inet static address 192.168.1.11#==========================sudo /etc/init.d/networking restart # 重启网卡,然后ip add查看操作用户:cat /etc/group # 列出用户cat /etc/group | grep ^e # grep 过滤选择, ^ 开头字符为e的用户sudo useradd username -m # 创建用户sudo passwd username # 设置密码su username # 切换用户ps -ef | grep eisc # 显示进程pid ,grep 过滤eisc名字的进程kill -9 eisc # 终止pid -9 参数;进程为eisc的进程。sudo userdel -r eisc # 删除用户eisccat /etc/issue # 查看版本号=========== ubuntu 18 ============vi /etc/netplan/50-cloud-init.yaml # ubuntu 18 路径enp6s0f0: addresses: - 9.0.0.9/24 - 10.0.0.10/24 - 11.0.0.11/24 dhcp4: false gateway4: 1.1.1.254 nameservers: addresses: - 8.8.8.8 search: sudo netplan apply # 重启网卡=============== debian ================忘记密码修改密码:1.重启进入开机选择界面,按键 e 后修改启动文件,2.将 linux /boot 开头的行的 末尾 ro quiet 及其后面的内容更改为 rw single init=/bin/bash3.命令:mount -a4.命令:passwd root 修改你为你的新密码5.重启,或关掉电源,完成-------------------安装教程:debian下载:http://mirrors.hust.edu.cn/debian-cd/9.8.0/amd64/iso-cd/安装教程:https://ywnz.com/linuxaz/2591.html启动后其中选择第二个为 install 最小安装安装load installer components from cd # 从CD加载安装组件install the base system # 安装基本系统guided use entire disk # 引导使用整个磁盘primary ˈprīm(ə)rē, # 主:主分区finish partitioning and write changes to disk # 完成分区并将更改写入磁盘write the changs to disks # 将更改写入磁盘 yes'device for boot loader installation # 用于引导加载程序安装的设备 : /dev/sda等待校验,然后就可以选择自己要安装的 ssh 包了a network mirror can be used to supplement the software that is included onthe CD-ROM # 可以使用网络镜像来补充CD-ROM附带的软件 # 选择否选择安装,按空格勾选,除了ssh 其余全部取消install the grub boot loader to the master boot record # 最后一部:将grub引导加载程序安装到主引导记录中,是,否则无法启动编辑文本使用:vimapt-get install -y vimvim /etc/network/interfaces # 配置网卡多个IPauto ens192:1 # 机器本身的是 allow-hotelug ens192,直接修改为auto # 多ip 格式:auto ens192 # ens192:1 其中 :1 表示新增ip auto ens192:1 inet static address 43.242.34.245/24 gateway 43.242.34.254auto eno2 # 内网,直接在这个文档里编辑iface eno2 inet static address 192.168.1.4/24/etc/init.d/networking restart # 重启网卡service networking restart手动安装 ssh apt-get install openssh-clientapt-get install openssh-serverps -e |grep sshvi /etc/ssh/sshd_configPermitRootLogin without-password # 修改前PermitRootLogin yes # 修改后 /etc/init.d/ssh restart # 重启service ssh restart--------------- esxi -------------------esxi6.7序列号: HV4WC-01087-1ZJ48-031XP-9A843需要关闭 ssh 与 esxi shell步骤:首页>>>F2>>>输入密码后回车>>>Troubleshooting Options>>>回车切换开启/关闭:右边状态栏查看当前状态 is只需要配置一个IPadd选择网卡新安装和重置密码,只有第六步不同ESXI root密码忘记,重置root密码 第一步、放入安装时候的光盘进行光盘引导,按回车键下一步 第二步、同意霸王条款,按F11,下一步:第三步、安装程序自动搜索安装磁盘 wKiom1aLjpaAj_aiAACJZu37C80110.png第四步、直接选择要安装的磁盘,就是早起安装的那个磁盘 第五步、安装程序会自动检测选择的硬盘上是否安装过系统,从而进行判断此次安装是升级还是安装第六步、由于之前安装过此系统,那么会有如下选项,解释分别如下: (1)升级此系统,保留VSMF数据(包括用户信息),因此选择此选项无用 (2)安装此系统,保留VSMF数据(安装系统,清除账户信息,不会丢失数据) (3)安装此系统,清楚所有VSMF数据(此操作会清空所有数据文件) 故而选择第二种安装方案 第七步、设置新的密码第八步、设置好密码后,系统手机信息,就有进度条开始走了第九步、安装完成后,系统提示“成功”,reboot后继续安装大功告成,可以使用客户端使用新的密码进行登录了。linux修改 ssh 远程端口:https://www.eisc.cn/index.php?c=read&id=154&page=1
#!/bin/bashcentos6d(){release=`cat /etc/redhat-release |grep release | awk -F" " '{print $3}' | awk -F"." '{print $1}'` ; echo "centos 版本为: $release "case "$release" in"6") echo " 当前匹配centos 版本为 6"repo="/etc/yum.repos.d/centos6-epel.repo"if [ ! -e $repo ]; then # -e 判断文件存在;参考:Shell if 条件判断文件或目录yum install -y wgetcd /etc/yum.repos.d/mkdir bakmv * bakwget work.eisc.cn/ruanjian/rpm/yumrepo/centos6-epel.repowget work.eisc.cn/ruanjian/rpm/yumrepo/centos6.repoyum clean all # 清除原有缓存yum makecache # 生成新的缓存 # make cache [me?k] [ka?] 制作 缓存{ka xi}yum list # 校验yumcdelseecho "yum已经切换"fi;;*) echo "低版本未匹配到,正在匹配红帽版本配置yum !!!"redhat8d;;esac}centos7(){repo="/etc/yum.repos.d/epel-7.repo"if [ ! -e $repo ]; then # -e 判断文件存在;参考:Shell if 条件判断文件或目录yum install -y wgetcd /etc/yum.repos.d/mkdir bakmv * bakwget work.eisc.cn/ruanjian/rpm/yumrepo/Centos-7.repowget work.eisc.cn/ruanjian/rpm/yumrepo/epel-7.repo# wget http://mirrors.aliyun.com/repo/Centos-7.repo# wget http://mirrors.aliyun.com/repo/epel-7.repo # 移动两个文件到 目录#wget http://mirrors.163.com/.help/CentOS7-Base-163.repo#sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo# sed -i 's/$releasever/7/g' /etc/yum.repos.d/* # yum源没有对应版本包匹配;修改yum为centos7yum clean all # 清除原有缓存yum makecache # 生成新的缓存 # make cache [me?k] [ka?] 制作 缓存{ka xi}yum list # 校验yumcdelseecho "yum已经切换"fi}centos8(){repo="/etc/yum.repos.d/Centos-8.repo"if [ ! -e $repo ]; thencd /etc/yum.repos.d/mkdir bakmv * bakwget work.eisc.cn/ruanjian/rpm/yumrepo/centos8/centos8.repowget work.eisc.cn/ruanjian/rpm/yumrepo/centos8/epel.repoyum clean all #清理缓存yum makecache #更新源elseecho "yum已经切换"fi}redhat8d(){release=`cat /etc/redhat-release |grep release | awk -F" " '{print $6}' | awk -F"." '{print $1}'` ; echo "redhat 版本为: $release "case "$release" in"8") echo " 当前匹配redhat 版本为 8"repo="/etc/yum.repos.d/Centos-8.repo"if [ ! -e $repo ]; thencd /etc/yum.repos.d/mkdir bakmv * bakwget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repowget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.reposed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.reposed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repoyum clean all && yum makecacheelseecho "yum已经切换"fi;;*) echo "红帽版本未匹配到,退出!!!";;esac}release=`cat /etc/redhat-release |grep release | awk -F" " '{print $4}' | awk -F"." '{print $1}'` ; echo "centos 版本为: $release "case "$release" in"6") echo " 当前匹配centos 版本为 6"centos6;;"7") echo " 当前匹配centos 版本为 7"centos7;;"8") echo "当前匹配centos 版本为 8"centos8;;*) echo "您的centos过于老旧,正在匹配低版本"centos6d;;esac# 清华 apt 源:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/# centos 6 切换yum: https://help.aliyun.com/document_detail/193569.htm# 一键切换yum执行: wget www.eisc.cn/file/shell/centos-yum.sh ; sh centos-yum.sh# 感谢网友提供yum解决方案:https://developer.aliyun.com/article/748336# 阿里巴巴开源镜像站,镜像仓库: https://developer.aliyun.com/mirror/# 阿里云linux系统镜像: https://mirrors.aliyun.com/centos-vault/1. /etc/yum.repos.d 文件夹里面的文件全部移动到其他目录,重新部署 yum2. 辛苦切换一下yum :https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11Pi5Ktu#---------- alibaba3 -----------#mkdir /yumbackmv /etc/yum.repos.d/* /yumbackwget work.eisc.cn/ruanjian/rpm/yumrepo/alibaba3/AliYun.repo -O /etc/yum.repos.d/al3.repowget work.eisc.cn/ruanjian/rpm/yumrepo/alibaba3/epel.repo -O /etc/yum.repos.d/epel3.repoyum clear all ; yum list#--------- centos8 停止维护,更换yum -------------#停止维护公告:https://help.aliyun.com/noticelist/articleid/1060980265.html更换yum:https://help.aliyun.com/document_detail/405635.html迁移服务器系统:https://help.aliyun.com/document_detail/370865.htm?spm=a2c4g.11186623.0.0.58863201lhpfjW#task-2156316
#!/bin/bashfolder="/eisc/yum" # 定义下载目录mkdir -p $folder # 创建下载目录wgetfile=(https://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpmhttps://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpmhttps://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/python-libs-2.6.6-66.el6_8.i686.rpmhttps://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/python-pycurl-7.19.0-9.el6.x86_64.rpmhttps://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpmhttps://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpmhttps://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpmhttps://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm)iffile="$folder/yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm" # 定义已经存在的文件if [ ! -e $iffile ] # 判断文件 ! 不存在,then 开始 then for ((i=0;i<${#wgetfile[*]};i++)) # i初始为0 数组角标从0开始 # i 范围为 0 到 小于数组个数值,这个区间自增加 # 数组 [*] 符号*指定所有,可以改为0从第一个角标,1表示第二个 # 不加#号表示展示数组元素 do wget -P $folder ${wgetfile[$i]} # wget -P 文件夹 被下载的文件 done else echo "安装文件已经下载!"fi#------- 安装 -------#rpmfile=(`ls $folder`)for((i=0;i<${#rpmfile[*]};i++ )) dorpm -ivh --force --nodeps $folder/${rpmfile[$i]}donecentos7 下载链接:https://mirrors.aliyun.com/centos-vault/7.0.1406/os/x86_64/Packages/脚本执行:wget www.eisc.cn/file/shell/yumnocommand6.sh ; sh yumnocommand6.sh
#------ 301 转跳 ----## 301 访问2.php文件转跳到另一个网站的2.php文件, 删除$1 就不指定文件名, 如果是https 方式 就要将80改为443在nginx配置文件的 server() 板块进行添加 if ($server_port = 80){ rewrite ^(/2.php)$ http://www.eisc.cn$1 permanent; }#---- nginx 转发 反向解析代理--# # nginx 子站点tcp转发server{listen 80;listen 443;server_name www.kbash.cn;location / { proxy_pass http://47.105.46.67; index index.php index.html; }}nginx -s reload # 重载nginx配置#-------------------------等待研究--------------------------------------##PROXY-START/location ~* \.(gif|png|jpg|css|js|woff|woff2)${ proxy_pass http://eisc.cn; proxy_set_header Host tx.kbash.cn; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; expires 12h;}location /{ proxy_pass http://eisc.cn; proxy_set_header Host tx.kbash.cn; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache add_header Cache-Control no-cache;}#PROXY-END/#------------------------------- 官方案例 ---------------------------------------#worker_processes auto;error_log /var/log/nginx/error.log info;events { worker_connections 1024;}stream { upstream backend { hash $remote_addr consistent; server backend1.example.com:12345 weight=5; server 127.0.0.1:12345 max_fails=3 fail_timeout=30s; server unix:/tmp/backend3; } server { listen 12345; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass backend; } server { listen [::1]:12345; proxy_pass unix:/tmp/stream.socket; }}#------------------------- 已成功案例 ---------------------------------user www-data;worker_processes auto;pid /run/nginx.pid;include /etc/nginx/modules-enabled/*.conf;events {worker_connections 768;# multi_accept on;}stream{log_format proxy '$remote_addr [$time_local] ''$status "$upstream_addr"';upstream ipctcp_proxy {hash $remote_addr consistent;server eisc.cn:80 weight=5 max_fails=3 fail_timeout=30s;server eisc.cn:37 weight=5 max_fails=3 fail_timeout=30s;server eisc.cn:55 weight=5 max_fails=3 fail_timeout=30s;}server{error_log /var/log/nginx/error.log;access_log /var/log/nginx/access.log proxy;listen 80;listen 8080;listen 37;listen 55;proxy_connect_timeout 1s;proxy_timeout 3s;proxy_pass ipctcp_proxy;}}
1.ssh keys 自行配置,2. 集群配置ssh 密钥 3.阿里云密钥配置 # 使用密匙秘钥登录服务器chmod 600 1.pem # 使用密匙 1.pem 登录,需要加权限 401 读和执行, # 7=4+2+1 = r + w + x 读+写+执行; Read(4) Write(2) eXecute(1)ssh -i /root/1.pem [email protected] # 使用密匙登录服务器 # 配置远程服务器 sshd 服务开启 密钥和密码登录 流程:再本机生成密匙---> 将本地密匙 发送给远程服务器授权 ---> 本地使用这个密匙远程免密登录目的服务器1. 生成的公共密钥保存在/.ssh/id_rsa.pub 私有密钥保存在 /.ssh/id_rsa 复制 .ssh/id_rsa.pub 文本内容到目标服务器2. 目标服务器:用户家目录创建文件:.ssh/authorized_keys 3. 权限:chmod 600 .ssh/authorized_keys # vim /etc/ssh/sshd_config # 修改sshd 配置文件PasswordAuthentication no # [ˈpɑ ːs wɜː d ɔːˌ θen tɪˈ keɪ ʃn] o fen ti k xin 密码 验证,登录 yes 或者 no ChallengeResponseAuthentication no # yes改为noRSAAuthentication yes # 去掉前面的注释PubkeyAuthentication yes # 去掉前面的注释AuthorizedKeysFile .ssh/authorized_keys # 去掉前面的注释echo "RSAAuthentication yesPubkeyAuthentication yes# 开启密钥登录PermitRootLogin yes开密码登录" >> /etc/ssh/sshd_config # 配置sshd 密钥和密码登录systemctl restart sshd # 重启ssh服务chmod 700 ~/ ; chmod 700 ~/.ssh ; chmod 600 ~/.ssh/authorized_keys # 文件权限,本地和服务器都需要配置#---------------------------- 本地配置ssh密钥,发送到远程服务器进行免密登录 -------------------------------#echo "# 生成密匙对:请一直回车,生成默认空的密匙,也可以参考生成密匙说明"ssh-keygen -t rsa # 在本地生成密钥 # 生成密匙对:一直回车;其中id_rsa 是私钥,id_rsa.pub是公钥 # 密钥和私钥是成对存在的,缺一不可echo "使用ssh秘钥分发 将本地密钥发送给远程服务器授权识别"ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected] # 对方主机地址IPssh [email protected] # 免密直接登录服务器 # ssh keys 生成秘钥说明#------ 命令生成 密匙种类 一直回车确认 ------#ssh-keygen -b 4096 # RSA 无需 -t 指定,-b 指定安全尺寸范围: 1024~16348 # 注意:使用更长的密钥存在收益递减。安全性比 RSA-2048 所提供的更强,应该做的是改用椭圆曲线密码学 ECDSAssh-keygen -t ed25519 # [dʒen] jie m 消息,密钥消息#----------- 案例: ssh-keygen -t rsa -----------#Generating public/private ed25519 key pair. # [ˈdʒe nə reɪ tɪŋ] jie lou rei ting 生成 [ˈpʌ b lɪk] / [ˈp raɪ vɪt] 公共私有 [kiː] [per] 密匙 (一), 两对Enter file in which to save the key (/root/.ssh/id_ed25519): # [ˈentər] en tou 输入 ( 开始) 文件 [faɪl] [ɪn] 在 [wɪtʃ] [tu ] 其中 保存这个密钥 {the 形容词翻译可以省略} # 输入保存密钥的文件。自定义文件名和路径 # 注意:密钥文件名不能重复,否则会覆盖原来的密钥Created directory '/root/.ssh'. # [k ri ˈeɪ tɪ d] kui ei tei te 创建 [də ˈre k tə ri] dou ruai ke tou rui 目录Enter passphrase (empty for no passphrase): # 输入 pass [f reɪ z] 短语,密码短语 [ˈe m pti] en m d 空的 为 没有密码短语。类似于密码加密,建议输入Enter same passphrase again: # 输入 [seɪ m] 相同 密码短语 [əˈ ɡen] ou gen 再一次Your identification has been saved in /root/.ssh/id_ed25519. # 您的 [aɪˌ den tɪ fɪˈkeɪ ʃn] ai den ti fei k xin 标识 [biːn] 曾经,has been 已经。保存在Your public key has been saved in /root/.ssh/id_ed25519.pub. The key fingerprint is: # [ði] 这个 [kiː] k i 密匙,关键, [ˈfɪŋɡəprɪnt] shen ge p len t 指纹 SHA256:xdq0kS22xfwTBo4d3BKD7uUXxtWS/ikPQEQsH7O1lEA [email protected] key's randomart image is: # 3. 阿里云密匙对配置 ECS 管理---网络与安全---密匙对---创建密匙对---查找创建的密匙对,绑定ECS实例控制台操作重启ECS生效参考:https://wangdoc.com/ssh/key.html
#---- 方案一,通过数据库修改管理后他域名 ---#第一步、进入数据库管理,大部分都是phpmyadmin管理,不是的也没事,反正进入到数据库管理就行,找到wp_options数据库表,如下图第二步、编辑选项名称siteurl和home后面的那个地址,如下图第三步、比如我老域名是www.liuhai.net,我现在要改成新域名www.baidu.com,改好选择保存,点执行后如下图通过数据库该域名http://www.liuhai.net/1239.html#----- 其它无效方法 直接忽略----------#找到wordpress中使用的模板中的function.php文件,查找路径如:/wwwroot/wp-content/themes/模板文件/function.phphttps://jingyan.baidu.com/article/afd8f4deaaae0334e386e955.html方法二:重命名登录页找到wp-login.php 更改为自定义的文件名,为了演示的需要,笔者更改为ilovelogin.php然后把ilovelogin.php里面所有wp-login全部替换为ilovelogin然后访问:http://localhost/w/ilovelogin.php 即可访问登录找到你现在所使用的主题,在主题目录中找到functions.php,在这个文件中加入以下代码:update_option(‘siteurl’,’http://你的新域名’);update_option(‘home’,’http://你的新域名’);
#----- 创建专有网络和交换机 ------------##--- 已经存在ecs ---#1. 进入 ecs 服务器 控制台 --- 点击左侧 【实例】 --- 点击顶部切换 【地域】--- 点击实例id 进入ecs 服务器 --- 可以查看 cpu 内存 ip 等信息 --- 下拉 找到【网络信息】 --- 绑定辅助弹性网卡 右边的三个点展开选项 --- 管理ipv6 --- 弹窗出来ipv6 地址 --- 分配新ipv6 --- 弹窗关闭后,复制专有网络id :vpc****2. 开通ipv6 带宽: IPv6网关管理控制台 --- 顶部切换到服务器所在地域 ---- ctrl +f 与 ctrl +v 定位vpc 位置 --- 点击定位左边的 :网关 id 进入 ---- 看到 ipv6 公网带宽 --- 右边点击 : 【开通公网带宽】3. 重点:服务器内部配置 配置IPv6地址 驱动:wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/ipv6/rhel/ecs-utils-ipv6?spm=a2c4g.11186623.0.0.486d6b17mxAJEC -O ipv6 # centos 下载驱动:大写O 下载文件保存为 ipv6 文件名# wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/ipv6/debian/ecs-utils-ipv6?spm=a2c4g.11186623.0.0.486d6b17mxAJEC -O ipv6 # ubuntu/Debian: 下载这个驱动chmod +x ipv6 # 附加执行权限./ipv6 # 执行当前目录下的这个脚本4. 添加安全组规则 ---- 进入ecs 实例 --- 切换地域 ---- 进入ecs 实例 ---- 点击安全组 ---- 如果有多个安全组 建议移除后保留一个 ---点击 【配置规则】--- 入方向手动添加 --- 协议类型 点击选择 ipv6 --- 点击端口范围选择全部 --- 授权对象 : ::/05. 测试ipv6 : ping6 aliyun.comcurl -6 aliyun.com#----------------------------------- 其他注意项 -----------------------------##--- 如果没有 ecs ----#1. 登录: 专有网络控制台2. 顶部选择 地域 --- 创建专有网络--- 名称自定义(只能大小写,不能加特殊符号如:-)3. 左侧导航栏交换机 --- 点击实例id 进入 --- 往下拉云资源管理 --- ecs 加号新增#--- 删除 vpc 专有网络 ----#先删除交换机--- 再 安全组 切换地域 找到并勾选删除 --- 最后删除vpc专有网络 专有网络控制台说明:专有网络的地域和要部署的云资源的地域必须相同,本文选择华北5(呼和浩特)。说明 目前,仅以下地域支持开通IPv6网段:华北1(青岛)、华北2(北京)、华北3(张家口)、华北5(呼和浩特)、华北6(乌兰察布)、华东1(杭州)、华东2(上海)、华南1(深圳)、华南2(河源)、华南3(广州)、西南1(成都)、中国(香港)、新加坡、美国(弗吉尼亚)、德国(法兰克福)。
1.手动安装,2.脚本自动安装 1.手动安装yum install -y ntpdate # 安装时间工具timedatectl set-timezone Asia/Shanghai # 设置时区:亚洲/上海systemctl restart ntpdate # 重新启动ntpsystemctl enable ntpdate # 添加开机启动; system [ˈsɪstəm] 系统; enable [ɛˈnebəl] 启动; cat /etc/redhat-release # 查看系统版本yum install -y wget # 下载工具rpm -Uvh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm # -U upgrade [ʌpˈɡreɪd] 改进 # -v verbose [vəːˈbəʊs] 沉长的;provide more detailed output [prəˈvʌɪd] [mɔr] [ˈdiːteɪld] [ˈaʊtpʊt] 提供更详细的输出 # -h hash [haʃ] 在...什么(打撒,混杂);print hash marks as package installs [mɑːks]标记 [ˈpakɪdʒ] [ɪnˈstɔːl]安装包 ;在软件包安装时打印散列标记wget -rndp /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # wget -O 下载文件到指定目录;此处是替换原有文件systemctl stop firewalld # 关闭防火墙 firewall [ˈfaɪrwɑl]setenforce 0 # 临时关闭selinux;永久关闭:sed -i "s/SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config ; rebootyum -y install httpd mariadb mariadb-server php php-mysql php-bcmath php-mbstring zabbix-server-mysql zabbix-web-mysql zabbix-agent # 安装mariadb 等软件sed -i s/index.html/index.php/g /etc/httpd/conf/httpd.conf # 修改默认访问文件; find / -name "httpd.conf" | grep "etc" # 查找 etc目录下的这个文件 # httpd.conf 修改 index 添加运用:x-httpd-php .php 去过滤grep Add cat -n `find / -name "httpd.conf" | grep etc` | grep "AddType application" # cat -n 查看文件显示行号;`find / -name "httpd.conf" | grep etc` 反单引号是执行结果为一个整体变量;find 查找文件路径 # grep 查找sed -i "272 a\AddType application/x-httpd-php .php" /etc/httpd/conf/httpd.conf # 添加运用的位置 ; a\ 是在指定272行下面插入字符 # 由上个查看行号有四行,任意位置可以添加,我这里是272行cat -n /etc/php.ini | grep "date.timezone" # 查看时间区域行号;我这里是878行sed -i "878 a\date.timezone = Asia/Shanghai" /etc/php.ini systemctl start mariadb # 重启mariadb数据库systemctl enable mariadb # enable [ɛˈnebəl] 启动;开机启动mysql # 默认没有密码,直接mysql 进入数据库;设置密码后需要 mysql -uroot -p密码 进入数据库set password = password('eisccn') ; # 设置密码create database zabbix character set utf8 collate utf8_bin; # create [kriˈet] 创建 ;database [ˈdædəˌbeɪs] 数据库;character [ˈkɛrɪktər] 字符,设置字符类型,collate [kəˈlet] 核对字符 # 登陆数据库,创建库编码为utf8grant all on zabbix.* to 'zabbix'@'localhost' identified by '123' # grant [grænt] 授权;all 所有,on 在...上; 授予zabbix账户在 localhost [ləʊkæl'həʊst] 本机的所有权限; identified [aɪ'dentɪfaɪd] 识别(设置密码) # identified [aɪ'dentɪfaɪd] 标识;by 由 123密码:设置zabbix 的 DBPassword # 123 是密码,需要单引号,数据库账户和本机需要find / -name "create.sql.gz" # 查找数据库文件路径zcat /usr/share/doc/zabbix-server-mysql-4.4.10/create.sql.gz | mysql -uzabbix -p123 zabbix # 将查到的文件导入数据库账户 zabbix 下的库名zabbix下cat -n /etc/zabbix/zabbix_server.conf | grep DBPassword # 查看到是124行sed -i "$NRuser a\DBPassword=123" /etc/zabbix/zabbix_server.conf # 配置密码/usr/bin/systemctl restart httpd zabbix-server zabbix-agent/usr/bin/systemctl enable httpd zabbix-server zabbix-agent # enable [ɛˈnebəl] 启动; 开机启动#################################添加主机####################################rpm -Uvh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpmyum list # 更新yumyum -y install zabbix-agentread -p "请输入Zabbix-serve的ip地址:" server_IPsed -i s/127.0.0.1/$server_IP/g /etc/zabbix/zabbix_agentd.conf /bin/systemctl restart zabbix-agent.service网页操作:ZABBIX 顶部导航栏 ---> 配置 --- 主机群组 --- 创建主机群组 --- 定义名称:ceshi --- 点击添加ZABBIX 顶部导航栏 ---> 配置 --- 主机 --- 创建主机 ---主机名称:zabbix_ceshi 群组: 选择刚创建的 ceshiagent代理程序的接口: 被监控的主机IP地址, 端口10050 保存ZABBIX 顶部导航栏 ---> 配置 --- 主机 --- 模版 --- 选择模板 Template OS Linux by Zabbix agent --- 更新ps aux | grep zabbix # 查看服务是否启动yum install -y telnet # 端口测试工具telnet x.x.x.x 10050 # 测试端口是否联通再到首页查看状态##########################################邮件报警ping监控###################################################systemctl stop firewalld # 关闭防火墙yum install fping -y # 在server和proxy端均安装fpingFpingLocation=/usr/sbin/fping # 在server和proxy端的配置文件里面打开注释telnet hc1.ssh.gs 10050 # ping 端口ZABBIX 顶部导航栏 ---> 配置 --- 主机群组 --- 点击刚刚创建的用户组里的用户zabbix_cesshi --- 监控项 --- 创建监控项名称:ping test类型:简单检查键值:icmpping[43.225.156.172,2,1000,68,3000]主机接口:默认信息类型:数字更新间隔:30s自定义时间间隔:类型:灵活 间隔:50s 期间:默认历史数据保留时长:90d储存时间 :365d查看值:不变应用集:无保存ZABBIX 顶部导航栏 ---> 配置 --- 主机群组 --- 点击刚刚创建的用户组里的用户zabbix_cesshi --- 监控项 --- 触发器 --- 创建触发器名称:fping严重性:警告表达式:选择 ping test保存ZABBIX 顶部导航栏 ---> 配置 --- 主机群组 --- 点击刚刚创建的用户组里的用户zabbix_cesshi --- 图形 --- 创建图形名称:fping监控项 --- 添加 --- ping test添加保存##########################################实现邮件报警功能 server 端口配置###################################################yum install mailx -y # 安装linux邮件工具,在控制节点:server 端进行操作; agent 是被监控端vi /etc/mail.rcset bsdcompatset sendcharsets=iso-8859-1,utf-8set [email protected] smtp=smtp://smtp.exmail.qq.comset [email protected] smtp-auth-password=xxxxxxset smtp-auth=login # 编辑邮件登陆配置信息echo "这是一封测试邮件" | mail -s "zabbix" [email protected] # 测试邮件发送是否正常mkdir -p /data/zabbix_server/data/alertscripts # 创建发邮件发警的脚本所在目录zabbix=`find / -name "zabbix_server.conf"` # 查找zabbix配置文件目录,将结果赋值给zabbix变量cat -n $zabbix | grep "AlertScriptsPath" # 查看需要更改的位置sed -i "517 s/AlertScriptsPath.*/AlertScriptsPath=\/data\/zabbix_server\/data\/alertscripts/g" $zabbix # 517 指定517行的内容进行修改 # sed 修改, 将AlertScriptsPath.* 后面的所有内容修改为:AlertScriptsPath=/data/zabbix_server/data/alertscripts 特殊符号 /,用转译 \systemctl restart zabbix-server.service # 重启服务 vi /data/zabbix_server/data/alertscripts/mailx.sh # 编写发邮件脚本#!/bin/bash#echo "$3" | mail -s "$2" "$1"FILE=/tmp/mailtmp${RANDOM}.txttouch $FILEecho "$3" >$FILEdos2unix -k $FILEmailx -v -s "$2" "$1" < $FILErm -rf $FILEchmod +x /data/zabbix_server/data/alertscripts/mailx.shchown zabbix:zabbix /data/zabbix_server/data/alertscripts/mailx.sh # 脚本增加执行权限sudo -u zabbix /data/zabbix_server/data/alertscripts/mailx.sh [email protected] "zabbix alert" "/etc/passwd is changed" # 测试一封邮件# zabbix页面配置webZABBIX 顶部导航栏 ---> 管理 ---> 报警媒介类型 ---> 创建媒体类型 ---> 名称:agent 报警器类型:脚本脚本名称:mailx.sh脚本参数(增加三个):{ALERT.SENDTO}{ALERT.SUBJECT}{ALERT.MESSAGE}# 创建用户 email 导航栏 --- 管理 --- 用户 --- 右上角创建用户 --- 别名:email 选择群组: Zabbix administrators密码:aaaassss保存# 创建用户组导航栏 --- 管理 --- 用户群组 --- 右上角创建用户群组组名:emailgroup用户(点击选择):email 再点击二级栏目的权限为读写保存# 配置用户报警媒介:导航栏 --- 管理 --- 报警媒介类型 --- 创建媒体类型 --- 类型选择脚本名称:Email脚本类型:脚本脚本名称:mail.sh# 点击添加,保存# alert [əˈlərt] 报警 ; to send [sɛnd tu] 发送到 ; message [ˈmɛsɪdʒ] 消息#用户配置 ZABBIX 顶部导航栏 ---> 管理 ---> 用户 ---> Admin ---> 报警媒介 ---> 添加 ---> 类型:agent 报警器接受人: [email protected]启用时间默认如果存在严重性则使用:全选勾选已启用点击添加# 配置动作ZABBIX 顶部导航栏 ---> 配置 ---> 动作 ---> 创建动作 名称: tcping新的触发条件: 主机 等于 test_centos选择后,再点击已启用上面的【添加】再点击【操作】暂停操作以制止问题操作【新的】发送到用户群组:【添加】【emailgroup】 【zabbix administrator】发送到用户: 【admin】 【email】点击蓝色【添加】上面的【添加】再点击【恢复操作】操作【新的】发送到用户群组:【添加】【emailgroup】 【zabbix administrator】发送到用户: 【admin】 【email】点击蓝色【添加】上面的【添加】再点击下已启用下面的【添加】 总添加完成ZABBIX 顶部导航栏 ---> 管理 --- 用户 --- Admin --- 报警媒介 --- 添加 : 填写收件人:[email protected] 2.脚本安装#!/bin/bash###################check network###################echo '正在检测网络是否和zabbix官方通畅......'ping -c 2 www.zabbix.com > /dev/null # 将ping -c 2 拼两次的消息结果重定向到空洞/dev/null,清除消息记录if [ $? != 0 ];then # $? 是上一个程序执行是否成功的标志,如果执行成功则$? 为0,否则 不为0 echo "请检查网络!" exit # 运行到此情况(网络异常ping不通);就全局退出脚本 [ˈɛgzɪt] exit 出口else echo "网络正常!" # 正常情况不仅仅打印一句话,然后继续往下执行fi###################set yum#################################yum install -y ntpdate ntpdate -u cn.pool.ntp.org timedatectl set-timezone Asia/Shanghai # systemctl start ntpd # start [stɑrt] 开始;开始执行 systemctl enable ntpd # enable [ɛˈnebəl] 启动;加入开启启动#时间矫正rm -rf /var/run/yum.pid # yum.pid 作用:防止启动多个进程副本;此处不需要yum -y install wgetsystem=`cat /etc/redhat-release | awk -F "." '{print $1}'` # release [riˈlis] 发布; system [ˈsɪstəm] 系统 # 查看系统版本,awk字段处理以点为分隔符:打印第一列;将结果赋值给变量 systemif [ "$system" == 'CentOS Linux release 7' ];then # if 判断变量 字符串绝对等于 指定字符串,then 然后执行 rpm -Uvh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm # U更新,升级rpm ;v表示显示安装过程,h表示显示进度 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # wget -O 下载文件到指定目录;此处是替换原有文件 systemctl stop firewalld # 关闭防火墙 firewall [ˈfaɪrwɑl]setenforce 0 # 临时关闭selinuxsed -i "s/SELINUX\=.*/SELINUX=disabled/g" /etc/selinux/config #永久关闭selinux ; disabled [dɪˈsebəld] 废除; config [kən'fɪg] 配置,设置elif [ "$system" == 'CentOS release 6' ];then wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo # base [bes] 基地;mirror [ˈmirəz] 镜像,镜子 rpm -Uvh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm service iptables stopsetenforce 0 # 临时关闭selinuxsed -i "s/SELINUX\=.*/SELINUX=disabled/g" /etc/selinux/config #永久关闭selinux ; disabled [dɪˈsebəld] 废除; config [kən'fɪg] 配置,设置fi##################install###############################eth=`ip a| grep "BROADCAST" | awk -F ":" 'NR==1{print $2}' | sed "s/ //g"` ; echo "网卡名为:"$eth ; # 命令 ip a 查看网卡 过滤;broadcast [ˈbrɔːdkɑːst] >广播;字段的行 # awk -F ":" 以冒号为分隔符 ; 选择第一行,第二列,sed删除空格 # 符号 ; 分号表示第一条命令结束,第二条开始ethCatalog=$(find / -name "*$eth" | grep "/etc/" | sed "s/ //g" ) ; echo "网卡路径为: " $ethCatalog # catalog [ˈkætəlɔg] 目录 # find 查找网卡名称的路径,grep 过滤/etc 目录下网卡名称。sed删除空格ip=$(cat $ethCatalog | grep IPADDR | awk -F "=" 'NR==1{print $2}' | sed "s/ //g") ; echo "IP地址为: " $ip # 查看网卡文件,过滤IPADDR的行,awk -F"=" 分隔符是冒号,打印第一行第二列sleep 5 # 等待5秒钟;sleep [slip] 睡眠server(){yum -y install httpd mariadb mariadb-server php php-mysql php-bcmath php-mbstringyum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent # 安装mariadb 等软件sed -i s/index.html/index.php/g /etc/httpd/conf/httpd.conf # 修改默认访问文件#######################修改配置文件################### sed -i "N;286i\AddType application/x-httpd-php .php" /etc/httpd/conf/httpd.conf# sed -i "N;880i\date.timezone = Asia/Shanghai" /etc/php.iniNRhttpd=$(cat -n /etc/httpd/conf/httpd.conf | grep "AddType application/x-gzip .gz .tgz" | awk -F" " '{print $1}' | sed "s/ //g") # add type [æd] [taɪp] 添加类型; application [ˌæpləˈkeʃən] 运用; # cat -n 查看文件内容并显示行号 # grep 匹配字符串所在行的整行内容 # awk -F" " 字段处理指定分隔符为空格,打印第一列;删除空格echo "根据字符串查找的文本中的行号:"$NRsed -i "/AddType application\/x-httpd-php .php/d" /etc/httpd/conf/httpd.conf # 在写入前,先删除将要插入的字符串,保证不会重复插入sed -i "$NRhttpd a\AddType application/x-httpd-php .php" /etc/httpd/conf/httpd.conf # $NR a\ 根据查找到行号,的下一行插入字符串 # i\ 是上一行插入字符串NRdate=`cat -n /etc/php.ini | grep ";date.timezone =" | awk -F" " '{print $1}' | sed "s/ //g"` ; echo $NRdatesed -i "/Asia\/Shanghai/d" /etc/php.inised -i "$NRdate a\date.timezone = Asia/Shanghai" /etc/php.ini # 其中符号 ; 表示注释符号。####################################################/usr/bin/systemctl start mariadb # 重启mariadb数据库/usr/bin/systemctl enable mariadb # enable [ɛˈnebəl] 启动;开机启动mysql -e "set password = password('WWWeisccn111@#')" # 进入数据库设置密码mysql -uroot -pWWWeisccn111@# -e "create database zabbix character set utf8 collate utf8_bin;" # create [kriˈet] 创建 ;database [ˈdædəˌbeɪs] 数据库;character [ˈkɛrɪktər] 字符,设置字符类型,collate [kəˈlet] 核对字符 # 登陆数据库,创建库编码为utf8mysql -uroot -pWWWeisccn111@# -e "grant all on zabbix.* to 'zabbix'@'localhost' identified by '123'" # grant [grænt] 授权;all 所有,on 在...上; 授予zabbix账户在 localhost [ləʊkæl'həʊst] 本机的所有权限; identified [aɪ'dentɪfaɪd] 识别(设置密码) # identified [aɪ'dentɪfaɪd] 标识;by 由 123密码:设置zabbix 的 DBPassword # 123 是密码,需要单引号,数据库账户和本机需要# 此处已经修改bugfind查看数据库文件createmysql=$(find / -name "create.sql.gz") ; echo "$createmysql 数据库文件导入中,请耐心等待!" # 查找文件路径并打印/usr/bin/zcat $createmysql | mysql -uzabbix -p123 zabbix # 导入数据库,登陆数据,用户名zabbix 密码123,并且进入数据库zabbix # zcat 查看压缩包的文件,管道到登陆数据库里面去执行# sed -i "N;110i\DBPassword=123" /etc/zabbix/zabbix_server.conf # 配置zabbix密码NRuser=`cat -n /etc/zabbix/zabbix_server.conf | grep "DBUser=zabbix" |awk '{print $1}' | sed "s/ //g"` ; echo $NRusersed -i "/DBPassword=123/d" /etc/zabbix/zabbix_server.confsed -i "$NRuser a\DBPassword=123" /etc/zabbix/zabbix_server.conf/usr/bin/systemctl restart httpd zabbix-server zabbix-agent/usr/bin/systemctl enable httpd zabbix-server zabbix-agent # enable [ɛˈnebəl] 启动; 开机启动echo "请用浏览器访问:http://$ip/zabbix安装配置:数据库名:zabbix数据库用户:zabbix密码:123登陆账户/密码:Admin/zabbix"}agent(){yum -y install zabbix-agentread -p "请输入Zabbix-serve的ip地址:" server_IPsed -i s/127.0.0.1/$server_IP/g /etc/zabbix/zabbix_agentd.conf /bin/systemctl restart zabbix-agent.service}##################install menu###########################MYDATE=`date +%d/%m/%y` # 定义一个时间变量:格式化字符为:十进制日期,月份,年份抹除100THIS_HOST=`hostname -s`USER=`whoami`while :do tput clear echo " # cat 与echo 相似,这里打印显示一段话;由 aMAYDAY 开始,也由它来结束;---------------------------------------------------------User:$USER Host:$THIS_HOST Date:$MYDATE# cat 这里直接打印字符串和变量的值--------------------------------------------------------- 1:安装 zabbix-server和zabbix-agent 2:只安装 zabbix-agent H:帮助 Q:退出---------------------------------------------------------" # 结束打印标记echo -e -n "\tYour Choice [1,2,Q]>" # -e 开启特殊字符转换 \t上一行换行;-n 它的下一行不换行打印;read CHOICE # 紧接着上一行的打印字符串,接着让用户输入信息,将输入信息写入变量 $CHOICE case $CHOICE in # 判断变量是一下情形 1) server # 为 1 执行 server 函数 ;; 2) agent ;; 3) who ;; H|h) # 输入为 H 则打印一段话 echo " Zabbix-server是服务端,Zabbix-agent是客户端!" # 打印结束,MAYDAY 他为开始,也以他为结束 ;; Q|q) exit 0 # 输入Q 退出 ;; *) echo -e "\t\007 输入有有误!" # 其他所有情况,提示 ;; esac # case 判断结束echo -e -n "\t按任意键返回菜单!"read DUMMYdone# 脚本执行: yum install -y wget ; rm -rf zabbix.sh ; wget eisc.cn/file/shell/zabbix.sh ; chmod 755 zabbix.sh ; source zabbix.sh
【漏洞公告】CVE-2016-10009:OpenSSH远程代码执行漏洞#---- 1. 升级 zlib ----#wget wget http://zlib.net/zlib-1.2.11.tar.gztar zxvf zlib-1.2.11.tar.gzcd zlib-1.2.11./configuremakemake installll /usr/local/lib # 查看版本#---- 升级openssl-flips ----#wget https://www.openssl.org/source/openssl-fips-2.0.14.tar.gztar zxvf openssl-fips-2.0.14.tar.gzcd openssl-fips-2.0.14./configmakemake install#------- 升级openssl ---------#wget https://www.openssl.org/source/openssl-1.0.2i.tar.gztar zxvf openssl-1.0.2i.tar.gzcd openssl-1.0.2i./configmakemake installln -s /usr/local/lib64/libssl.so.1.0 /usr/lib64/libssl.so.1.0ln -s /usr/local/lib64/libcrypto.so.1.0 /usr/lib64/libcrypto.so.1.0ln -s /usr/local/ssl/bin/openssl /usr/bin/opensslyum install pam* -y#-------- 安装 openssh ---------#wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gztar zxvf openssh-7.4p1.tar.gzcd openssh-7.4p1./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-privsep-path=/var/lib/sshd --with-ssl-dir=/usr/local/lib64 --without-hardeningmakemake install# 备份sshd文件,重命名为sshd_20170209_oldmv /etc/init.d/sshd /etc/init.d/sshd_20170209_old# 复制配置文件、赋权、添加到开机启动项cd /root/openssh-7.4p1/contrib/redhatcp sshd.init /etc/init.d/sshdcp ssh_config /etc/ssh/ssh_config# 根据提示,输入y进行覆盖(若对原文件重命名,则无需覆盖)cp -p sshd_config /etc/ssh/sshd_config# 根据提示,输入y进行覆盖(若对原文件重命名,则无需覆盖)chmod u+x /etc/init.d/sshdchkconfig --add sshdchkconfig sshd on# 重启sshd服务service sshd restart#------ 查看版本 ------#ssh -VOpenSSH_7.4p1, OpenSSL 1.0.2i 22 Sep 2016https://help.aliyun.com/document_detail/48573.htm
vi /etc/ssh/sshd_configDenyUsers root # 再sshd 配置文件底部写入禁止admin 远程sshd 登录AllowUsers eisc root # 允许用户登录:eisc 和 rootsystemctl restart sshd # 重启sshd 服务普通用户添加 sudo 超级权限再 /etc/sudoers 文件添加底部:eisc ALL=(ALL) ALL表示:eisc用户拥有sudo超级权限
您可以找到 之前的数据库文件。一般是 /www/server/data 这个目录下文件。通过 cp 复制部分数据库文件,但是.pid 无法直接使用,只能将其移动到其他目录后再进行拷贝到现有文件。然后重新新建数据名称您将数据库文件复制到到现有数据库目录后,将目录授权给mysql ,宝塔新建数据库。chown -R mysql:mysql /www/server/data参考卸载数据盘:https://help.aliyun.com/document_detail/25447.html云盘使用完了卸载云盘,释放拷贝完了不需要的云盘:https://help.aliyun.com/document_detail/33828.html
def modify_file(file_path, replacements):
with open(file_path, 'r') as file:
content = file.read()
for old_value, new_value in replacements.items():
content = content.replace(old_value, new_value)
with open(file_path, 'w') as file:
file.write(content)
# 定义需要替换的内容和对应的新值
replacements = {
'old_value1': 'new_value1',
'old_value2': 'new_value2',
'old_value3': 'new_value3'
# 指定文件路径
file_path = 'path/to/your/file.txt'
# 调用函数修改文件
modify_file(file_path, replacements)
Select Installation ModeWhich components should be installed?If Normal Installation is choosen than VBFConvert will be installed with normal logfeatures. If Advanced Installation is choosen than VBFConvert will be installed withextended log features.This should be used only to report errors when the NormalInstallation is not working!Normal Installation [ˈnɔːml] [ˌɪnstəˈleɪʃn] 正常 安装
# centos 安装 vscode 配置 gcc g++ cmake 开发环境
vscodeUrl="http://work.eisc.cn/ruanjian/ubuntu/server/"
dir="/datadisk/eisc/download/cmake"
installDir="/datadisk/eisc/server"
debList=(
cmake-3.27.0-rc3.tar.gz
make-4.4.tar.gz
gcc-12.3.0.tar.gz
downloadGF=(
https://ftp.gnu.org/gnu/gcc/gcc-12.3.0/gcc-12.3.0.tar.gz
https://ftp.gnu.org/gnu/make/make-4.4.tar.gz
debrun=(
cmake3
make4
gcc12
if [ $USER="root" ]
qx=" "
qx="sudo"
xitong=` cat /etc/os-release | grep -w ID | awk -F"=" '{print $2}' | sed "s/\"//g" `
case "$xitong" in
"centos" ) iCMD="yum" ; rpmCMD="rpm -qa " ; echo "当前是 centos 系统" ;;
"ubuntu" ) iCMD="apt" ; rpmCMD="dpkg -l " ; echo "当前是 ubuntu 系统" ;;
$qx $iCMD install -y openssl-devel gcc gcc-c++ g++ cmake make wget
$qx mkdir -p $dir $installDir ; $qx chmod 777 $dir $installDir; cd $dir
download()
for i in ${debList[*]}
debname=`echo $i | awk -F".tar.gz" '{print $1}'`
debnameInstalled=`$qx $rpmCMD | grep -w "ii $debname"`
debnameInstalledLength=${#debnameInstalled}
$qx mkdir -p $installDir/$debname
if [ $debnameInstalledLength -gt 1 ]
echo "[ok] 该包 $i 已经安装,安装信息: $debnameInstalled"
installIF=0
installIF=1
echo "[runing] 正在检查是否下载安装包: $i"
if [ ! -e $i ]
echo "[runing] 当前没有下载,正在下载包:$i"
$qx wget $vscodeUrl/$i
echo "[running] 正在解压 $i 到目录: $installDir/$debname "
$qx tar -xzvf $i -C $installDir
echo "[ok] 已经下载: $i "
debinstall(){
for((i=0;i<=${#debrun[*]};i++))
if [ ! -e /bin/${debrun[$i]} ]
debname=`echo ${debList[$i]} | awk -F".tar.gz" '{print $1}'`
echo "[waring] 包没有安装 ${debList[$i]} 正在安装 文件不存在: /bin/${debrun[$i]} " ; ls /bin/${debrun[$i]} ; sleep 3;
cd $installDir/$debname ; $qx ./configure ; $qx make install ; $qx rm -rf /bin/${debrun[$i]}
$qx ln -s $installDir/$debname/bin/${debrun[$i]} /bin/${debrun[$i]}
echo "已经安装: ${debrun[$i]}"
download ; debinstall
# 一键部署: wget eisc.cn/file/ubuntu/shell/server/cmakegcc.sh ; sudo chmod +x cmakegcc.sh ; ./cmakegcc.sh
// c 语言 if 比较符+运算符
static uint32_t a; // static 静态,1. 隐藏:不能跨文件使用,2. 存储在静态存储区:全局变量 和 static 变量(和全局变量一些写入内存跨函数可读)
static uint32_t b; // 作用:3. 默认初始化为 0
int functionTest()
a = 0x00000800;
b = 0x00000400;
if(0x00000100>a | 0x00000100>b) // 先判断 左右两边任意一个成立, 再进行变量想或计算,再判断相或 是否大于0
printf("++++++++++++++++++ \n ");
printf("------------------");
return 0;
int main()
printf("\n 第一次: a=%lx \n",a );
functionTest(); // 执行函数后,可以获取该函数中 变量的值
printf("\n 第二次: a=%lx \n",a ); // 中的 x 是16进制,l意思是长整型十六进制
#----------------- Canoe 使用 ------------------------#
1. 打开 Canoe -> 将日志 blf 拖进 Trace -> 导入数据库 : 顶部 View -> Simulation Set up -> Networkks -> CAN Networks ->
-> CAN -> Databases -> 鼠标右键 Add -> 导入 DBC 文件
2. 导入dbc 和设置离线
顶部设置: View -> Measurement Setup -> 右键将 Online 切换到 Offline 离线 ->
-> 底部 Configuration -> Logging 双击 CANOE 选择输出文件路径 ->
-> 导入dbc 顶部 或 View 中的 Simulation -> Simulation Setup 右边can databases 导入数据库
3. 添加Graphics窗口:顶部 Analysis – Graphics 或 顶部 View -> Graphics
添加信号:Graphics窗口 -> name 栏 鼠标右键 -> Add Signal 右边有望远镜搜索
点击 双曲线 -> 点击 右边倒数第4个图形下拉框,选择 多个不重叠
设置后,点击 Start 启动#-------- CANoe 安装 ------#
# 作用: 分析Pcan 抓的日志,将 dbf 转换之前的 dbc 数据库导入分析日志
1. 下载地址: CANoe10.0.rar
注意: 建议安装 CANoe10.0 , 因为 CANoe8.0 安装有问题
解压后 -> 点击 autorun.exe -> 提示缺少包,点击下一步会自动安装 -> 等待提示安装窗口结束,然后退出初始安装窗口 Exit
-> 被遮挡的 填写注册码安装窗口,输入下面信息,进行安装。 如果出现 处理 .net 一直没动,继续等待。可能磁盘读写速度慢。 或者重新安装
填写注册码:
Chongqing University of Posts
Key:YNS2-EI6W-HW3W-VDMS-8PPB-5EP4-SILS-1DG6
Serial Number:50000022992
#-------- CANoe 使用 ------#
打开 CANoe ,目录:CANoe\Exec64\CANoe64.exe 最大化软件窗口
1. 导入日志文件:
-> 在初始窗口 Trace 将日志文件 拖动到 Trace 窗口
-> 点击左下角 Configuration -> 在窗口 Measurement Setup 界面 点击 online 切换到 Offline 离线模式; 最左边第一个图(类似文件桶) -> 双击或右键 -> Show Window ->
-> 弹出 Lost of log files to be played 或者 Offline Mode 界面 -> 点击 + 号 Add Logging 导入日志 ALL.asc 文件; 如果需要重新添加 需要x掉之前的
2. 导入 dbc 数据库:
-> 点击左下角 Configuration -> 在窗口 Simulation Setup -> Networks -> CAN Networks -> CAN
-> Databases -> 鼠标右键 Add -> 打开 dbc 数据库文件(参数定义文件,与 参数定义表相似) ->
-> 在 Measurement Setup 界面 -> 右键点击 Online 切换到 Offine 离线模式
3. 分析日志:
-> 点击导航栏 Start -> 点击导航栏底部 -> Analysis -> 最大化 Graphics 图像化窗口 -> 左边状态栏 右键点击 Add Signals...
-> DBC_COCAN_V11_20220810 -> Frames -> IPK_STS -> IPK_EPS_IMCorrelativeMode -> ok
# https://github.com/Nyr/openvpn-install
vpnGW="10.1.1.0"
# Detect Debian users running the script with "sh" instead of bash
if readlink /proc/$$/exe | grep -q "dash"; then
echo 'This installer needs to be run with "bash", not "sh".'
# Discard stdin. Needed when running from an one-liner which includes a newline
read -N 999999 -t 0.001
# Detect OpenVZ 6
if [[ $(uname -r | cut -d "." -f 1) -eq 2 ]]; then
echo "The system is running an old kernel, which is incompatible with this installer."
# Detect OS
# $os_version variables aren't always in use, but are kept here for convenience
if grep -qs "ubuntu" /etc/os-release; then
os="ubuntu"
os_version=$(grep 'VERSION_ID' /etc/os-release | cut -d '"' -f 2 | tr -d '.')
group_name="nogroup"
elif [[ -e /etc/debian_version ]]; then
os="debian"
os_version=$(grep -oE '[0-9]+' /etc/debian_version | head -1)
group_name="nogroup"
elif [[ -e /etc/almalinux-release || -e /etc/rocky-release || -e /etc/centos-release ]]; then
os="centos"
os_version=$(grep -shoE '[0-9]+' /etc/almalinux-release /etc/rocky-release /etc/centos-release | head -1)
group_name="nobody"
elif [[ -e /etc/fedora-release ]]; then
os="fedora"
os_version=$(grep -oE '[0-9]+' /etc/fedora-release | head -1)
group_name="nobody"
echo "This installer seems to be running on an unsupported distribution.
Supported distros are Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS and Fedora."
if [[ "$os" == "ubuntu" && "$os_version" -lt 1804 ]]; then
echo "Ubuntu 18.04 or higher is required to use this installer.
This version of Ubuntu is too old and unsupported."
if [[ "$os" == "debian" && "$os_version" -lt 9 ]]; then
echo "Debian 9 or higher is required to use this installer.
This version of Debian is too old and unsupported."
if [[ "$os" == "centos" && "$os_version" -lt 7 ]]; then
echo "CentOS 7 or higher is required to use this installer.
This version of CentOS is too old and unsupported."
# Detect environments where $PATH does not include the sbin directories
if ! grep -q sbin <<< "$PATH"; then
echo '$PATH does not include sbin. Try using "su -" instead of "su".'
if [[ "$EUID" -ne 0 ]]; then
echo "This installer needs to be run with superuser privileges."
if [[ ! -e /dev/net/tun ]] || ! ( exec 7<>/dev/net/tun ) 2>/dev/null; then
echo "The system does not have the TUN device available.
TUN needs to be enabled before running this installer."
new_client () {
# Generates the custom client.ovpn
cat /etc/openvpn/server/client-common.txt
echo ""
cat /etc/openvpn/server/easy-rsa/pki/ca.crt
echo ""
echo ""
sed -ne '/BEGIN CERTIFICATE/,$ p' /etc/openvpn/server/easy-rsa/pki/issued/"$client".crt
echo ""
echo ""
cat /etc/openvpn/server/easy-rsa/pki/private/"$client".key
echo ""
echo ""
sed -ne '/BEGIN OpenVPN Static key/,$ p' /etc/openvpn/server/tc.key
echo ""
} > ~/"$client".ovpn
if [[ ! -e /etc/openvpn/server/server.conf ]]; then
# Detect some Debian minimal setups where neither wget nor curl are installed
if ! hash wget 2>/dev/null && ! hash curl 2>/dev/null; then
echo "Wget is required to use this installer."
read -n1 -r -p "Press any key to install Wget and continue..."
apt-get update
apt-get install -y wget
clear
echo 'Welcome to this OpenVPN road warrior installer!'
# If system has a single IPv4, it is selected automatically. Else, ask the user
if [[ $(ip -4 addr | grep inet | grep -vEc '127(\.[0-9]{1,3}){3}') -eq 1 ]]; then
ip=$(ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}')
number_of_ip=$(ip -4 addr | grep inet | grep -vEc '127(\.[0-9]{1,3}){3}')
echo "Which IPv4 address should be used?"
ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | nl -s ') '
read -p "IPv4 address [1]: " ip_number
until [[ -z "$ip_number" || "$ip_number" =~ ^[0-9]+$ && "$ip_number" -le "$number_of_ip" ]]; do
echo "$ip_number: invalid selection."
read -p "IPv4 address [1]: " ip_number
[[ -z "$ip_number" ]] && ip_number="1"
ip=$(ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | sed -n "$ip_number"p)
# If $ip is a private IP address, the server must be behind NAT
if echo "$ip" | grep -qE '^(10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.|192\.168)'; then
echo "This server is behind NAT. What is the public IPv4 address or hostname?"
# Get public IP and sanitize with grep
get_public_ip=$(grep -m 1 -oE '^[0-9]{1,3}(\.[0-9]{1,3}){3}$' <<< "$(wget -T 10 -t 1 -4qO- "http://ip1.dynupdate.no-ip.com/" || curl -m 10 -4Ls "http://ip1.dynupdate.no-ip.com/")")
read -p "Public IPv4 address / hostname [$get_public_ip]: " public_ip
# If the checkip service is unavailable and user didn't provide input, ask again
until [[ -n "$get_public_ip" || -n "$public_ip" ]]; do
echo "Invalid input."
read -p "Public IPv4 address / hostname: " public_ip
[[ -z "$public_ip" ]] && public_ip="$get_public_ip"
# If system has a single IPv6, it is selected automatically
if [[ $(ip -6 addr | grep -c 'inet6 [23]') -eq 1 ]]; then
ip6=$(ip -6 addr | grep 'inet6 [23]' | cut -d '/' -f 1 | grep -oE '([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}')
# If system has multiple IPv6, ask the user to select one
if [[ $(ip -6 addr | grep -c 'inet6 [23]') -gt 1 ]]; then
number_of_ip6=$(ip -6 addr | grep -c 'inet6 [23]')
echo "Which IPv6 address should be used?"
ip -6 addr | grep 'inet6 [23]' | cut -d '/' -f 1 | grep -oE '([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}' | nl -s ') '
read -p "IPv6 address [1]: " ip6_number
until [[ -z "$ip6_number" || "$ip6_number" =~ ^[0-9]+$ && "$ip6_number" -le "$number_of_ip6" ]]; do
echo "$ip6_number: invalid selection."
read -p "IPv6 address [1]: " ip6_number
[[ -z "$ip6_number" ]] && ip6_number="1"
ip6=$(ip -6 addr | grep 'inet6 [23]' | cut -d '/' -f 1 | grep -oE '([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}' | sed -n "$ip6_number"p)
echo "Which protocol should OpenVPN use?"
echo " 1) UDP (recommended)"
echo " 2) TCP"
read -p "Protocol [1]: " protocol
until [[ -z "$protocol" || "$protocol" =~ ^[12]$ ]]; do
echo "$protocol: invalid selection."
read -p "Protocol [1]: " protocol
case "$protocol" in
1|"")
protocol=udp
protocol=tcp
echo "What port should OpenVPN listen to?"
read -p "Port [1194]: " port
until [[ -z "$port" || "$port" =~ ^[0-9]+$ && "$port" -le 65535 ]]; do
echo "$port: invalid port."
read -p "Port [1194]: " port
[[ -z "$port" ]] && port="1194"
echo "Select a DNS server for the clients:"
echo " 1) Current system resolvers"
echo " 2) Google"
echo " 3) 1.1.1.1"
echo " 4) OpenDNS"
echo " 5) Quad9"
echo " 6) AdGuard"
read -p "DNS server [1]: " dns
until [[ -z "$dns" || "$dns" =~ ^[1-6]$ ]]; do
echo "$dns: invalid selection."
read -p "DNS server [1]: " dns
echo "Enter a name for the first client:"
read -p "Name [client]: " unsanitized_client
# Allow a limited set of characters to avoid conflicts
client=$(sed 's/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-]/_/g' <<< "$unsanitized_client")
[[ -z "$client" ]] && client="client"
echo "OpenVPN installation is ready to begin."
# Install a firewall if firewalld or iptables are not already available
if ! systemctl is-active --quiet firewalld.service && ! hash iptables 2>/dev/null; then
if [[ "$os" == "centos" || "$os" == "fedora" ]]; then
firewall="firewalld"
# We don't want to silently enable firewalld, so we give a subtle warning
# If the user continues, firewalld will be installed and enabled during setup
echo "firewalld, which is required to manage routing tables, will also be installed."
elif [[ "$os" == "debian" || "$os" == "ubuntu" ]]; then
# iptables is way less invasive than firewalld so no warning is given
firewall="iptables"
read -n1 -r -p "Press any key to continue..."
# If running inside a container, disable LimitNPROC to prevent conflicts
if systemd-detect-virt -cq; then
mkdir /etc/systemd/system/[email protected]/ 2>/dev/null
echo "[Service]
LimitNPROC=infinity" > /etc/systemd/system/[email protected]/disable-limitnproc.conf
if [[ "$os" = "debian" || "$os" = "ubuntu" ]]; then
apt-get update
apt-get install -y --no-install-recommends openvpn openssl ca-certificates $firewall
elif [[ "$os" = "centos" ]]; then
yum install -y epel-release
yum install -y openvpn openssl ca-certificates tar $firewall
# Else, OS must be Fedora
dnf install -y openvpn openssl ca-certificates tar $firewall
# If firewalld was just installed, enable it
if [[ "$firewall" == "firewalld" ]]; then
systemctl enable --now firewalld.service
# Get easy-rsa
easy_rsa_url='https://github.com/OpenVPN/easy-rsa/releases/download/v3.1.2/EasyRSA-3.1.2.tgz'
mkdir -p /etc/openvpn/server/easy-rsa/
{ wget -qO- "$easy_rsa_url" 2>/dev/null || curl -sL "$easy_rsa_url" ; } | tar xz -C /etc/openvpn/server/easy-rsa/ --strip-components 1
chown -R root:root /etc/openvpn/server/easy-rsa/
cd /etc/openvpn/server/easy-rsa/
# Create the PKI, set up the CA and the server and client certificates
./easyrsa --batch init-pki
./easyrsa --batch build-ca nopass
./easyrsa --batch --days=3650 build-server-full server nopass
./easyrsa --batch --days=3650 build-client-full "$client" nopass
./easyrsa --batch --days=3650 gen-crl
# Move the stuff we need
cp pki/ca.crt pki/private/ca.key pki/issued/server.crt pki/private/server.key pki/crl.pem /etc/openvpn/server
# CRL is read with each client connection, while OpenVPN is dropped to nobody
chown nobody:"$group_name" /etc/openvpn/server/crl.pem
# Without +x in the directory, OpenVPN can't run a stat() on the CRL file
chmod o+x /etc/openvpn/server/
# Generate key for tls-crypt
openvpn --genkey --secret /etc/openvpn/server/tc.key
# Create the DH parameters file using the predefined ffdhe2048 group
echo '-----BEGIN DH PARAMETERS-----
MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz
+8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a
87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7
YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi
7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD
ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
-----END DH PARAMETERS-----' > /etc/openvpn/server/dh.pem
# Generate server.conf
echo "local $ip
port $port
proto $protocol
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh.pem
auth SHA512
tls-crypt tc.key
topology subnet
server $vpnGW 255.255.255.0" > /etc/openvpn/server/server.conf
# IPv6
if [[ -z "$ip6" ]]; then
echo 'push "redirect-gateway def1 bypass-dhcp"' >> /etc/openvpn/server/server.conf
echo 'server-ipv6 fddd:1194:1194:1194::/64' >> /etc/openvpn/server/server.conf
echo 'push "redirect-gateway def1 ipv6 bypass-dhcp"' >> /etc/openvpn/server/server.conf
echo 'ifconfig-pool-persist ipp.txt' >> /etc/openvpn/server/server.conf
# DNS
case "$dns" in
1|"")
# Locate the proper resolv.conf
# Needed for systems running systemd-resolved
if grep '^nameserver' "/etc/resolv.conf" | grep -qv '127.0.0.53' ; then
resolv_conf="/etc/resolv.conf"
resolv_conf="/run/systemd/resolve/resolv.conf"
# Obtain the resolvers from resolv.conf and use them for OpenVPN
grep -v '^#\|^;' "$resolv_conf" | grep '^nameserver' | grep -v '127.0.0.53' | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | while read line; do
echo "push \"dhcp-option DNS $line\"" >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 8.8.8.8"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 8.8.4.4"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 1.1.1.1"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 1.0.0.1"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 208.67.222.222"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 208.67.220.220"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 9.9.9.9"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 149.112.112.112"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 94.140.14.14"' >> /etc/openvpn/server/server.conf
echo 'push "dhcp-option DNS 94.140.15.15"' >> /etc/openvpn/server/server.conf
echo 'push "block-outside-dns"' >> /etc/openvpn/server/server.conf
echo "keepalive 10 120
cipher AES-256-CBC
user nobody
group $group_name
persist-key
persist-tun
verb 3
crl-verify crl.pem" >> /etc/openvpn/server/server.conf
if [[ "$protocol" = "udp" ]]; then
echo "explicit-exit-notify" >> /etc/openvpn/server/server.conf
# Enable net.ipv4.ip_forward for the system
echo 'net.ipv4.ip_forward=1' > /etc/sysctl.d/99-openvpn-forward.conf
# Enable without waiting for a reboot or service restart
echo 1 > /proc/sys/net/ipv4/ip_forward
if [[ -n "$ip6" ]]; then
# Enable net.ipv6.conf.all.forwarding for the system
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.d/99-openvpn-forward.conf
# Enable without waiting for a reboot or service restart
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
if systemctl is-active --quiet firewalld.service; then
# Using both permanent and not permanent rules to avoid a firewalld
# reload.
# We don't use --add-service=openvpn because that would only work with
# the default port and protocol.
firewall-cmd --add-port="$port"/"$protocol"
firewall-cmd --zone=trusted --add-source=$vpnGW/24
firewall-cmd --permanent --add-port="$port"/"$protocol"
firewall-cmd --permanent --zone=trusted --add-source=$vpnGW/24
# Set NAT for the VPN subnet
firewall-cmd --direct --add-rule ipv4 nat POSTROUTING 0 -s $vpnGW/24 ! -d $vpnGW/24 -j SNAT --to "$ip"
firewall-cmd --permanent --direct --add-rule ipv4 nat POSTROUTING 0 -s $vpnGW/24 ! -d $vpnGW/24 -j SNAT --to "$ip"
if [[ -n "$ip6" ]]; then
firewall-cmd --zone=trusted --add-source=fddd:1194:1194:1194::/64
firewall-cmd --permanent --zone=trusted --add-source=fddd:1194:1194:1194::/64
firewall-cmd --direct --add-rule ipv6 nat POSTROUTING 0 -s fddd:1194:1194:1194::/64 ! -d fddd:1194:1194:1194::/64 -j SNAT --to "$ip6"
firewall-cmd --permanent --direct --add-rule ipv6 nat POSTROUTING 0 -s fddd:1194:1194:1194::/64 ! -d fddd:1194:1194:1194::/64 -j SNAT --to "$ip6"
# Create a service to set up persistent iptables rules
iptables_path=$(command -v iptables)
ip6tables_path=$(command -v ip6tables)
# nf_tables is not available as standard in OVZ kernels. So use iptables-legacy
# if we are in OVZ, with a nf_tables backend and iptables-legacy is available.
if [[ $(systemd-detect-virt) == "openvz" ]] && readlink -f "$(command -v iptables)" | grep -q "nft" && hash iptables-legacy 2>/dev/null; then
iptables_path=$(command -v iptables-legacy)
ip6tables_path=$(command -v ip6tables-legacy)
echo "[Unit]
Before=network.target
[Service]
Type=oneshot
ExecStart=$iptables_path -t nat -A POSTROUTING -s $vpnGW/24 ! -d $vpnGW/24 -j SNAT --to $ip
ExecStart=$iptables_path -I INPUT -p $protocol --dport $port -j ACCEPT
ExecStart=$iptables_path -I FORWARD -s $vpnGW/24 -j ACCEPT
ExecStart=$iptables_path -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
ExecStop=$iptables_path -t nat -D POSTROUTING -s $vpnGW/24 ! -d $vpnGW/24 -j SNAT --to $ip
ExecStop=$iptables_path -D INPUT -p $protocol --dport $port -j ACCEPT
ExecStop=$iptables_path -D FORWARD -s $vpnGW/24 -j ACCEPT
ExecStop=$iptables_path -D FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT" > /etc/systemd/system/openvpn-iptables.service
if [[ -n "$ip6" ]]; then
echo "ExecStart=$ip6tables_path -t nat -A POSTROUTING -s fddd:1194:1194:1194::/64 ! -d fddd:1194:1194:1194::/64 -j SNAT --to $ip6
ExecStart=$ip6tables_path -I FORWARD -s fddd:1194:1194:1194::/64 -j ACCEPT
ExecStart=$ip6tables_path -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
ExecStop=$ip6tables_path -t nat -D POSTROUTING -s fddd:1194:1194:1194::/64 ! -d fddd:1194:1194:1194::/64 -j SNAT --to $ip6
ExecStop=$ip6tables_path -D FORWARD -s fddd:1194:1194:1194::/64 -j ACCEPT
ExecStop=$ip6tables_path -D FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT" >> /etc/systemd/system/openvpn-iptables.service
echo "RemainAfterExit=yes
[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/openvpn-iptables.service
systemctl enable --now openvpn-iptables.service
# If SELinux is enabled and a custom port was selected, we need this
if sestatus 2>/dev/null | grep "Current mode" | grep -q "enforcing" && [[ "$port" != 1194 ]]; then
# Install semanage if not already present
if ! hash semanage 2>/dev/null; then
if [[ "$os_version" -eq 7 ]]; then
# Centos 7
yum install -y policycoreutils-python
# CentOS 8 or Fedora
dnf install -y policycoreutils-python-utils
semanage port -a -t openvpn_port_t -p "$protocol" "$port"
# If the server is behind NAT, use the correct IP address
[[ -n "$public_ip" ]] && ip="$public_ip"
# client-common.txt is created so we have a template to add further users later
echo "client
dev tun
proto $protocol
remote $ip $port
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
auth SHA512
cipher AES-256-CBC
ignore-unknown-option block-outside-dns
verb 3" > /etc/openvpn/server/client-common.txt
# Enable and start the OpenVPN service
systemctl enable --now [email protected]
# Generates the custom client.ovpn
new_client
echo "Finished!"
echo "The client configuration is available in:" ~/"$client.ovpn"
echo "New clients can be added by running this script again."
clear
echo "OpenVPN is already installed."
echo "Select an option:"
echo " 1) Add a new client"
echo " 2) Revoke an existing client"
echo " 3) Remove OpenVPN"
echo " 4) Exit"
read -p "Option: " option
until [[ "$option" =~ ^[1-4]$ ]]; do
echo "$option: invalid selection."
read -p "Option: " option
case "$option" in
echo "Provide a name for the client:"
read -p "Name: " unsanitized_client
client=$(sed 's/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-]/_/g' <<< "$unsanitized_client")
while [[ -z "$client" || -e /etc/openvpn/server/easy-rsa/pki/issued/"$client".crt ]]; do
echo "$client: invalid name."
read -p "Name: " unsanitized_client
client=$(sed 's/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-]/_/g' <<< "$unsanitized_client")
cd /etc/openvpn/server/easy-rsa/
./easyrsa --batch --days=3650 build-client-full "$client" nopass
# Generates the custom client.ovpn
new_client
echo "$client added. Configuration available in:" ~/"$client.ovpn"
# This option could be documented a bit better and maybe even be simplified
# ...but what can I say, I want some sleep too
number_of_clients=$(tail -n +2 /etc/openvpn/server/easy-rsa/pki/index.txt | grep -c "^V")
if [[ "$number_of_clients" = 0 ]]; then
echo "There are no existing clients!"
echo "Select the client to revoke:"
tail -n +2 /etc/openvpn/server/easy-rsa/pki/index.txt | grep "^V" | cut -d '=' -f 2 | nl -s ') '
read -p "Client: " client_number
until [[ "$client_number" =~ ^[0-9]+$ && "$client_number" -le "$number_of_clients" ]]; do
echo "$client_number: invalid selection."
read -p "Client: " client_number
client=$(tail -n +2 /etc/openvpn/server/easy-rsa/pki/index.txt | grep "^V" | cut -d '=' -f 2 | sed -n "$client_number"p)
read -p "Confirm $client revocation? [y/N]: " revoke
until [[ "$revoke" =~ ^[yYnN]*$ ]]; do
echo "$revoke: invalid selection."
read -p "Confirm $client revocation? [y/N]: " revoke
if [[ "$revoke" =~ ^[yY]$ ]]; then
cd /etc/openvpn/server/easy-rsa/
./easyrsa --batch revoke "$client"
./easyrsa --batch --days=3650 gen-crl
rm -f /etc/openvpn/server/crl.pem
cp /etc/openvpn/server/easy-rsa/pki/crl.pem /etc/openvpn/server/crl.pem
# CRL is read with each client connection, when OpenVPN is dropped to nobody
chown nobody:"$group_name" /etc/openvpn/server/crl.pem
echo "$client revoked!"
echo "$client revocation aborted!"
read -p "Confirm OpenVPN removal? [y/N]: " remove
until [[ "$remove" =~ ^[yYnN]*$ ]]; do
echo "$remove: invalid selection."
read -p "Confirm OpenVPN removal? [y/N]: " remove
if [[ "$remove" =~ ^[yY]$ ]]; then
port=$(grep '^port ' /etc/openvpn/server/server.conf | cut -d " " -f 2)
protocol=$(grep '^proto ' /etc/openvpn/server/server.conf | cut -d " " -f 2)
if systemctl is-active --quiet firewalld.service; then
ip=$(firewall-cmd --direct --get-rules ipv4 nat POSTROUTING | grep '\-s $vpnGW/24 '"'"'!'"'"' -d $vpnGW/24' | grep -oE '[^ ]+$')
# Using both permanent and not permanent rules to avoid a firewalld reload.
firewall-cmd --remove-port="$port"/"$protocol"
firewall-cmd --zone=trusted --remove-source=$vpnGW/24
firewall-cmd --permanent --remove-port="$port"/"$protocol"
firewall-cmd --permanent --zone=trusted --remove-source=$vpnGW/24
firewall-cmd --direct --remove-rule ipv4 nat POSTROUTING 0 -s $vpnGW/24 ! -d $vpnGW/24 -j SNAT --to "$ip"
firewall-cmd --permanent --direct --remove-rule ipv4 nat POSTROUTING 0 -s $vpnGW/24 ! -d $vpnGW/24 -j SNAT --to "$ip"
if grep -qs "server-ipv6" /etc/openvpn/server/server.conf; then
ip6=$(firewall-cmd --direct --get-rules ipv6 nat POSTROUTING | grep '\-s fddd:1194:1194:1194::/64 '"'"'!'"'"' -d fddd:1194:1194:1194::/64' | grep -oE '[^ ]+$')
firewall-cmd --zone=trusted --remove-source=fddd:1194:1194:1194::/64
firewall-cmd --permanent --zone=trusted --remove-source=fddd:1194:1194:1194::/64
firewall-cmd --direct --remove-rule ipv6 nat POSTROUTING 0 -s fddd:1194:1194:1194::/64 ! -d fddd:1194:1194:1194::/64 -j SNAT --to "$ip6"
firewall-cmd --permanent --direct --remove-rule ipv6 nat POSTROUTING 0 -s fddd:1194:1194:1194::/64 ! -d fddd:1194:1194:1194::/64 -j SNAT --to "$ip6"
systemctl disable --now openvpn-iptables.service
rm -f /etc/systemd/system/openvpn-iptables.service
if sestatus 2>/dev/null | grep "Current mode" | grep -q "enforcing" && [[ "$port" != 1194 ]]; then
semanage port -d -t openvpn_port_t -p "$protocol" "$port"
systemctl disable --now [email protected]
rm -f /etc/systemd/system/[email protected]/disable-limitnproc.conf
rm -f /etc/sysctl.d/99-openvpn-forward.conf
if [[ "$os" = "debian" || "$os" = "ubuntu" ]]; then
rm -rf /etc/openvpn/server
apt-get remove --purge -y openvpn
# Else, OS must be CentOS or Fedora
yum remove -y openvpn
rm -rf /etc/openvpn/server
echo "OpenVPN removed!"
echo "OpenVPN removal aborted!"
help()
sudo chmod u+x openvpn-install.sh
./openvpn-install.sh
sudo cp /root/ubuntuvps.ovpn $HOME/
sudo chown $USER:$USER ubuntuvps.ovpn
echo "当前是help 帮助中心..."
sudo openvpn --genkey --secret static-OpenVPN.key
# 生成 vpn 密钥
############################# 创建仓库初始化仓库 ###########################
创建远程仓库:192.168.4.53:3000 右上角的创建
注意初始化时候本地文件夹和仓库名一致
nano .gitignore
# 写入屏蔽文件,
git push -u origin master
# 推送本地代码到远程,如果需要拉取代码: git pull
################### rv1126 sdk 初始化git 并且开始 编译 ###################
wget http://73e.top/download/docker/rv11xx-camera/rv11xx.tar.gz
tar -xzvf rv11xx.tar.gz -C ./ && cd rv1126
# 下载并解压sdk ,进入sdk 根目录,执行下面配置 sdk
rm -rf .git && rm -rf chivalrous/.git
# 删除原有的 .git 配置
## git 远程有仓库后进行本地配置
touch README.md && git init
git checkout -b main
# 创建分支 mian
git add *
# 将当前目录所有文件以增加的方式进行上传。
git add -A
# 覆盖方式上传
git reset *
# 清除暂存区内容
git commit -m "first commit"
# 上传本次任务备注
# git config --global --add safe.directory /datadisk/git
# 安全提示,将目录加权限
#----------------- 初始化 git 仓库 首次配置git -----------------#
touch README.md
git init
git checkout -b main
git add README.md
git commit -m "first commit"
git config --global user.email "[email protected]" && git config --global user.name "wanyang"
# 告诉git 我是谁; global [ˈɡləʊbl] 完整的
git config --global credential.helper store
# 长期储存密码 git pull时候的登陆密码
# 执行完后查看%HOME%目录下的.gitconfig文件
# [krəˈ den ʃ l] 凭据; [ˈhel pə(r)] 助手 [s tɔː] 储存
git remote add origin http://192.168.122.80:3000/eisc/eisc.git
# 配置仓库
#-----------------------------------------------------------------#
git remote add origin http://192.168.4.53:3000/mengxun/MXI_A01_Rv1126.git
# 新增配置http 方式进行连接git 仓库
# git branch –set-upstream-to=origin/master master
# 忽略此命令:重新为git pull添加跟踪分支即可。
# [rɪˈ məʊt] 远程 [ˈɒ rɪ dʒɪn] 起源
# rv1126 工程路径:http://192.168.4.53/mengxun/MXI_A01_Rv1126
git remote
# 查看有哪些remote
git remote remove origin
git push -u origin main
# 上传分支
git fetch --all && git reset --hard origin/master && git pull
# 覆盖本地并获取
# [fe tʃ] 提取;
git branch --set-upstream-to=origin/master master
# 当前分支没有跟踪信息。请指定您要变基到哪一个分支。
# [b rɑːn tʃ] 分支 [ˌʌpˈ s triː m] 上游 [ˈɒ rɪ dʒɪn] 起源,[ˈmɑːstə] 控制
git pull
# 拉取最新代码
#-------------- 开始 rv1126 编译 --------------#
./build.sh lunch
# 选择 :7. BoardConfig-ctk-ipc.mk
./envsetup.sh
# 选择: 105. rockchip_rv11xx_ctk_ipc
./build.sh
# 开始编译
#-------------- 解决报错:编译错误:libgpg-error-1.25 ------------#
编译包:libgpg-error 1.27 Building 错误
sudo find ./ -name mkstrtable.awk
cd ~/rv1126/buildroot/output/rockchip_rv11xx_ctk_ipc/build/libgpg-error-1.27/src
subl mkstrtable.awk
# 修改文件
print "static const char " namespace "msgstr[] = "; 修改为: print "static const char " pkg_namespace "msgstr[] = ";
sub (/\#.+/, ""); 修改为: sub (/#.+/, "");
print "static const int " namespace "msgidx[] ="; 修改为:print "static const int " pkg_namespace "msgidx[] =";
print namespace "msgidxof (int code)"; 修改为:print pkg_namespace "msgidxof (int code)";
rc下面的Makefile Makfile.in Makefile.am 需要修改一个名字,加上 gpk_
namespace 改为: pkg_namespace
#-------------------------
./build.sh
# 再次编译
#--------- 编译app 报错,删除cmake ,重新编译
# mkdir build ; cd build ; cmake ..
# 手动添加编译,编译输出文件到 指定 build目录
subl ~/rv1126/app/CameraModule/CMakeLists.txt
# 修改cmake 的编译gcc 为sdk 目录,如下:
set(CMAKE_C_COMPILER ~/rv1126/buildroot/output/rockchip_rv11xx_ctk_ipc/host/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ~/rv1126/buildroot/output/rockchip_rv11xx_ctk_ipc/host/bin/arm-linux-gnueabihf-g++)
或者创建 git sdk 目录 软连接 到家目录 rv1126 ,如下:
ln -s /git/rv11xx/ ~/rv1126
cd ~/rv1126/app/CameraModule/app/build && rm -rf *
# 进入项目编译路径
cmake ..
# 重新生成cmake 方法
rm -rf ~/rv1126/buildroot/output/rockchip_rv11xx_ctk_ipc/build/CameraModule-0.0.1/
# 删除输出目录,重新编译,会报错没有可执行文件进行安装。需要再次删除输出目录重新编译
# 注意:需要编译两次才能编过
# 参考:https://blog.csdn.net/QQ962662562/article/details/122363849
######################################## rv1126 配置结束 ##########################################
##### 其他备注资料 ######
#-------- rv11xx 恢复文件 删除版本 ------#
git reflog # 查看版本
git reset --hard 729fa0bab # 重置到之前的版本
git status # 查看git仓库的状态
git diff # 查看git修改了的内容
git log --pretty=oneline # 显示提交者和时间
git fetch --all && git reset --hard origin/master && git pull
# 强制覆盖本地
#-------- 说明 -----——#
$ git reset --hard HEAD #恢复当前版本,删除工作区和缓存区的修改
$ git reset --soft HEAD^ #恢复上一个版本,保留工作区,缓存区准备再次提交commit
$ git reset --mixed HEAD #恢复当前版本,保留工作区,清空缓存区
$ git reset --hard 1094a #切换到特定版本号,并删除工作区和缓存区的修改
#场景1:修改仅存在工作区
$ git checkout -- readme.txt # 单文件
#场景2:修改存在暂存区、工作区
$ git reset HEAD readme.txt
$ git checkout -- readme.txt
#场景3:修改存在版本库、暂存区、工作区
$ git reset --hard 1094a
参考:https://blog.csdn.net/zeye5731/article/details/122261447
################ 退回一个版本 ###############
#-------- git 暂存区 删除 ----------#
git rm -r --cached ./ # 删除暂存区文件,指定当前目录
git reset --hard HEAD # 恢复当前版本,删除工作区和缓存区的修改
git status -s # 查看看文件
#---------------------------------------------------#
git push -u origin master
# 推送本地代码到远程,如果需要拉取代码: git pull
git push --set-upstream origin master
# 当前master 没有对应上游分支,推送当前分支并建立与远程上游的跟踪
#------------- git 推送 -----------#
git add *
# 不覆盖性上传
git add -A
# -A 覆盖性上传
git reset *
# 清除暂存区内容
git commit -m "将本地当前目录所有文件添加到远程git仓库"
git push origin master
# 推送到 master 分支
git commit -m "new rv1126"
# 重新推送
#------------ git 下载 ---------------#
git clone http://192.168.4.53:3000/mengxun/MXI_A01_Rv1126.git
# 远程仓库拉取到本地
# 忽略以下命令,报错。
git pull origin master
# 如果远程分支是与当前分支合并,则冒号后面的部分可以省略。
git pull origin master:brantest
# 忽略此步骤:将远程主机 origin 的 master 分支拉取过来,与本地的 brantest 分支合并。
#------------------ git log 历史版本 --------------
git log # 查看历史的版本
windos 安装git :https://www.runoob.com/git/git-install-setup.html
#------------- git commit 本地版本删除 ------------#
git rebase -i HEAD~1
# 选择上一个版本进行编辑:将 pick xxx commit1 中的 pick 改为 drop 保存后,自动删除
注意:将.git 不能删除其中有版本缓存用于对比,将其他项目文件删除,再将原来的文件复制进入
#---------------- 故障排查 ------------#
You've added another git repository inside your current repository.
即在本地初始化的仓库(使用 git init的文件夹) 中的某一个文件夹,也含有 .git 文件 。
删除子文件夹里的.git文件,或者重命名为其他名字。然后重新add、commit、push
# 提示:You've added another git repository inside your current repository. #
# 提示:您已经在当前存储库中添加了另一个git存储库。
解答:删除当前目录的 .git 隐藏文件,重新添加 。 说明:git 包含版本备份。
当前是本地网络节点 192.168 网段 当前拥堵,优化网络中,点击查看配置信息
公开版,免备案
您的IP:10.1.1.1,2023-08-28 00:16:54,Processed in 0.12326 second(s).