tail -f /var/log/nginx/error.log

tail 명령어에 -f 옵션을 줘서 실시간으로 변경되는걸 확인 할 수 있다

'Dev' 카테고리의 다른 글

Nginx 에서 Socket.io 세팅하기  (20) 2023.02.11
[Nginx] 403 forbidden ( 13 : permission denied )  (48) 2021.11.23
Fail2ban 설치  (47) 2021.06.07
[Raspbian] 라즈베리 파이 VNC 접속하기  (14) 2021.03.17
[Linux] ssh server 자동 실행  (19) 2021.02.16

0.

 

집에 라즈베리파이를 설치, 서버를 열어놨다.

근데 어느순간부터 ssh가 렉이 엄청 먹길래

무슨일인가 싶어서 보니 cpu 사용량이 100%를 찍고있었다. 아무것도 안했는데

 

그래서 해킹인가 싶어서 ssh 접속 기록을 찾아봤다

 

sudo nano /var/log/auth.log

 

난리가 났다. 모르는 아이피에서 엄청나게 짧은 간격으로 계속 접속을 시도하고 있었다.

fail2ban 을 설치해서 한번 무차별 접속을 막아보자

 

1. 설치

 

sudo apt install fail2ban

 

2. 세팅

 

세팅 파일을 작성하자

sudo nano /etc/fail2ban/jail.local
# jail.local

[DEFAULT]
# 최대 입력 허용 횟수
maxretry = 5

# 밴 시간 (초), -1 : 영구
bantime  = -1

[sshd]
enabled = true

# 22번 포트가 아닌 다른 포트를 사용 중 이라면 변경
port = ssh
filter = sshd
logpath = /var/log/auth.log

 

간단하게 이정도만 작성했다. 필요한 기능이 있으면 공식 홈페이지에서 찾아보는걸로.

제일 하단에 공홈 링크 첨부

 

sudo service fail2ban restart

 

서비스를 재시작해서 작성한 세팅 파일로 시작되도록

 

3. 확인

 

밴이 잘 되고 있는지 확인해보자

sudo fail2ban-client status sshd
Status for the jail: sshd
|- Filter
|  |- Currently failed: 3
|  |- Total failed:     11
|  `- File list:        /var/log/auth.log
`- Actions
   |- Currently banned: 5
   |- Total banned:     5
   `- Banned IP list:   116.252.80.181 123.207.198.153 139.155.55.250 218.92.0.208 223.39.219.159

 

5개의 ip가 밴된걸 확인 할 수 있다.

 

나도 실수로 밴 될수도 있으니 밴 해제 명령어도 있다

sudo fail2ban-client set sshd unbanip [ip]

 

https://www.fail2ban.org/

 

Fail2ban

Since spammers were way too much active on this wiki, user account creation has been disabled. Please, ask on the mailing-lists if you require a new user account. Thank you for your understanding and sorry about that. To experiment with this wiki try Sandb

www.fail2ban.org

 

 

분명 안드로이드 스튜디오가 설치되어있는데 설치되지 않았단다.

 

flutter config --android-studio-dir="C:\Program Files\Android\Android Studio"

 

안드로이드 스튜디오의 경로를 지정해주자

 

 

 

안드로이드 스튜디오 문제는 해결됐다

그런데 이제 갑자기 Android toolchaing 에서 경고가 뜬다.

 

flutter doctor --android-licenses

 

이게 제대로 라이센스 동의하는 문구가 나올수도 있고 

이런 에러가 나올 수도 있다.

(Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema)

 

라이센스 동의하는 문구가 나오면 y 입력으로 그냥 넘어가면 되고 

이 에러가 뜰 경우 안드로이드 스튜디오 세팅으로 넘어가자

 

Android SDK Command-line Tools 를 체크하고 OK

 

 

이제야 다 됐다.

 

 

listview 를 사용중인데 item 에 image 가 들어간다. 문제는 이 이미지가 network 에서 받아와서 이미지의 높이를 받아오기전까지 모른다는거...

 

그래서 이미지를 받아와서 container height 를 설정해주고 있다

 

문제는 리스트뷰를 쫙~ 내리고 다시 올라올때 listview 특성상 기존 아이템들을 잠시 제거했다가 화면에 보일때 다시 렌더링한다는거... 

 

기존 아이템이 제거돼서 높이가 0이 됐다가 다시 화면에 보여 렌더링되면서 높이가 100? 200? 정도 로 설정되면서 스크롤이 갑자기 한움큼 내려가버리는 문제 발생.

 

그래서 listview 나 pageview 같은 곳에서 기존 아이템들을 살릴 수 있는 방법을 찾아봤다.

 

import 'package:flutter/material.dart';

class TestItem extends StatefulWidget {
  @override
  _TestItemState createState() => _TestItemState();
}

class _TestItemState extends State<TestItem>
    with AutomaticKeepAliveClientMixin { // <-----
  @override
  bool get wantKeepAlive => true; // <-------

  @override
  Widget build(BuildContext context) {
    super.build(context); // <------
    return Container();
  }
}

 

방법은 하위 아이템에 AutomaticKeepAliveClientMixin 을 with 해주고,

get 으로 wantKeepAlive true 로 반환하는 코드를 오버라이딩 해주면 된다.

 

이 방법은 tabbar, listview 등등 적용된다

참조 https://stackoverflow.com/questions/52541172/flutter-listview-keepalive-after-some-scroll

flutter 에서 Globalkey 를 이용하여 위젯의 크기와 위치를 구하는 방법.

크기를 구할땐 LayoutBuilder 위젯도 있다. 여기선 GlobalKey 로 구하는 법

 

베이스 코드

// ...

GlobalKey _redBoxKey = GlobalKey();
GlobalKey _greenBoxKey = GlobalKey();
GlobalKey _blueBoxKey = GlobalKey();


@override
  Widget build(BuildContext context) {

    return Scaffold(
        body: SafeArea(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          Center(
            child: Container(
              key: _redBoxKey,
              height: 40,
              width: 40,
              color: Colors.red,
            ),
          ),
          Center(
            child: Container(
              key: _greenBoxKey,
              height: 100,
              width: 40,
              color: Colors.green,
            ),
          ),
          Center(
            child: Container(
              key: _blueBoxKey,
              height: 40,
              width: 100,
              color: Colors.blue,
            ),
          ),
        ],
      ),
    ));
    
    
    //...

일단 GlobalKey 를 선언하여 widget 에 key 를 할당해준다. 그 후 진행

 

1. 크기

 

// ...

_getSize(GlobalKey key) {
    if (key.currentContext != null) {
      final RenderBox renderBox =
          key.currentContext!.findRenderObject() as RenderBox;
      Size size = renderBox.size;
      return size;
    }
  }
  
// ...

 

key 를 이용하여 RenderBox 를 구하면 RenderBox에서 size 를 구할 수 있다.

 

// ...

    final redBoxSize = _getSize(_redBoxKey);
    final greenBoxSize = _getSize(_greenBoxKey);
    final blueBoxSize = _getSize(_blueBoxKey);

    print('red box size : ${redBoxSize.width} ${redBoxSize.height}');
    print('green box size : ${greenBoxSize.width} ${greenBoxSize.height}');
    print('blue box size : ${blueBoxSize.width} ${blueBoxSize.height}');

// ...

//    I/flutter ( 5007): red box size : 40.0 40.0
//    I/flutter ( 5007): green box size : 40.0 100.0
//    I/flutter ( 5007): blue box size : 100.0 40.0

 

2. 위치

// ...

_getPosition(GlobalKey key) {
    if (key.currentContext != null) {
      final RenderBox renderBox =
          key.currentContext!.findRenderObject() as RenderBox;
      final position = renderBox.localToGlobal(Offset.zero);
      return position;
    }
  }
  
 // ...

 

크기와 비슷하다. renderBox 의 localToGlobal 함수를 이용한다. 

Offset.zero 즉. 위젯의 좌상단을 기준으로 global 포지션을 구하는 방식이다.

 

// ...

    final redBoxPosition = _getPosition(_redBoxKey);
    final greenBoxPosition = _getPosition(_greenBoxKey);
    final blueBoxPosition = _getPosition(_blueBoxKey);

    print('red box posiiton : ${redBoxPosition.dx} ${redBoxPosition.dy}');
    print('green box posiiton : ${greenBoxPosition.dx} ${greenBoxPosition.dy}');
    print('blue box posiiton : ${blueBoxPosition.dx} ${blueBoxPosition.dy}');
    
// ...

// I/flutter ( 5007): red box posiiton : 0.0 147.71428571428572 
// x축 확인을 위해 redbox 를 맨 왼쪽으로 붙인 상태이다
// I/flutter ( 5007): green box posiiton : 185.71428571428572 384.8571428571429
// I/flutter ( 5007): blue box posiiton : 155.71428571428572 682.0

 

+ Recent posts