伺服器搭建DOS
⑴ 如何在windows系統上安裝伺服器
安裝Winfows服務首先要添加安裝程序,添加安裝程序步驟如下:
1、將Windows服務程序切換到設計視圖, 右擊設計視圖選擇「添加安裝程序」
2、切換到剛被添加的ProjectInstaller的設計視圖
一般設置如下:
設置serviceInstaller1組件的屬性:
1) ServiceName = 服務名稱
2) StartType = Automatic ,即自動
設置serviceProcessInstaller1組件的屬性
1) Account = LocalSystem,賬戶一般設置為本地系統
3、生成解決方案
安裝服務:
方法一、使用DOS命令安裝window服務
1、在服務所在的文件夾下的bin\debug文件夾下找到.exe文件(例如WindowsService1.exe)
將此文件拷貝到你想安裝的文件夾中。
2、進入DOS界面
(VS2008-->Visual Studio Tools-->Visual Studio 2008 命令提示)來進入DOS,直接用cmd可能有些命令找不到;
3、輸入
方法二、使用安裝項目安裝windows服務
個人比較推薦這個方法,選擇目錄安裝更靈活,而且不用在DOS環境下運行。
因為本人比較懶,直接給出別人總結的地址
注意,以後每次服務項目有更改的時候,需要編譯服務後,在安裝項目中刷新依賴項!!!
方法三、
在ProjectInstaller.cs的後台代碼中添加安裝服務和卸載服務的代碼
/// <summary>
/// 安裝服務
/// </summary>
/// <param name="stateSaver"></param>
public override void Install(System.Collections.IDictionary stateSaver)
{
Microsoft.Win32.RegistryKey system,
//HKEY_LOCAL_MACHINE\Services\CurrentControlSet
currentControlSet,
//...\Services
services,
//...\<Service Name>
service,
//...\Parameters - this is where you can put service-specific configuration
config;
try
{
//Let the project installer do its job
base.Install(stateSaver);
//Open the HKEY_LOCAL_MACHINE\SYSTEM key
system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
//Open CurrentControlSet
currentControlSet = system.OpenSubKey("CurrentControlSet");
//Go to the services key
services = currentControlSet.OpenSubKey("Services");
//Open the key for your service, and allow writing
service = services.OpenSubKey(conServiceName, true);
//Add your service's description as a REG_SZ value named "Description"
service.SetValue("Description", "描述語言");
//(Optional) Add some custom information your service will use...
config = service.CreateSubKey("Parameters");
}
catch (Exception e)
{
Console.WriteLine("An exception was thrown ring service installation:\n" + e.ToString());
}
}
/// <summary>
/// 卸載服務
/// </summary>
/// <param name="savedState"></param>
public override void Uninstall(System.Collections.IDictionary savedState)
{
Microsoft.Win32.RegistryKey system,
currentControlSet,
services,
service;
try
{
//Drill down to the service key and open it with write permission
system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
currentControlSet = system.OpenSubKey("CurrentControlSet");
services = currentControlSet.OpenSubKey("Services");
service = services.OpenSubKey(conServiceName, true);
//Delete any keys you created ring installation (or that your service created)
service.DeleteSubKeyTree("Parameters");
//...
}
catch (Exception e)
{
Console.WriteLine("Exception encountered while uninstalling service:\n" + e.ToString());
}
finally
{
//Let the project installer do its job
base.Uninstall(savedState);
}
}
代碼添加完成後
添加window service安裝的批處理命令
1)在項目添加一個文本文件,更名為install.bat,編輯文件的內容如下:
@echo off
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i "WindowsService1.exe"
@pause
2)在項目添加一個文本文件,更名為uninstall.bat,編輯文件的內容如下
@echo off
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -u "WindowsService1.exe"
@pause
說明:上面綠色字體為服務名稱
編譯完成後將debug的文件拷貝到想安裝的目錄下,點擊install.bat即完成安裝。
⑵ Linux-dos2unix
Linux-dos2unix是一個實用工具,用於調整文件的換行符格式,確保它們能在Unix和Linux系統上正確讀取。Windows系統使用的文件換行符是\r\n,而Unix和Linux偏好\n。dos2unix命令的作用就是將文件中的\r\n替換為\n,這樣在Linux環境中就不會遇到讀取錯誤。
與之相反,unix2dos則是dos2unix的對應功能,它負責將Unix和Linux的\n換行符轉換為Windows的\r\n,以適應Windows的文件格式。
若要在伺服器上安裝dos2unix,首先從sourceforge.net下載壓縮包(如dos2unix-7.4.4.tar.gz),並將它上傳至伺服器。然後,使用命令tar -zxvf進行解壓。接下來,查閱INSTALL.txt中的安裝指南,按照指示進行,通常步驟包括在解壓後的文件夾中執行特定命令。
由於伺服器可能限制安裝許可權,不能直接安裝在根目錄,所以在執行make install時,需要指定安裝路徑。例如,為避免許可權問題,可以為dos2unix創建一個專用的安裝目錄。
安裝成功後,需要將dos2unix的可執行文件添加到環境變數中,這樣就可以在任何目錄下直接使用它了。如果在安裝過程中遇到任何問題,歡迎隨時指出以便修正。