# Centos/RHEL7 기술노트
# Centos 7 Run level 변경방법
자주 사용하는 시스템 런레벨
**런레벨** | **용도** |
0 | 종료 |
1 | 싱글사용자 |
2 | 다중사용자 (multi-user.target) |
5 | 그래픽 환경 (graphic.target) |
6 | 재부팅 |
Centos7에서는 아래 명령어로 변경 가능 (재부팅 후부터 반영)
```shell
[root@localhost ~]# systemctl set-default graphical.target
```
현재환경에서 변경
```shell
[root@localhost ~]# systemctl isolate graphical.target
```
현재 사용중인 런레벨 확인 방법
1. who명령어로 확인 ```shell
[root@localhost ~]# who -r
run-level 3 2014-09-18 10:22
```
2. systemctl 명령어로 확인 ```shell
[root@localhost ~]# systemctl get-default multi-user.target
```
# Centos7(vsftp 3.x) chroot적용하기
Centos7에서 vsftp 구성할때, 일반 사용자가 홈디렉토리 상단으로 올라오지 못하게 하는 chroot 옵션만 넣으면 FTP접근이 안됨.
응답 500 OOPS:vsftpd:refusing to run with writable root inside chroot()
```shell
$> vi /etc/vsftpd/vsftpd.conf
...
chroot_loca_user=YES
...
```
보통 이렇게만 설정하는데, Centos7(VSFTP 3.x)에서는 저렇게만 하면 접속이 안된다.
[](http://igoni.kr/uploads/images/gallery/2022-06/image-1654587303751.png)
이런 메시지를 보게 될 것이야…;;
그래서 한줄 더 넣어줘야 한다. chroot가 적용된 사용자만 쓰기권한부여 하는 옵션..
```shell
$> vi /etc/vsftpd/vsftpd.conf
...
allow_writeable_chroot=YES
...
```
그리고 나서 서비스 재시작 하면 원하는 파일리스트가 잘 나온다~ 짜잔~~
```shell
$> systemctl restart vsftpd.service
```
# Centos7에 프록시 서버 설정하기
1. Squid 패키지 설치 ```shell
$> yum install -y squid
```
2. 설정파일 확인 ```shell
$> vi /etc/squid/squid.conf
...
acl 정책이름 (소스정보/목적지정보) (ip/class)
acl proxy_net src 127.0.0.1/32
acl proxy_net src 1.2.3.4/24
* proxy_net이라는 정책으로, 소스IP가 127.0.0.1, 1.2.3.4에 대해서 적용
...
#ACL설정방법
http_access 적용방법 정책명
http_access allow proxy_net
http_access deny all
* 정책명이 proxy_net인 정보를 제외하고 모두 거부
...
#프록시 접근포트
http_port 8080
#캐쉬정보
cache_dir ufs /dev/shm/squid 100 5 10
#덤프파일 경로
coredump_dir /dev/shm/squid
#캐쉬데이터 보관주기
refresh_pattern . 5 20% 360
#5분동안 20%의 예전데이터를 보관하고 최대 360분까지 캐쉬데이터를 보관.
```
3. 서비스 활성화 ```shell
$> systemctl enable squid --now
```
4. 디렉토리 구조 설명
1. /var/spool/squid 디렉토리에 최대 100M까지 1차로 생성하는 디렉토리는 5개까지, 2차 디렉토리는 10개까지 설정
2. 기본값은 1차는 16개까지, 2차는 256개까지 생성하는 값
3. 디렉토리 구조는 다음과 같이 생성된다 ```shell
$> ls -l /var/spool/squid/
/var/spool/squid/00
/var/spool/squid/00/00
/var/spool/squid/00/01
/var/spool/squid/00/02
/var/spool/squid/00/03
…
/var/spool/squid/00/09
/var/spool/squid/01
/var/spool/squid/01/00
/var/spool/squid/01/01
/var/spool/squid/01/02
/var/spool/squid/01/03
…
/var/spool/squid/01/09
```
# centos7에서 vnc 구성하기
1. VNC패키지 설치 ```shell
$ yum install -y tiger*
```
2. 설정파일 복사 ```shell
$ cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@\:2.service
```
3. 설정파일 편집 ```shell
$ vi /etc/systemd/system/vncserver@\:2.service
...
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1024x768"
PIDFile=/root/.vnc/%H%i.pid
```
4. 설정파일 읽어오기 ```shell
$ systemctl daemon-reload
```
5. vnc 패스워드 파일 성성 (두번입력) ```shell
$ vncpasswd
Password:
Password:
```
6. VNC 서비스 활성화 및 실행 ```shell
$ systemctl enable vncserver@:2.service --now
```
7. VNC 서비스 중지 ```shell
$ systemctl stop vncserver@:2.service
```
8. vnc서비스 자동으로 비활성화 ```shell
$ systemctl disable vncserver@:2.service
```
# Centos7환경에서 VNC서비스 실행시킬때 vnc failed로 응답할때
1. VNC 구동시 Fail로그 확인 ```shell
$> systemctl start vncserver@:2.service
Job for vncserver@:2.service failed. See 'systemctl status vncserver@:2.service' and 'journalctl -xn' for details.
```
2. 프로세스 실행여부 확인 ```shell
[root@localhost /]# ps -ef | grep vnc
test 24303 1 0 20:08 ? 00:00:00 /usr/bin/Xvnc :2 -desktop
192.168.0.100:2 (test) -httpd /usr/share/vnc/classes -auth
/home/test/.Xauthority -geometry 600×800 -rfbwait 30000 -rfbauth
/home/test/.vnc/passwd -rfbport 5902 -fp catalogue:/etc/X11/fontpath.d
-pn -nolisten tcp
test 24310 1 0 20:08 ? 00:00:00 /usr/bin/vncconfig -iconic
root 25037 21274 0 20:09 pts/0 00:00:00 grep –color=auto vnc
```
3. 프로세스가 실행중이기 때문에, VNC viewer로 접속하거나, 프로세스가 이상할 경우에는 서비스 재시작.
4. 실행중인 포트 확인
```shell
[root@localhost tmp]# netstat -antp | grep vnc
tcp 0 0 0.0.0.0:5802 0.0.0.0:* LISTEN 24303/Xvnc
tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN 24303/Xvnc
```
- 기본적으로 5900을 기본으로 뒤에 디스플레이번호에 따라서 1자리 포트가 바뀜.
- 2번 디스플레이일경우에는 5902, 5번 디스플레이이면 5905번 포트가 LISTEN으로 됨.
- 2. 1번 사항대로 확인했는데 아무것도 없을때….
- VNC서비스를 실행시키면서 생성되는 파일이 정상적으로 삭제되지 않았기 때문인데,
- VNC가 활성화 되어 있는 상태에서 재부팅이 이루어지면 이런 현상이 자주 발생하고 있네요.
- /tmp/.ICE-unix /tmp/.X11-unix 폴더가 제거되지 않았을 경우에 이렇게 때문에 해당 파일을 삭제해주면 됨. ```shell
$> ls -al /tmp
total 48
drwxrwxrwt. 11 root root 12288 Dec 29 20:15 .
drwxr-xr-x. 20 root root 4096 Dec 29 12:58 ..
drwxrwxrwt 2 test test 30 Dec 29 20:08 .ICE-unix
drwxrwxrwt 2 test test 15 Dec 29 20:08 .X11-unix
```
\#.ICE-unix, .X11-unix 이 두개 폴더 삭제
```shell
$> rm -rf /tmp/.ICE-unix /tmp/.X11-unix
```
- 서비스 재실행 ```shell
$> systemctl start vncserver@:2.service
```