리눅스
- 리눅스 기본 명령어
cafe.daum.net/flowlife/9A8Q/161
리눅스 기본 명령어
vmwarehttps://www.vmware.com/kr.html무료사용 제품VMware Workstation Playerhttps://www.centos.org/vmware에 centos 설치 하기https://jhnyang.tistory.com/280https://www.ubuntu-kr.org/1. 데비안(Debian)Debian은
cafe.daum.net
- 리눅스 기본 편집기 vi/vim 명령어
- 터미널 명령어 실행
pwd : 사용자의 경로
ls : 디렉토리
-l : 자세히 보기
-a : 숨김파일 확인
-al : 숨김파일 자세히 보기
~ : 현재 사용자의 경로
/ : 리눅스의 경로
vi aaa : 파일 생성
esc : 입력어 대기화면
i, a : append
shift + space : 한영
:q! : 미저장 종료
:wq : 저장 후 종료
vi bbb.txt : 파일 생성
리눅스에선 확장자 X
vi .ccc : 숨김 파일 생성
. : 숨김 파일
yy : 복사
p : 붙여넣기
dd : 한줄 지우기
숫자+명령어 : 명령어 여러번 반복
:set nu : 줄 번호 넣기
:set nonu : 줄 번호 제거
whoami : id 확인
s /home : id 확인
mkdir kbs : 디렉토리 생성
mkdir -p mbc/sbs : 상위 디렉토리 자동 생성
cd 디렉토리명 : 디렉토리 변경
cd ~ : home으로
cd .. : 상위 디렉토리로 이동
rmdir 디렉토리명 : 디렉토리 삭제
rm 파일명 : 파일 삭제
rm -rf kbs : 파일 있어도 삭제 가능
touch 파일명 : 빈 파일 생성
cat 파일명 : 파일 내용 확인
cat 파일명1 파일명2 : 파일 내용확인
cp 파일명 디렉토리명/ : 파일 복사
cp 파일명 디렉토리명/새파일명 : rename 파일 복사
mv 파일명 디렉토리 : 파일 이동
rename 파일명 happy 새파일명 : 파일명 변경
mv 파일명 새파일명 : 파일명 변경
head -3 파일명 : 앞에 3줄 확인
tail -3 파일명 : 뒤에 3줄 확인
more +10 파일명 :
grep "검색어" 파일명 : 검색
grep "[^A-Z]" 파일명* : 해당 파일명을 가진 모든 파일에서 대문자가 아닌 값 검색
whereis java : 파일 설치 모든 경로
whichis java : 파일 설치 경로
ifconfig : ip 확인
su - root : super user 접속
su - hadoop : hadoop 일반 계정에 접속
useradd tom : tom 일반 계정 만들기
passwd tom : tom 일반 계정에 암호설정
exit : 해당 계정 logout
userdel james : 계정 삭제(logout상태에서)
rm -rf james : 잔여 계정목록 삭제
-rwxrw-r-- : user, group, others
chmod u-w test.txt : 현재 사용자에게 쓰기 권한 제거
chmod u-r test.txt : 현재 사용자에게 읽기 권한 제거
chmod u+rwx test. extxt : 현재 사용자에게 읽기/쓰기/excute 권한 추가
./test.txt : 명령어 실행
chmod 777 test.txt : 모든 권한 다 주기
chmod 111 test.txt : excute 권한 다 주기
ls -l : 목록 확인
rpm -qa : 설치 목록확인
rpm -qa java* : java 설치 경로
yum install gimp : 설치
su -c 'yum install gimp': 설치
su -c 'yum remove gimp' : 제거
- gimp 설치
yum list gi* : 특정단어가 들어간 리스트
which gimp : gimp 설치 여부 확인
ls -a /usr/bin/gimp
yum info gimp : 패키지 정보
gimp : 실행
wget https://t1.daumcdn.net/daumtop_chanel/op/20200723055344399.png : 웹상에서 다운로드
wget https://archive.apache.org/dist/httpd/Announcement1.3.txt : 웹상에서 다운로드
- 파일 압축
vi aa
gzip aa : 압축
gzip -d aa.gz : 압축해제
bzip2 aa : 압축
bzip2 -d aa.bz2 : 압축해제
tar cvf my.tar aa bb : 파일 묶기
tar xvf my.tar : 압축 해제
java -version : 자바 버전 확인
su - : 관리자 접속
yum update : 패키지 업데이트
rpm -qa | grep java* : rpm 사용하여 파일 설치
java : 자바 실행
javac : javac 실행
yum remove java-1.8.0-openjdk-headless.x86_64 : 삭제
yum -y install java-11-openjdk-devel : 패키지 설치
rpm -qa | java : 설치 확인
- 이클립스 다운로드
mkdir work : 디렉토리 생성
cd work
eclipse.org - download - 탐색기 - 다운로드 - 복사 - work 붙여넣기
tar xvfz eclipse tab키 : 압축해제
cd eclipse/
./eclipse
work -> jsou
open spective - java
Gerneral - Workspace - utf-8
Web - utf-8
file - new - java project - pro1 / javaSE-11 - Don't create
new - class - test / main
sysout alt /
sum inss
- FlashPlayer 설치
get.adobe.com/kr/flashplayer 접속
wget ftp://ftp.pbone.net/mirror/www.mde.djura.org/2007.0/RPMS/FlashPlayer-9.0.31.0-1mde2007.0.i586.rpm
rm -f FlashPlayer-9.0.31.0-1mde2007.0.i586.rpm
chmod 777 FlashPlayer-9.0.31.0-1mde2007.0.i586.rpm
rpm -Uvh --nodeps FlashPlayer*.rpm
- putty
putty -> ifconfig의 ip -> open -> 예
- centos rpm
- CentOS에 MariaDB 설치
cafe.daum.net/flowlife/HqLk/81
- MySql, MariaDB
cafe.daum.net/flowlife/HqLk/63 에서 다운로드
Build path - Configure Buil - Librarie - classpath - AddExternel JARs - apply
- apache server 다운로드
apache.org 접속
맨아래 Tomcat 클릭
Download / Tomcat 10 클릭
tar.gz (pgp, sha512) 다운로드
터미널 창 접속
ls /~다운로드
cd work
mv ~/다운로드.apach ~~ .gz ./
tar xvfz apache-tomcat-10.0.5.tar.gz
cd apache-tomcat-10.0.5/
cd bin/
pwd
./startup.sh : 서버 실행
http://localhost:8080/ 접속
./shutdown.sh : 서버 종료
./catalina.sh run : 개발자용 서버 실행
http://localhost:8080/ 접속
ctrl + c : 개발자용 서버 종료
cd conf
ls se*
vi server.xml
cd ~
pwd
eclipse 접속
Dynimic web project 생성
이름 : webpro / Targert runtime -> apache 10 및 work - apache 폴더 연결
webapp에 abc.html 생성.
window - web browser - firefox
내용 작성 후 서버 실행.
- R, R Studio Server 설치 및 기타
cafe.daum.net/flowlife/RlkF/11
- R 설치
su - root
yum install epel-release
yum install dnf-plugins-core
yum config-manager --set-enabled powertools
yum install R
R
a <- 10
a
df <- data.frame(value=rnorm(1000, 1, 1))
head(df)
head(df, 3)
q()
- R studio 설치
wget https://download1.rstudio.org/desktop/fedora28/x86_64/rstudio-1.2.5033-x86_64.rpm
rpm -ivh rstudio-1.2.5033-x86_64.rpm
exit
rstudio
install.packages("ggplot2")
library(ggplot2)
a <- 10
print(a)
print(head(iris, 3))
ggplot(data=iris, aes(x = Petal.Length, y = Petal.Width)) + geom_point()
- R studio 서버
vi /etc/selinux/config
SELINUX=permissive으로 수정
reboot
su - root
vi /etc/selinux/config
cd /usr/lib/firewalld/services/
ls http*
cp http.xml R.xml
vi R.xml
port="8787"으로 수정
firewall-cmd --permanent --zone=public --add-service=R
firewall-cmd --reload
https://www.rstudio.com/products/rstudio/download-server/
redhat/centos
wget https://download2.rstudio.org/server/centos7/x86_64/rstudio-server-rhel-1.4.1106-x86_64.rpm
wget https://download2.rstudio.org/server/fedora28/x86_64/rstudio-server-rhel-1.2.5033-x86_64.rpm
yum install --nogpgcheck rstudio-server-rhel-1.4.1106-x86_64.rpm
systemctl status rstudio-server
systemctl start rstudio-server
http://ip addr:8787/auth-sign-in : 본인 ip에 접속
useradd testuser
passwd testuser
ls /home
mkdir mbc
cd mbc
ls
- 프로그램 셋팅 : ipython, anaconda
cafe.daum.net/flowlife/RUrO/44
주의 : VmWare를 사용할 때는 Virtual Machine Settings에서 Processors를 2 이상으로 주도록 하자.
- anaconda 설치
www.anaconda.com/products/individual
Download - Linux / 64-Bit (x86) Installer (529 MB) - 링크주소 복사
wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
chmod +x Anaconda~~
./Anaconda~~
q
yes
vi .bash_profile : 파일 수정
=============================================
PATH=$PATH:$HOME/bin
export PATH
# added by Anaconda3 installer
export PATH="/home/hadoop/anaconda3/bin:$PATH"
==============================================
source .bash_profile
python3
conda deactivate : 가상환경 나오기
source activate base : 가상환경 들어가기
jupyter notebook
jupyter lab
localhost:8888/tree
ctrl + c
y
jupyter notebook --generate-config
python
from notebook.auth import passwd
passwd() #sha1 값 얻기
quit()
비밀번호 설정
Verify password 복사
vi .jupyter/jupyter_notebook_config.py : 파일 수정
ctrl + end
==============================================
c.NotebookApp.password =u' Verify password 붙여넣기 '
==============================================
quit()
vi .jupyter/jupyter_notebook_config.py
su -
cd /usr/lib/firewalld/services/
cp http.xml NoteBook.xml
vi NoteBook.xml
8001포트 설정
:wq
systemctl status firewalld.service 방화벽 서비스 상태 확인 start, stop, enable
firewall-cmd --permanent --zone=public --add-service=NoteBook
firewall-cmd --reload
jupyter notebook --ip=0.0.0.0 --port=8001 --allow-root
jupyter lab --ip=0.0.0.0 --port=8001 --allow-root
vi .jupyter/jupyter_notebook_config.py
==============================================
c.NotebookApp.open_browser = False
==============================================
- 하둡 ppt
cafe.daum.net/flowlife/RZ23/24
: 빅데이터 파일을 여러 대의 서버에 분산 저장(HDFS, Hadoop Distributed File Syetem).
: 각 서버에서 분산병렬 처리.(MapReduce)
: 하둡은 데이터 수정불가.
: sale-out 사용.
- Hadoop 싱글노드로 설치 : Centos 기반 (2020년 기준)
cafe.daum.net/flowlife/RZ23/11
- 하둡 설치
conda deactivate : 가상환경 나오기
java -version : 자바 버전 확인
ls -al /etc/alternatives/java : 자바 경로 확인 후 경로 복사
=> /usr/ ~~ .x86_64 복사
https://apache.org/ 접속 => 맨 밑에 hadoop접속 => Download =>
su - : 관리자 접속
cd /usr/lib/firewalld/services/ : 특정 port 방화벽 해제
cp http.xml hadoop.xml
vi hadoop.xml : 파일 수정 후 저장(:wq)
==============================================
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>Hadoop</short>
<description></description>
<port protocol="tcp" port="8042"/>
<port protocol="tcp" port="9864"/>
<port protocol="tcp" port="9870"/>
<port protocol="tcp" port="8088"/>
<port protocol="tcp" port="19888"/>
</service>
==============================================
firewall-cmd --permanent --zone=public --add-service=hadoop
firewall-cmd --reload
exit
wget http://apache.mirror.cdnetworks.com/hadoop/common/hadoop-3.2.1/hadoop-3.2.1.tar.gz
tar xvzf hadoop-3.2.1.tar.gz
vi .bash_profile
==============================================
# User specific environment and startup programs
export JAVA_HOME=/usr/ ~~ .x86_64 붙여넣기
export HADOOP_HOME=/home/사용자명/hadoop-3.2.1
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin #추가
export PATH
==============================================
source .bash_profile : .bash_profile을 수정된 내용으로 등록
conda deactivate
ls
cd hadoop-3.2.1/
vi README.txt
vi kor.txt : 임의 내용 입력
cd etc
cd hadoop
pwd
vi hadoop-env.sh : 파일 상단에 입력
==============================================
export JAVA_HOME=/usr/ ~~ .x86_64 붙여넣기
==============================================
vi core-site.xml : 하둡 공통 설정을 기술
==============================================
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/사용자명/hadoop-3.2.1/tmp/</value>
</property>
</configuration>
==============================================
vi hdfs-site.xml : HDFS 동작에 관한 설정
==============================================
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
==============================================
vi yarn-env.sh : yarn 설정 파일
==============================================
export JAVA_HOME=/usr/ ~~ .x86_64 붙여넣기
==============================================
vi mapred-site.xml : yarn 설정 파일
==============================================
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.admin.user.env</name>
<value>HADOOP_MAPRED_HOME=$HADOOP_COMMON_HOME</value>
</property>
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=$HADOOP_COMMON_HOME</value>
</property>
</configuration>
==============================================
vi yarn-site.xml
==============================================
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
</configuration>
==============================================
cd : root로 이동
hdfs namenode -format
hadoop version : 하둡 버전 확인
ssh : 원격지 시스템에 접근하여 암호화된 메시지를 전송할 수 있는 프로그램
ssh-keygen -t rsa : ssh 키 생성. enter 3번.
cd .ssh
scp id_rsa.pub /home/사용자명/.ssh/authorized_keys : 생성키를 접속할 때 사용하도록 복사함. yes
ssh 사용자명@localhost
start-all.sh : deprecated
start-dfs.sh
start-yarn.sh
mr-jobhistory-daemon.sh start historyserver : 안해도됨
jps : 하둡 실행 상태 확인 - NameNode와 DataNode의 동작여부 확인
stop-all.sh : deprecated
stop-dfs.sh
stop-yarn.sh
http://localhost:9870/ 접속 : Summary(HDFS 상태 확인)
http://localhost:8088/ 접속 : All Applications
- Map/Reduce 처리과정
cafe.daum.net/flowlife/RZ23/17
- 워드 카운트
conda deactivate
cd hadoop-3.2.1/
hdfs dfs -mkdir /test
hdfs dfs -ls/test
hdfs dfs -copyFromLocal ./README.txt /test : 복사
hdfs dfs -cat /test/README.txt
hadoop jar /home/사용자명/hadoop-3.2.1/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.1.jar wordcount /test/README.txt /output : map/reduce 작업 진행.
hdfs dfs -ls /output : 목록확인
hdfs dfs -cat /output/part-r-00000
hdfs dfs -ls /
hdfs dfs -rm /output/part* : 파일삭제
hdfs dfs -rm /output/_SUCCESS
hdfs dfs -rmdir /output
hdfs dfs -put ./kor.txt /test
hadoop jar /home/사용자명/hadoop-3.2.1/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.1.jar wordcount /test/kor.txt /daumdata
hdfs dfs -get /daumdata/part* happy.txt : 하둡에서 파일 가져오기
ls
vi happy.txt
- eclipse + hadoop 연동
conda deactivate
start-dfs.sh
start-yarn.sh
jps
http://localhost:9870/ 접속 : Summary(HDFS 상태 확인)
http://localhost:8088/ 접속 : All Applications
eclipse 실행
Tensorflow.js 간단한 예
cafe.daum.net/flowlife/S2Ul/27
* abc.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>tensorflow.js sample</title>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.0/dist/tf.min.js"></script>
<script type="text/javascript">
function abc(){
// 선형회귀 모델 생성
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
// 학습을 위한 준비 : 손실 함수와 최적화 함수를 설정
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
// 학습 데이터
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
// 데이터를 사용해서 학습
model.fit(xs, ys).then(() => {
// 학습된 모델로 결과 예측값 얻기
pred = model.predict(tf.tensor2d([5], [1, 1]))
pred.print() // console로 출력
document.write('예측값 : ', pred);
});
}
</script>
</head>
<body>
결과는 브라우저의 콘솔로 확인하세요.
<br>
<button xxxxxxxxxxxxonclick="abc()">클릭</button>
</body>
</html>
propertive - javaSE
프로젝트 생성
hadoop_pro
Java1.8
프로젝트 오른쪽 클릭
Configure - Convert to Maven Project
* pom.xml
hadoop-common 검색
apache
3.2.1
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>3.2.1</version>
</dependency>
hadoop-client
apache
3.2.1
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.2.1</version>
</dependency>
hadoop-hdfs
apache
3.2.1
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>3.2.2</version>
</dependency>
hadoop-mapreduce-client-core
apache
3.2.1
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>3.2.2</version>
</dependency>
- example code download
Documentation - 3.2.2
MapReduce
Tutorial
Example: WordCount v1.0 - Source Code
src - new - class - pack.WordCount
* WordCount.java
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class WordCount {
public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public static class IntSumReducer
extends Reducer<Text,IntWritable,Text,IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values,
Context context
) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
conf.set("fs.default.name", "hdfs://localhost:9000");
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path("hdfs://localhost:9000/test/data.txt"));
FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:9000/out1"));
System.out.println("success");
//FileInputFormat.addInputPath(job, new Path(args[0]));
//FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
ls
cd hadoop-3.2.1/
vi data.txt
임의 텍스트 입력
hdfs dfs -put data.txt /test
hdfs dfs -get /out1/part* result1.txt
vi result1.txt
vi vote.txt
임의 텍스트 입력
hdfs dfs -put vote.txt /test
src - new - class - pack2.VoteMapper
* VoteMapper.java
import java.util.regex.*;
import org.apache.hadoop.io.IntWritable
import org.apache.hadoop.io.Text
import org.apache.hadoop.mapreduce.Mapper
public class VoteMapper extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
@Override
public void map(Object ket, Text value, Context context)throws IOException, InterruptedException{
String str = value.toString();
System.out.println(str);
String regex = "홍길동|신기해|한국인";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
String result = "";
while(match.find()){
result += matcher.group() + "";
}
StringTokenizer itr = new StringTokenizer(result);
while(itr.hasMoreTokens()){
word.set(itr.nextToken());
context.write(word, one);
}
}
}
src - new - class - pack2.VoteReducer
* VoteReducer.java
public class VoteReducer extends Reducer<Textm IntWritable, Text, IntWritable>{
private IntWritable result = new IntWritable();
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context) throw IOException, InterruptedException{
int sum = 0;
for(IntWritable val:values){
sum += val.get();
}
result.set(sum);
context.wrtie(key, result);
}
}
src - new - class - pack2.VoteCount
* VoteCount.java
public class VoteCount{
public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();
conf.set("fs.default.name", "hdfs://localhost:9000");
Job job = Job.getInstance(conf, "vote");
job.setJarByClass(VoteCount.class);
job.setMapperClass(VoteMapper.class);
job.setCombinerClass(VoteReducer.class);
job.setReducerClass(VoteReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path("hdfs://localhost:9000/test/vote.txt"));
FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:9000/out2"));
System.out.println("end");
System.exit(job.waitForCompletion(true)?0:1);
}
}
hdfs dfs -get /out2/part* result2.txt
'BACK END > Python Library' 카테고리의 다른 글
[Pandas] pandas 정리2 - db, django (0) | 2021.03.02 |
---|---|
[MatPlotLib] matplotlib 정리 (0) | 2021.03.02 |
[Pandas] pandas 정리 (0) | 2021.02.24 |
[NumPy] numpy 정리 (0) | 2021.02.23 |