提交 d28f5b9c authored 作者: 曾传波's avatar 曾传波

最新版

上级 4c47efe3
......@@ -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
......
......@@ -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;
}
}
......@@ -19,13 +19,12 @@ namespace Tool
{
public partial class Form1 : Form
{
Thread t1, t2;
public Form1()
{
InitializeComponent();
}
private void Detection_Click(object sender, EventArgs e)//检测按钮点击事件
{
......@@ -54,44 +53,45 @@ namespace Tool
try
{
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机器中,然后在运行,这里面是所有验证都通过了
{
MessageBox.Show("请点击启动按钮");
this.Start.Enabled = true;
ssh.Dispose();
}
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机器中,然后在运行,这里面是所有验证都通过了
//{
MessageBox.Show("请点击启动按钮");
this.Start.Enabled = true;
ssh.Dispose();
//}
}
else//这个是Linux下没有安装java环境时去执行的
{
MessageBox.Show("您当前未安装Java环境,请稍等!");//未安装java环境就要给他安装一个
SftpClient sftp = new SftpClient(this.host.Text, Convert.ToInt32(this.port.Text), this.name.Text, this.pwd.Text);//创建sftp对象
//创建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));
Stream stream = new FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
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"));
stream = new FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
filename = "JavaPath.sh";
sftp.UploadFile(stream, "/usr/local/src/" + filename);//这个是把设置path的脚本复制到Linux中的文件夹里面
sftp.Dispose();
cmd = ssh.CreateCommand(string.Format("sh /usr/local/src/{0} /usr/local/src/jdk1.8.0_301", filename));
cmd.Execute();
ssh.Dispose();
else//这个是Linux下没有安装java环境时去执行的
{
MessageBox.Show("您当前未安装Java环境,请稍等!");//未安装java环境就要给他安装一个
SftpClient sftp = new SftpClient(this.host.Text, Convert.ToInt32(this.port.Text), this.name.Text, this.pwd.Text);//创建sftp对象
//创建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));
Stream stream = new FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
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"));
stream = new FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
filename = "JavaPath.sh";
sftp.UploadFile(stream, "/usr/local/src/" + filename);//这个是把设置path的脚本复制到Linux中的文件夹里面
sftp.Dispose();
cmd = ssh.CreateCommand(string.Format("sh /usr/local/src/{0} /usr/local/src/jdk1.8.0_301", filename));
cmd.Execute();
ssh.Dispose();
MessageBox.Show(cmd.Result);//这个是看一下有没有配置成功
MessageBox.Show("安装成功!");
}
......@@ -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);
}
......@@ -193,7 +193,7 @@ namespace Tool
// MessageBox.Show("运行成功");
// //t1.Abort();//关闭进程
// t2.Abort();//关闭进程
//}
public static string Result()//获取文件运行时下目录中的文件,主要目的是找里面的jar包
{
......@@ -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
{
......@@ -240,7 +240,7 @@ namespace Tool
p.WaitForExit();
p.Close();
}
public void SshConnec(string cmd)
public void SshConnec(string cmd)
{
SshClient ssh = new SshClient(this.host.Text, Convert.ToInt32(this.port.Text), this.name.Text, this.pwd.Text);
ssh.Connect();//打开连接
......@@ -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;//启动按钮
}
}
......
......@@ -12,7 +12,7 @@
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>D:\toolExe\</PublishUrl>
<PublishUrl>D:\toolExe2\</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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论