Linux hostname 확인하고 변경하는 방법

| hostname 확인

명령어로 확인하기

다음과 같이 입력하면 hostname을 출력합니다.

$ hostname

설정 파일 열어서 확인하기

$ vi /etc/hostname

| hostname 변경

명령어로 변경

다음과 같이 입력하면 hostname이 new-hostname 으로 바뀝니다.

$ hostnamectl set-hostname new-hostnameCode language: JavaScript (javascript)

설정 파일 열어서 변경하기

텍스트 에디터로 /etc/hostname 파일을 열어서 내용을 new-hostname 으로 바꾸면 hostname이 new-hostname으로 바뀝니다.

| 재부팅

그리고 재부팅. 재부팅을 하면 위에서 설정한 사항들이 반영됩니다.

Disk Speed Test (Read/Write) HDD/SSD Performance in Linux

이 글은 HDD, SSD, USB플래시 드라이브 등과 같은 장치에서 파일 시스템의 읽기/쓰기 성능을 측정하는 방법을 다룹니다.

  • dd명령을 사용하여 테스트 하는 방법과
  • hdparm을 사용해서 읽기 속도를 측정하는 방법을 보여드립니다.

정확한 읽기/쓰기 속도를 얻으려면 아래 테스트를 여러 번(3~5번) 반복하고 평균 결과를 얻어야 합니다.

dd: 테스트 디스크 쓰기 속도

$ sync; dd if=/dev/zero of=tempfile bs=1M count=1024; sync
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 6.39392 s, 168 MB/sCode language: JavaScript (javascript)

dd: 테스트 디스크 읽기 속도

$ dd if=tempfile of=/dev/null bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.0844541 s, 12.7 GB/sCode language: JavaScript (javascript)
Cache를 클리어 하여 실제 속도를 측정합니다.
$ /sbin/sysctl -w vm.drop_caches=3
vm.drop_caches = 3
$ dd if=tempfile of=/dev/null bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.354828 s, 3.0 GB/sCode language: JavaScript (javascript)

hdparm: 읽기 테스트

hdparm -Tt /dev/sda2

/dev/sda2:
 Timing cached reads:   17942 MB in  1.99 seconds = 8998.20 MB/sec
 Timing buffered disk reads: 3642 MB in  3.00 seconds = 1212.65 MB/sec

/dev/sda2등의 경로는 자신의 환경에 맞게 수정해주세요.

윈도우에서 파이썬 ZIP 설치

PYTHON ZIP 다운로드

https://www.python.org/downloads/windows/ 에서 Download Windows x86-64 embeddable zip file 링크를 통해 다운로드할 수 있다.

pip 설치

get-pip.py 파일을 파이썬 디렉토리에 저장한다.

C:\>cd c:\python-3.8.1
C:\python-3.8.1>python get-pip.pyCode language: CSS (css)

python38._pth 파일 수정

python38._pth 파일에 파이썬 관련 경로를 추가하고 저장한다.

C:\python-3.8.1
C:\python-3.8.1\DLLs
C:\python-3.8.1\lib
C:\python-3.8.1\lib\plat-win
C:\python-3.8.1\lib\site-packagesCode language: CSS (css)

PATH 환경변수 추가

PATH 환경변수에 파이썬 경로를 추가하기 위해 명령 프롬프트 창을 관리자 권한으로 실행하여 아래의 명령어를 입력한다.

setx -m path "%path%;C:\python-3.8.1;C:\python-3.8.1\Scripts"Code language: CSS (css)

External Network Access to Kestrel and IIS Express in ASP.NET Core

Today I ported over my AlbumViewer sample Angular 2.0 application I worked on for a workshop for the last few weeks, to my ASP.NET Core project. I’ve been building various different kinds of backends for this Angular 2.0 front end app and it’s been very easy to simply swap them out by changing the base URL to the API endpoints.

I’ve been working on the Angular 2.0 app on my Mac, but the server side ASP.NET I’m moving it to is running on Windows using ASP.NET Core and so I need to run my API application in a Windows VM on Parallels and access this API from the Mac side where the Angular application is running locally using the WebPack dev server.

In order to access the Windows API service from the Mac requires a bit of configuration as by default both Kestrel and IIS Express only serve requests on localhost. Both servers use default bindings that point explicitly at localhost which effectively disables remote access.

In order to make this work there are a couple of configuration steps required:

  • Change the default URL binding to a non-localhost address
  • Open the Firewall port
  • Map a host name to make it easier

Kestrel: What’s the Problem? Url Bindings

The issue is that the default binding that Kestrel uses, binds explicitly to localhost. A localhost bound IP won’t expose to the external network, so even though you might be able to access other ports on the VM over the network – like IIS running on port 80 – accessing of http://<WindowsVmIp>:5000/ is not supported without some configuration changes.

When Kestrel starts without any binding customization you get:

which clearly shows that it’s using the localhost URL.

Override the default URLs

In order to expose Kestrel externally you either have to bind to a specific machine name, IP Address or 0.0.0.0 which stands for all IP Addresses (thanks to @DamianEdwards and @BradyMHolt for their help).

ASP.NET Core allows overriding the startup URLs as part of the startup process for the Web host and there are a number of ways that you can do this:

  • Set the –urls command line parameter
  • Use WebHost.UseUrls()
  • Set up hosting.json

You can override the start this via the launch command line:

 dockerfile
 dotnet run --urls http://0.0.0.0:5001

In order for this to work make sure that command line argument configuration is enabled as part of the startup procedure:

 csharppublic static void Main(string[] args)
 {
  // use this to allow command line parameters in the config
  var configuration = new ConfigurationBuilder()
  .AddCommandLine(args)
  .Build();
  ...
 }

If you want more control you can also explicitly set the host Url or Urls. In code you can use the following – including reading a configuration setting from a custom command line parameter:

 csharppublic static void Main(string[] args)
 {
  // use this to allow command line parameters in the config
  var configuration = new ConfigurationBuilder()
  .AddCommandLine(args)
  .Build();
 ​
 ​
  var hostUrl = configuration["hosturl"];
  if (string.IsNullOrEmpty(hostUrl))
  hostUrl = "http://0.0.0.0:6000";
 ​
 ​
  var host = new WebHostBuilder()
  .UseKestrel()
  .UseUrls(hostUrl) // <!-- this
  .UseContentRoot(Directory.GetCurrentDirectory())
  .UseIISIntegration()
  .UseStartup<Startup>()
  .UseConfiguration(configuration)
  .Build();
 ​
  host.Run();
 }

With that in place you could run:

 dockerfiledotnet run                                 // default on port 6000
 dotnet run --hosturl http://0.0.0.0:6001 // explicit

The key is the .UseUrls() call that applies the host url to the Webhost and as you can see you can apply logic and configuration to decide where the value comes from.

Note that you can specify multiple startup URLs separated by semicolons in the string passed.

Open your Firewall

Next you need to make sure that your Windows firewall allows access to the requested port.

 pgsql
 netsh advfirewall firewall add rule name="Http Port 5000" dir=in action=allow protocol=TCP localport=5000

or you can use the interactive Windows Firewall application.

Assuming you used a non-localhost IP address or name, your application should now be externally accessible when you dotnet run.

On the Mac: Create a HOSTS entry

This step is optional, but when developing in a two OS environment I like to make it as easy as possible to identify machines, so I tend to create domain names for the server rather than using an IP address to access it by modifying the HOSTS file on the client machine. So I have dev.west-wind.com locally which maps to the IP address of my Windows virtual machine in Parallels.

With this in place I can now navigate to my app with:

http://dev.west-wind.com:5000/index.html

to get to my ASP.NET Core application on the Windows VM. Schweet!

Exposing IIS Express to the Network

If you want to use IIS Express and allow external access, you need to explicitly change the bindings in the solution applicationhost.config file which can be found in <solutionRoot>\.vs\config. Change the bindingInformation to:

 xml<site name="AlbumViewerNetCore" id="2">
  <application path="/" applicationPool="Clr4IntegratedAppPool">
  <virtualDirectory path="/" physicalPath="C:\projects2010\AlbumViewerVNext\src\AlbumViewerNetCore" />
  </application>
  <bindings>
  <binding protocol="http" bindingInformation="*:26448:*" />
  <binding protocol="https" bindingInformation="*:44319:*" />
  </bindings>
 </site>

changing the *:26448:localhost to *:26448:* where 26448 is the IIS Express port.

Then run:

 nginx
 netsh http add urlacl url=http://*:26448/ user=Interactive listen=yes

to bind the http.sys entry.

Finally open the firewall to allow inbound connections to the specific IIS Express port:

 pgsql
 netsh advfirewall firewall add rule name="Http Port 26448" dir=in action=allow protocol=TCP localport=26448

and you should be off to the races.