배열에 includes 통하여 조건 단순화

function isKoreanFood(food) {
  if (["불고기", "비빔밥", "떡볶이"].includes(food)) {
    return true;
  }
  return false;
}

const food1 = isKoreanFood("불고기");
const food2 = isKoreanFood("파스타");
console.log(food1);
console.log(food2);

객체의 가로 표기법으로 if 문 줄이기

const meal = {
  한식: "불고기",
  중식: "멘보샤",
  일식: "초밥",
  양식: "스테이크",
  인도식: "카레"
};

const getMeal = (mealType) => {
  return meal[mealType] || "굶기";
};

console.log(getMeal("중식"));
console.log(getMeal());

 

자바 설치 

sudo amazon-linux-extras enable corretto8
sudo yum clean metadata
sudo yum install java-1.8.0-amazon-corretto-devel

자바의 설치 경로를 확인합니다. 

$ which java
/usr/bin/java

$ readlink -f /usr/bin/java
/usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre/bin/java

자바를 환경설정 JAVA_HOME 설정

sudo vi /etc/profile

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar

source /etc/profile

HBase 설치

wget http://archive.apache.org/dist/hbase/1.2.7/hbase-1.2.7-bin.tar.gz
tar -zxvf hbase-1.2.7-bin.tar.gz
rm hbase-1.2.7-bin.tar.gz

hbase-1.2.7/conf/hbase-env.sh 파일 수정

# Configure PermSize. Only needed in JDK7. You can safely remove it for JDK8+
export HBASE_MASTER_OPTS="$HBASE_MASTER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m -XX:ReservedCodeCacheSize=256m"
export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m -XX:ReservedCodeCacheSize=256m"

위 두줄을 주석 처리하여 준다. 

hbase-1.2.7/conf/hbase-site.xml 파일 수정

 <configuration>
      <property>
          <name>hbase.rootdir</name>
          <value>file:///home/ec2-user/pinpoint/data</value>
      </property>
      <property>
          <name>hbase.zookeeper.property.dataDir</name>
          <value>/home/ec2-user/pinpoint/zookeeper</value>
      </property>
  </configuration>

실행

hbase-1.2.7/bin/start-hbase.sh

hbase 스키마 생성

cd /home/ec2-user/pinpoint/hbase-1.2.7/bin
wget https://raw.githubusercontent.com/pinpoint-apm/pinpoint/master/hbase/scripts/hbase-create.hbase

TTL 값이 31536000 초(365일), 5184000 초(60 일)로 데이터를 유지하도록 되어있어 604800 초(7일)로 변경

sed 's/31536000/604800/' hbase-create.hbase > hbase-create-real.hbase
sed -i 's/5184000/604800/' hbase-create-real.hbase

스키마 생성

./hbase shell ./hbase-create-real.hbase

Pinpoint Collector 설치 및 실행

wget https://github.com/pinpoint-apm/pinpoint/releases/download/v2.2.0/pinpoint-collector-boot-2.2.0.jar
nohup java -jar -Dpinpoint.zookeeper.address=localhost pinpoint-collector-boot-2.2.0.jar 1>/dev/null 2>&1 &

Pinpoint Web 설치 및 실행

wget https://github.com/pinpoint-apm/pinpoint/releases/download/v2.2.0/pinpoint-web-boot-2.2.0.jar
nohup java -jar -Dpinpoint.zookeeper.address=localhost pinpoint-web-boot-2.2.0.jar 1>/dev/null 2>&1 &

 

Pinpoint Agent 설치

wget https://github.com/pinpoint-apm/pinpoint/releases/download/v2.2.0/pinpoint-agent-2.2.0.tar.gz
tar -zxvf pinpoint-agent-2.2.0.tar.gz

vi /pinpoint-agent-2.2.0/pinpoint-root.config 수정 

profiler.transport.grpc.collector.ip=192.168.0.207

 

회사에서 서버로 쓰려고 창고에 박아 두었던 라즈베리를 꺼냈다. 

우분투를 설치하려다가 centos를 설치하기로 함 

8버전 부터 도커를 지원하다고(인터넷 검색).. 8버전으로.. 

1. SD카드를 포맷할 수 있는 프로그램 다운로드

https://www.sdcard.org/downloads/formatter/ 

 

SD Memory Card Formatter | SD Association

SD Memory Card Formatter 5.0.1 for SD/SDHC/SDXC The SD Memory Card Formatter formats SD Memory Card, SDHC Memory Card and SDXC Memory Card (respectively SD/SDHC/SDXC Cards) complying with the SD File System Specification created by the SD Association (SDA)

www.sdcard.org

SD 포맷 시킬 프로그램을 다운받는다. (윈도우면 필요없을 수도...)

2.  centos 8 버전 다운로드 (라즈베리파이용)

https://people.centos.org/pgreco/CentOS-Userland-8-stream-aarch64-RaspberryPI-Minimal-4/

 

Pablo Greco | People of CentOS

 

people.centos.org

3.  설치 유틸 (SD 카드) 로 옮겨줌 

https://www.balena.io/etcher/

 

balena - The complete IoT fleet management platform

Infrastructure and tools to develop, deploy, and manage connected devices at scale. Your first ten devices are always free.

www.balena.io

4. 초기화 셋팅 

처음 암호는 root 비밀번호는 centos 이다. 

5. 용량 늘리기 

32GB 용량을 구매했는데 df를 해보니 8기가 였다. 

인터넷 검색해보니 용량을 확장하는 방법이 있었다. 

https://ivps.tistory.com/717

1. 서비스 생성 파일 만든다. 

sudo vi /lib/systemd/system/mypythonservice.service

 2. 실행 구문을 넣어준다. 

[Unit] 
Description=My Python Service 
After=multi-user.target 

[Service] 
Type=idle 
ExecStart=/usr/bin/python /home/myuser/mypythonproject.py 
Restart=on-failure 

[Install] 
WantedBy=multi-user.target

 3. 권한 설정 

sudo chmod 644 /lib/systemd/system/mypythonservice.service

 4. 데몬 재시작 

sudo systemctl daemon-reload

 5. enable 시켜줌

sudo systemctl enable mypythonservice.service
 
 

아마존 영역에서 elasticsearch를 사용하기 위해서는 opensearch를 사용해야되는데 기존 elasticsearch 와 연동하는 부분이 라이센스 문제 때문에 삽질을 계속했다.  

logstash에서 opensearch로 데이터를 전송하기 위해서는 logstash-oss 다운받아야 하며 opensearch 모듈이 포함되어 있는 것을 다운 받아야 한다. (https://opensearch.org/downloads.html)

curl https://artifacts.opensearch.org/logstash/logstash-oss-with-opensearch-output-plugin-7.16.2-linux-x64.tar.gz -o logstash-oss-with-opensearch-output-plugin-7.16.2-linux-x64.tar.gz

tar -zxvf logstash-oss-with-opensearch-output-plugin-7.16.2-linux-x64.tar.gz

로그스태시 생성

/home/ec2-user/logstash-7.16.2/config/logstash.conf 파일 생성

input {
  file {
    path => ["/log/*.log"]
    start_position => "beginning"
  }
}
filter {
    json {
      source => "message"
      remove_field => ["message", "@timestamp", "@version"]
    }
}
output {
     opensearch {
        hosts       => ["https://:443"]
        user        => "user"
        password    => "password"
        index       => "logstash-logs"
    }
}

로그스태시  실행 

/home/ec2-user/logstash-7.16.2/bin/logstash -f /home/ec2-user/logstash-7.16.2/config/test.conf
systemctl stop [servicename]
systemctl disable [servicename]
rm /etc/systemd/system/[servicename]
rm /etc/systemd/system/[servicename] # and symlinks that might be related
rm /usr/lib/systemd/system/[servicename] 
rm /usr/lib/systemd/system/[servicename] # and symlinks that might be related
systemctl daemon-reload
systemctl reset-failed
  1. 기본정렬
  2. 역순정렬
  3. null포함(nullLast)
  4. null포함(nullFirst)

1.기본 정렬

List<Member> list = List.of(Member.of(10), Member.of(20), Member.of(30));

List<Member> result = list.stream()
    .sorted(Comparator.comparing(Member::getAge))
    .collect(Collectors.toList());

System.out.println(result);

결과

[Member{age=10}, Member{age=20}, Member{age=30}]

2.역순 정렬

List<Member> list = List.of(Member.of(10), Member.of(20), Member.of(30));

List<Member> result = list.stream()
     .sorted(Comparator.comparing(Member::getAge, Comparator.reverseOrder()))
     .collect(Collectors.toList());

System.out.println(result);

결과

[Member{age=30}, Member{age=20}, Member{age=10}]

3.null 포함 nullLast

List<Member> list = List.of(Member.of(10), Member.of(null), Member.of(30));

List<Member> result = list.stream()
    .sorted(Comparator.comparing(Member::getAge, Comparator.nullsLast(Comparator.naturalOrder())))
    .collect(Collectors.toList());

System.out.println(result);

결과

[Member{age=10}, Member{age=30}, Member{age=null}]

4.null 포함 nullFirst

List<Member> list = List.of(Member.of(10), Member.of(null), Member.of(30));

List<Member> result = list.stream()
    .sorted(Comparator.comparing(Member::getAge, Comparator.nullsFirst(Comparator.naturalOrder())))
    .collect(Collectors.toList());

System.out.println(result);

결과

[Member{age=null}, Member{age=10}, Member{age=30}]

예제 Member class

class Member{

    Integer age;

    public Member(Integer age){
        this.age = age;
    }

    public static Member of(Integer age){
        return new Member(age);
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Member{" +
                "age=" + age +
                '}';
    }
}

토픽 생성

bin/kafka-topics.sh --create \
--bootstrap-server 카프카서버:9092 \
--replication-factor 1 \
--partitions 3 \
--topic 토픽이름

토픽 삭제

bin/kafka-topics.sh --delete --bootstrap-server 카프카서버:2181 --topic 토픽이름

토픽 리스트

bin/kafka-topics.sh  --bootstrap-server 카프카서버:9092 --list

토픽 상세

bin/kafka-topics.sh --bootstrap-server 카프카서버:9092 --describe --topic 토픽이름

컨슈머

컨슈머 확인

bin/kafka-console-consumer.sh --bootstrap-server 카프카서버:9092 --topic 토픽이름 --from-beginning

컨슈머 그룹 리스트

bin/kafka-consumer-groups.sh --bootstrap-server 카프카서버:9092 --list

컨슈머 그룹 상세

bin/kafka-consumer-groups.sh --bootstrap-server 카프카서버:9092 --describe --group 컨슈머그룹이름

+ Recent posts