Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
ToolNew
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
曾传波
ToolNew
Commits
d28f5b9c
提交
d28f5b9c
authored
5月 06, 2023
作者:
曾传波
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
最新版
上级
4c47efe3
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
86 行增加
和
25 行删除
+86
-25
Tool.sln
Tool/Tool.sln
+4
-0
Form1.Designer.cs
Tool/Tool/Form1.Designer.cs
+32
-2
Form1.cs
Tool/Tool/Form1.cs
+48
-20
ServiceManagement.jar
Tool/Tool/Resources/ServiceManagement.jar
+0
-0
Tool.csproj
Tool/Tool/Tool.csproj
+2
-3
没有找到文件。
Tool/Tool.sln
浏览文件 @
d28f5b9c
...
...
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.31313.79
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tool", "Tool\Tool.csproj", "{9B6513DB-F34F-4E5C-82D2-225D7D3B4529}"
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup", "Setup\Setup.vdproj", "{BB9114B0-C3DD-4B74-9411-6D12A0A3E5A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -15,6 +17,8 @@ Global
{9B6513DB-F34F-4E5C-82D2-225D7D3B4529}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B6513DB-F34F-4E5C-82D2-225D7D3B4529}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B6513DB-F34F-4E5C-82D2-225D7D3B4529}.Release|Any CPU.Build.0 = Release|Any CPU
{BB9114B0-C3DD-4B74-9411-6D12A0A3E5A6}.Debug|Any CPU.ActiveCfg = Debug
{BB9114B0-C3DD-4B74-9411-6D12A0A3E5A6}.Release|Any CPU.ActiveCfg = Release
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
Tool/Tool/Form1.Designer.cs
浏览文件 @
d28f5b9c
...
...
@@ -43,13 +43,15 @@ namespace Tool
this
.
port
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
Windows
=
new
System
.
Windows
.
Forms
.
RadioButton
();
this
.
Linux
=
new
System
.
Windows
.
Forms
.
RadioButton
();
this
.
Close
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
Open
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
panel1
.
SuspendLayout
();
this
.
SuspendLayout
();
//
// Detection
//
this
.
Detection
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
20F
,
System
.
Drawing
.
FontStyle
.
Bold
);
this
.
Detection
.
Location
=
new
System
.
Drawing
.
Point
(
166
,
44
);
this
.
Detection
.
Location
=
new
System
.
Drawing
.
Point
(
32
,
33
);
this
.
Detection
.
Name
=
"Detection"
;
this
.
Detection
.
Size
=
new
System
.
Drawing
.
Size
(
120
,
67
);
this
.
Detection
.
TabIndex
=
0
;
...
...
@@ -61,7 +63,7 @@ namespace Tool
//
this
.
Start
.
Enabled
=
false
;
this
.
Start
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
20F
,
System
.
Drawing
.
FontStyle
.
Bold
);
this
.
Start
.
Location
=
new
System
.
Drawing
.
Point
(
363
,
44
);
this
.
Start
.
Location
=
new
System
.
Drawing
.
Point
(
180
,
33
);
this
.
Start
.
Name
=
"Start"
;
this
.
Start
.
Size
=
new
System
.
Drawing
.
Size
(
120
,
67
);
this
.
Start
.
TabIndex
=
1
;
...
...
@@ -198,11 +200,37 @@ namespace Tool
this
.
Linux
.
UseVisualStyleBackColor
=
true
;
this
.
Linux
.
CheckedChanged
+=
new
System
.
EventHandler
(
this
.
Linux_CheckedChanged
);
//
// Close
//
this
.
Close
.
Enabled
=
false
;
this
.
Close
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
16F
,
System
.
Drawing
.
FontStyle
.
Bold
);
this
.
Close
.
Location
=
new
System
.
Drawing
.
Point
(
328
,
33
);
this
.
Close
.
Name
=
"Close"
;
this
.
Close
.
Size
=
new
System
.
Drawing
.
Size
(
131
,
67
);
this
.
Close
.
TabIndex
=
4
;
this
.
Close
.
Text
=
"关闭防火墙"
;
this
.
Close
.
UseVisualStyleBackColor
=
true
;
this
.
Close
.
Click
+=
new
System
.
EventHandler
(
this
.
Close_Click
);
//
// Open
//
this
.
Open
.
Enabled
=
false
;
this
.
Open
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
16F
,
System
.
Drawing
.
FontStyle
.
Bold
);
this
.
Open
.
Location
=
new
System
.
Drawing
.
Point
(
487
,
33
);
this
.
Open
.
Name
=
"Open"
;
this
.
Open
.
Size
=
new
System
.
Drawing
.
Size
(
131
,
67
);
this
.
Open
.
TabIndex
=
5
;
this
.
Open
.
Text
=
"打开防火墙"
;
this
.
Open
.
UseVisualStyleBackColor
=
true
;
this
.
Open
.
Click
+=
new
System
.
EventHandler
(
this
.
Open_Click
);
//
// Form1
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
640
,
432
);
this
.
Controls
.
Add
(
this
.
Open
);
this
.
Controls
.
Add
(
this
.
Close
);
this
.
Controls
.
Add
(
this
.
Linux
);
this
.
Controls
.
Add
(
this
.
Windows
);
this
.
Controls
.
Add
(
this
.
panel1
);
...
...
@@ -234,6 +262,8 @@ namespace Tool
private
System
.
Windows
.
Forms
.
RadioButton
Windows
;
private
System
.
Windows
.
Forms
.
RadioButton
Linux
;
private
System
.
Windows
.
Forms
.
ProgressBar
progressBar1
;
private
System
.
Windows
.
Forms
.
Button
Close
;
private
System
.
Windows
.
Forms
.
Button
Open
;
}
}
Tool/Tool/Form1.cs
浏览文件 @
d28f5b9c
...
...
@@ -19,7 +19,6 @@ namespace Tool
{
public
partial
class
Form1
:
Form
{
Thread
t1
,
t2
;
public
Form1
()
{
InitializeComponent
();
...
...
@@ -56,21 +55,22 @@ namespace Tool
SshClient
ssh
=
new
SshClient
(
this
.
host
.
Text
,
Convert
.
ToInt32
(
this
.
port
.
Text
),
this
.
name
.
Text
,
this
.
pwd
.
Text
);
//创建ssh连接
ssh
.
Connect
();
//打开连接
SshCommand
cmd
=
ssh
.
RunCommand
(
"bash --login -c 'java -version'"
);
if
(
cmd
.
Error
.
Contains
(
"1.8"
)){
cmd
=
ssh
.
RunCommand
(
"cat /etc/redhat-release"
);
//这条命令是查看centos的版本
string
[]
result
=
cmd
.
Execute
().
Split
(
' '
);
string
version
=
result
[
3
];
if
(
Convert
.
ToInt32
(
version
.
Split
(
'.'
)[
0
])
>=
8
)
//这个是判断centOS的版本号是否大过了8版本
{
MessageBox
.
Show
(
"您的centOS版本过高"
);
return
;
}
else
//版本合适的话,Linux内需要上传文件到Linux机器中,然后在运行,这里面是所有验证都通过了
if
(
cmd
.
Error
.
Contains
(
"1.8"
))
{
//cmd=ssh.RunCommand("cat /etc/redhat-release");//这条命令是查看centos的版本
//string[] result = cmd.Execute().Split(' ');
//string version = result[3];
// if (Convert.ToInt32(version.Split('.')[0]) >= 8)//这个是判断centOS的版本号是否大过了8版本
// {
// MessageBox.Show("您的centOS版本过高");
// return;
//}
//else//版本合适的话,Linux内需要上传文件到Linux机器中,然后在运行,这里面是所有验证都通过了
//{
MessageBox
.
Show
(
"请点击启动按钮"
);
this
.
Start
.
Enabled
=
true
;
ssh
.
Dispose
();
}
//
}
}
else
//这个是Linux下没有安装java环境时去执行的
{
...
...
@@ -79,12 +79,12 @@ namespace Tool
//创建sftp对象的目的就是将java的压缩包上传到Linux上,然后给他解压并且安装
sftp
.
Connect
();
string
filename
=
"jdk-8u301-linux-x64.tar.gz"
;
//这个是java安装包的名字
FileInfo
fi
=
new
FileInfo
(
string
.
Format
(
@"{0}\{1}\{2}"
,
Application
.
StartupPath
,
"Resources"
,
filename
));
FileInfo
fi
=
new
FileInfo
(
string
.
Format
(
@"{0}\{1}\{2}"
,
Application
.
StartupPath
,
"Resources"
,
filename
));
Stream
stream
=
new
FileStream
(
fi
.
FullName
,
FileMode
.
OpenOrCreate
,
FileAccess
.
ReadWrite
,
FileShare
.
ReadWrite
);
sftp
.
UploadFile
(
stream
,
"/usr/local/src/"
+
filename
);
//这个是把Java压缩文件复制到Linux中的路径里面
sftp
.
UploadFile
(
stream
,
"/usr/local/src/"
+
filename
);
//这个是把Java压缩文件复制到Linux中的路径里面
cmd
=
ssh
.
CreateCommand
(
string
.
Format
(
"tar -zxvf /usr/local/src/{0} -C /usr/local/src/"
,
filename
));
//这个是将java压缩包解压到文件夹中
cmd
.
Execute
();
//执行解压命令
fi
=
new
FileInfo
(
string
.
Format
(
@"{0}\{1}\{2}"
,
Application
.
StartupPath
,
"Resources"
,
"JavaPath.sh"
));
fi
=
new
FileInfo
(
string
.
Format
(
@"{0}\{1}\{2}"
,
Application
.
StartupPath
,
"Resources"
,
"JavaPath.sh"
));
stream
=
new
FileStream
(
fi
.
FullName
,
FileMode
.
OpenOrCreate
,
FileAccess
.
ReadWrite
,
FileShare
.
ReadWrite
);
filename
=
"JavaPath.sh"
;
sftp
.
UploadFile
(
stream
,
"/usr/local/src/"
+
filename
);
//这个是把设置path的脚本复制到Linux中的文件夹里面
...
...
@@ -148,8 +148,8 @@ namespace Tool
MaxSize
=
(
int
)
stream
.
Length
;
this
.
progressBar1
.
Invoke
(
(
MethodInvoker
)
delegate
{
this
.
progressBar1
.
Maximum
=
MaxSize
;
});
sftp
.
UploadFile
(
stream
,
"/java/javafilestoragepath/ServiceProxy.jar"
,
UpdateProgresBar
);
//上传第二个jar包
cmd
=
ssh
.
CreateCommand
(
string
.
Format
(
"bash --login -c 'nohup java -jar /java/javafilestoragepath/ServiceManagement.jar >
/java/javafilestoragepath/
log.out &'"
));
sftp
.
UploadFile
(
stream
,
"/java/javafilestoragepath/ServiceProxy.jar"
,
UpdateProgresBar
);
//上传第二个jar包
cmd
=
ssh
.
CreateCommand
(
string
.
Format
(
"bash --login -c 'nohup java -jar /java/javafilestoragepath/ServiceManagement.jar > log.out &'"
));
cmd
.
Execute
();
//MessageBox.Show(cmd.Result);
}
...
...
@@ -208,16 +208,16 @@ namespace Tool
}
public
static
string
[]
GetValue
(
string
[]
path
)
//获取文件路径下包含.jar文件的路劲
{
for
(
int
i
=
0
;
i
<
path
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
path
.
Length
;
i
++)
{
if
(
path
[
i
].
Contains
(
".jar"
))
//如果这个路径内包含带有.jar后缀的文件
{
char
[]
temp
=
path
[
i
].
ToCharArray
();
Array
.
Reverse
(
temp
);
path
[
i
]
=
string
.
Join
(
""
,
temp
).
Split
(
' '
)[
0
];
//这个可以获取jar文件
path
[
i
]
=
string
.
Join
(
""
,
temp
).
Split
(
' '
)[
0
];
//这个可以获取jar文件
temp
=
path
[
i
].
ToCharArray
();
Array
.
Reverse
(
temp
);
path
[
i
]
=
string
.
Join
(
""
,
temp
);
path
[
i
]
=
string
.
Join
(
""
,
temp
);
}
else
{
...
...
@@ -260,6 +260,8 @@ namespace Tool
}
private
void
Windows_CheckedChanged
(
object
sender
,
EventArgs
e
)
{
this
.
Close
.
Enabled
=
false
;
this
.
Open
.
Enabled
=
false
;
this
.
panel1
.
Visible
=
false
;
this
.
Start
.
Enabled
=
false
;
//启动按钮
}
...
...
@@ -270,9 +272,35 @@ namespace Tool
this
.
port
.
Text
=
"22"
;
}
private
void
Close_Click
(
object
sender
,
EventArgs
e
)
//关闭防火墙
{
SshCommand
cmd
=
null
;
SshClient
ssh
=
new
SshClient
(
this
.
host
.
Text
,
Convert
.
ToInt32
(
this
.
port
.
Text
),
this
.
name
.
Text
,
this
.
pwd
.
Text
);
ssh
.
Connect
();
cmd
=
ssh
.
CreateCommand
(
"bash --login -c 'systemctl stop firewalld'"
);
//关闭防火墙
cmd
.
Execute
();
cmd
.
Dispose
();
ssh
.
Dispose
();
this
.
Detection
.
Enabled
=
true
;
}
private
void
Open_Click
(
object
sender
,
EventArgs
e
)
//打开防火墙
{
SshCommand
cmd
=
null
;
SshClient
ssh
=
new
SshClient
(
this
.
host
.
Text
,
Convert
.
ToInt32
(
this
.
port
.
Text
),
this
.
name
.
Text
,
this
.
pwd
.
Text
);
ssh
.
Connect
();
cmd
=
ssh
.
CreateCommand
(
"bash --login -c 'systemctl start firewalld'"
);
//打开防火墙
cmd
.
Execute
();
this
.
Detection
.
Enabled
=
false
;
this
.
Start
.
Enabled
=
false
;
}
private
void
Linux_CheckedChanged
(
object
sender
,
EventArgs
e
)
{
this
.
panel1
.
Visible
=
true
;
this
.
Close
.
Enabled
=
true
;
this
.
Open
.
Enabled
=
true
;
this
.
Detection
.
Enabled
=
false
;
this
.
Start
.
Enabled
=
false
;
//启动按钮
}
}
...
...
Tool/Tool/Resources/ServiceManagement.jar
浏览文件 @
d28f5b9c
No preview for this file type
Tool/Tool/Tool.csproj
浏览文件 @
d28f5b9c
...
...
@@ -12,7 +12,7 @@
<FileAlignment>
512
</FileAlignment>
<Deterministic>
true
</Deterministic>
<IsWebBootstrapper>
false
</IsWebBootstrapper>
<PublishUrl>
D:\toolExe\
</PublishUrl>
<PublishUrl>
D:\toolExe
2
\
</PublishUrl>
<Install>
true
</Install>
<InstallFrom>
Disk
</InstallFrom>
<UpdateEnabled>
false
</UpdateEnabled>
...
...
@@ -22,8 +22,7 @@
<UpdatePeriodically>
false
</UpdatePeriodically>
<UpdateRequired>
false
</UpdateRequired>
<MapFileExtensions>
true
</MapFileExtensions>
<AutorunEnabled>
true
</AutorunEnabled>
<ApplicationRevision>
22
</ApplicationRevision>
<ApplicationRevision>
23
</ApplicationRevision>
<ApplicationVersion>
1.0.0.%2a
</ApplicationVersion>
<UseApplicationTrust>
false
</UseApplicationTrust>
<PublishWizardCompleted>
true
</PublishWizardCompleted>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论