--- tags: Dynasafe --- # Nexus 安裝 # Nexus ## 環境需求 * ### 作業系統: CentOS8 * ### JDK版本: 1.8以上 * ### Nexus版本: 3.33.1 * ### VM IP: 192.168.50.29 ## 安裝包 ### [官方載點](https://help.sonatype.com/repomanager3/download) ### ![](https://i.imgur.com/A78hWZE.png) ## 啟動步驟 ### 1. 複製安裝包到VM `/root` ![](https://i.imgur.com/wLmQR83.png) ### 2. 檢查 JDK 版本 ``` [root@localhost ~]java -version openjdk version "1.8.0_201" OpenJDK Runtime Enviroment (build 1.8.0_201-b09) OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode) ``` ### 3. 配置環境變數 ( 可忽略 ) ``` [root@localhost ~]vi /etc/profile export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64 export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin --生效環境變數-- [root@localhost ~]source /etc/profile ``` ### 4. 創建資料夾 ( 放置nexus壓縮檔 ) ``` [root@localhost ~]mkdir /data/apps/nexus ``` ### 5. 解壓縮到剛剛創建的資料夾 ``` [root@localhost ~]tar -zxvf nexus-3.33.1-01-unix.tar.gz -C /data/apps/nexus ``` ### 6. 進入指定路徑 ``` [root@localhost ~]cd /data/apps/nexus/ [root@localhost nexus]ls nexus-3.33.1-01 sonatype-work ``` ### 7. 進入到執行檔 ``` [root@localhost nexus]cd nexus-3.33.1-01/bin/ [root@localhost bin]ls contrib nexus nexus.rc nexus.vmoptions ``` ### 8. 運行Nexus ``` [root@localhost bin]./nexus start WARNING: ************************************************************ WARNING: Detected execution as "root" user. This is NOT recommended! WARNING: ************************************************************ Starting nexus -- 運行狀態 -- [root@localhost bin]./nexus status WARNING: ************************************************************ WARNING: Detected execution as "root" user. This is NOT recommended! WARNING: ************************************************************ nexus is running. --暫停Nexus-- [root@localhost bin]./nexus stop WARNING: ************************************************************ WARNING: Detected execution as "root" user. This is NOT recommended! WARNING: ************************************************************ Shutting down nexus Stopped. --重新啟動Nexus-- [root@localhost bin]./nexus restart ``` ### 9. 連線測試 ``` 連線到 http://[ ip ]:8081 ``` ### 10. Service Mode (non-root) #### 1. 創建 Nexus User ``` // create a system account // do not create the user's home directory // login shell of the new account $ useradd -r -M -s /sbin/nologin nexus ``` #### 2. 修改Nexus檔案 的 Group ``` // 路徑要為 Nexus檔案路徑 $ chown nexus:nexus -R /data ``` #### 3. Create nexus.service ``` $ vi /etc/systemd/system/nexus.service ... [Unit] Description=nexus service After=network.target [Service] Type=forking LimitNOFILE=65536 =========> Nexus 最低要求 ExecStart=/data/apps/nexus/nexus-3.33.1-01/bin/nexus start =========> Nexus 檔案路徑 ExecStop=/data/apps/nexus/nexus-3.33.1-01/bin/nexus stop =========> Nexus 檔案路徑 User=nexus =========> 剛剛創建的使用者名稱 Restart=on-abort TimeoutSec=600 [Install] WantedBy=multi-user.target ``` #### 4. 修改啟動Nexus的使用者 ``` vi /data/nexus/nexus-3.33.1-01/bin/nexus.rc ... run_as_user="nexus" ``` #### 5. 啟動 nexus.service ``` $ systemctl daemon-reload $ systemctl enable nexus.service $ systemctl start nexus.service ``` #### 6. 測試 stop nexus.service 是否有錯誤 ``` // 會發現 有錯誤 $ systemctl status nexus.service ... Active: failed (Result: exit-code) since Fri 2021-08-27 11:31:17 CST; 2min 4s ago ... // 這是因為在 /data 底下的檔案 有些Group還是 root $ ls -lR /data/ | grep root -rw-r--r-- 1 root root 6560 Aug 27 11:27 cache.stt -rw-r--r-- 1 root root 6560 Aug 27 11:27 component.28.wal ... // <sol> 重新執行 $ chown nexus:nexus -R /data // 再重啟 nexus.service $ systemctl daemon-reload $ systemctl restart nexus.service ``` ## 錯誤排除 ### • 無 JDK 1. #### 掛載 iso 2. #### Mount RHEL CD and set yum repository 1. ##### 列出系統上的所有磁碟列表 ``` $ lsblk -fp ``` ![](https://i.imgur.com/UoWXP65.png) 2. ##### 掛載磁碟 ``` $ mount -t [ FSTYPE ] [ 磁碟NAME ] [ 掛載點 ] $ mount -t iso9660 /dev/sr0 /mnt $ lsblk -fp ``` ![](https://i.imgur.com/ylGeWNn.png) 3. ##### 查看掛載的詳細檔案 ``` $ ls /mnt // 主要使用 AppStream、BaseOS ``` ![](https://i.imgur.com/oqfO5MN.png) 4. ##### 撰寫 repo檔 ``` $ vi /etc/yum.repo.d/AppStream.repo [AppStream] name=DVD for Red Hat Enterprise Linux 7.9 Server gpgcheck=0 enabled=1 baseurl=file:///mnt/AppStream/ $ vi /etc/yum.repos.d/BaseOS.repo [BaseOS] name=DVD for Red Hat Enterprise Linux 7.9 Server gpgcheck=0 enabled=1 baseurl=file:///mnt/BaseOS/ ``` 5. ##### 查詢 JDK ``` $ yum search java | grep jdk ``` 6. ##### 下載 JDK ``` $ yum install java-1.8.0-openjdk.x86_64 ``` ### • 無法連線 #### 排解1. 查詢Port是否監聽 ``` $ sudo netstat -anopt Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name Timer tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 14297/java off (0.00/0/0) tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1143/sshd off (0.00/0/0) tcp 0 0 127.0.0.1:39259 0.0.0.0:* LISTEN 14297/java off (0.00/0/0) tcp 0 48 192.168.50.29:22 10.8.4.4:62154 ESTABLISHED 8439/sshd: root [pr on (0.20/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:52569 ESTABLISHED 13774/sshd: root [p keepalive (6459.42/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:59545 ESTABLISHED 13704/sshd: root [p keepalive (6307.73/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:52570 ESTABLISHED 13779/sshd: root [p keepalive (6459.92/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:52285 ESTABLISHED 13632/sshd: root [p keepalive (6107.99/0/0) tcp 0 0 192.168.50.29:22 10.8.4.4:50742 ESTABLISHED 8614/sshd: root [pr keepalive (2324.45/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:59546 ESTABLISHED 13709/sshd: root [p keepalive (6308.25/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:52284 ESTABLISHED 13627/sshd: root [p keepalive (6107.45/0/0) tcp6 0 0 :::22 :::* LISTEN 1143/sshd off (0.00/0/0) ``` #### 排解2. curl url 是否正常 ``` $ curl localhost:8081 <!DOCTYPE html> <html lang="en"> <head> <title>Nexus Repository Manager</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="description" content="Nexus Repository Manager"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> ... $ curl [ ip ]:8081 <!DOCTYPE html> <html lang="en"> <head> <title>Nexus Repository Manager</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="description" content="Nexus Repository Manager"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> ... ``` #### 排解3. 防火牆 開啟指定Port ``` -- 查詢指定Port是否開通 -- $ firewall-cmd --query-port=[ port ]/tcp <ex> $ firewall-cmd --query-port=8081/tcp -- 開啟指定Port -- $ firewall-cmd --add-port=[ port ]/tcp --permanent <ex> $ firewall-cmd --add-port=8081/tcp --permanent -- reload firewall -- $ firewall-cmd --reload -- 重啟防火牆 -- $ systemctl restart firewalld ``` #### 4. 測試連線 ``` 連線到 http://[ ip ]:8081 ``` #### 5. 查看netState ``` $ sudo netstat -anopt Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name Timer tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 14297/java off (0.00/0/0) tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1143/sshd off (0.00/0/0) tcp 0 0 127.0.0.1:39259 0.0.0.0:* LISTEN 14297/java off (0.00/0/0) tcp 0 0 192.168.50.29:8081 10.8.4.4:57827 ESTABLISHED 14297/java off (0.00/0/0) tcp 0 0 192.168.50.29:8081 10.8.4.4:63374 ESTABLISHED 14297/java off (0.00/0/0) tcp 0 48 192.168.50.29:22 10.8.4.4:62154 ESTABLISHED 8439/sshd: root [pr on (0.20/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:52569 ESTABLISHED 13774/sshd: root [p keepalive (6442.33/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:59545 ESTABLISHED 13704/sshd: root [p keepalive (6290.64/0/0) tcp 0 0 192.168.50.29:8081 10.8.4.4:58865 ESTABLISHED 14297/java off (0.00/0/0) tcp 0 0 192.168.50.29:8081 10.8.4.4:63150 ESTABLISHED 14297/java off (0.00/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:52570 ESTABLISHED 13779/sshd: root [p keepalive (6442.83/0/0) tcp 0 0 192.168.50.29:8081 10.8.4.4:60257 ESTABLISHED 14297/java off (0.00/0/0) tcp 0 0 192.168.50.29:8081 10.8.4.4:49973 ESTABLISHED 14297/java off (0.00/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:52285 ESTABLISHED 13632/sshd: root [p keepalive (6090.90/0/0) tcp 0 0 192.168.50.29:22 10.8.4.4:50742 ESTABLISHED 8614/sshd: root [pr keepalive (2307.37/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:59546 ESTABLISHED 13709/sshd: root [p keepalive (6291.16/0/0) tcp 0 0 192.168.50.29:22 10.8.14.184:52284 ESTABLISHED 13627/sshd: root [p keepalive (6090.37/0/0) tcp6 0 0 :::22 :::* LISTEN 1143/sshd off (0.00/0/0) ``` ### • File Descriptors #### 1. 編輯` /etc/security/limits.conf ` ``` $ vi /etc/security/limits.conf ... @root - nofile 65536 ``` ![](https://i.imgur.com/PesJNLM.png) #### 2. 編輯 ` /data/apps/nexus/nexus-3.33.1-01/bin/nexus.rc ` ``` run_as_user="root" ``` #### 3. 重新啟動Nexus、Linux ``` $ systemctl restart nexus.service $ reboot ``` ### • DMZ SELinux 起服務失敗 #### 錯誤訊息 ``` Aug 31 03:09:23 localhost.nexus03 setroubleshoot[11125]: failed to retrieve rpm info for /data/nexus/nexus-3.33.1-01/bin/nexus Aug 31 03:09:23 localhost.nexus03 setroubleshoot[11125]: SELinux is preventing /usr/lib/systemd/systemd from execute_no_trans access on the ``` #### 解決方案 ``` $ ausearch -c '(nexus)' --raw | audit2allow -M my-nexus ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i my-nexus.pp ``` ``` $ semodule -X 500 -i my-nexus.pp libsemanage.semanage_direct_install_info: Overriding my-nexus module at lower priority 400 with module at priority 500. ``` ``` $ systemctl reset-failed $ systemctl restart nexus.service ``` ## Log ### Log位置 ` ${ 安裝資料夾 }/sonatype-work/nexus3/log/nexus.log ` # 實際安裝紀錄 ## 20210825 ### 進度 1. #### 將 Nexus 導入並啟動 ( Not Service mode ) ( 226、227 ) 2. #### mount RHEL CD ( 226、227 ) ### 問題 1. #### 無法 ssh DMZ 2. #### 無 jdk 需下載 3. #### File Descriptor 問題 ## 20210826 ### 進度 1. #### 能夠 ssh DMZ 2. #### mount RHEL CD ( DMZ ) 3. #### 安裝 jdk ( DMZ ) 4. #### 將 Nexus 導入並啟動 ( Not Service mode ) ( DMZ ) 5. #### File Descriptors 錯誤排除 ( 226、227 ) 6. #### 改為 Service Mode ( 三台 ) ### 問題 1. #### DMZ Service Failed ## 20210827 ### 進度 1. #### 創建新帳號,並用新帳號啟動 2. #### 將 Nexus 專案改放到 /data ### 問題 1. #### yum repo fail ## 20210902 ### 進度 #### [ 228 ] ##### Maven * ###### proxy to proxy 下載 Gson * ###### 上傳 * ###### 下載 ##### Python * ###### proxy to proxy 下載 twine * ###### 上傳 * ###### 下載 ### 問題 #### Python 下載 只向Hosted 請求失敗 ##### [ ERROR ] Could not finnd a version that satisfies the requirement thirft==0.10.0 (from xxxxxxxx) (from version: none) ##### [ ERROR ] No matching distribution found for thrift==0.10.0 # LVM ## 架構 ![](https://i.imgur.com/YG5Q2Bt.jpg) ## 名詞介紹 ### PV ( Physical Volume ) * #### 物理卷。 是 PP 的LVM抽象,維護了PP的結構信息。一般一個 PV 對應一個 PP。 * #### 組成VG的基本邏輯單元 ### VG ( Volume Group ) * #### 卷組,即 LVM 卷組。 * #### 可由一個或數個 PV 組成。 ### LV ( Logical Volume ) * #### 邏輯卷。 * #### 它建立在 VG 之上,文件系統之下。 * #### 由多個 LE 組成 ## 創建 LVM 磁碟 ### 查看硬碟 ``` $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 600M 0 part ├─sda2 8:2 0 1G 0 part /boot └─sda3 8:3 0 48.4G 0 part ├─rhel-root 253:0 0 44.5G 0 lvm / └─rhel-swap 253:1 0 4G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk ├─sdb1 8:17 0 30G 0 part │ └─nexus_vg-nexus_lg 253:2 0 70G 0 lvm /opt/sonatype └─sdb2 8:18 0 20G 0 part └─nexus_vg-nexus_lg 253:2 0 70G 0 lvm /opt/sonatype sdc 8:32 0 10G 0 disk └─nexus_vg-nexus_lg 253:2 0 70G 0 lvm /opt/sonatype sdd 8:48 0 10G 0 disk └─nexus_vg-nexus_lg 253:2 0 70G 0 lvm /opt/sonatype sr0 11:0 1 1024M 0 rom ``` ### 創建PV ``` $ pvcreate /dev/sda1 WARNING: vfat signature detected on /dev/sda1 at offset 82. Wipe it? [y/n]: y Wiping vfat signature on /dev/sda1. WARNING: vfat signature detected on /dev/sda1 at offset 0. Wipe it? [y/n]: y Wiping vfat signature on /dev/sda1. WARNING: vfat signature detected on /dev/sda1 at offset 510. Wipe it? [y/n]: y Wiping vfat signature on /dev/sda1. Physical volume "/dev/sda1" successfully created. $ pvscan PV /dev/sdb1 VG nexus_vg lvm2 [<30.00 GiB / 0 free] PV /dev/sdb2 VG nexus_vg lvm2 [<20.00 GiB / 0 free] PV /dev/sdc VG nexus_vg lvm2 [<10.00 GiB / 0 free] PV /dev/sdd VG nexus_vg lvm2 [<10.00 GiB / 4.00 MiB free] PV /dev/sda3 VG rhel lvm2 [48.41 GiB / 0 free] PV /dev/sda1 lvm2 [600.00 MiB] Total: 6 [118.98 GiB] / in use: 5 [118.39 GiB] / in no VG: 1 [600.00 MiB] $ pvdisplay --- NEW Physical volume --- PV Name /dev/sda1 VG Name PV Size 600.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID CrRIgS-NWo1-1aXa-KF0S-qdgo-BGwd-WA2JE0 ``` ### 創建VG ``` $ vgcreate nexus_vg2 /dev/sda1 Volume group "nexus_vg2" successfully created $ vgscan Found volume group "nexus_vg" using metadata type lvm2 Found volume group "rhel" using metadata type lvm2 Found volume group "nexus_vg2" using metadata type lvm2 $ vgdisplay --- Volume group --- VG Name nexus_vg2 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 596.00 MiB PE Size 4.00 MiB Total PE 149 Alloc PE / Size 0 / 0 Free PE / Size 149 / 596.00 MiB VG UUID clHJKm-6PVy-Y7Cf-9c5Y-ymkA-iZMb-WR6fAz ``` ### 創建LV ``` ------------ lvcreate -L < 容量參照輸入vgdisplay後得到的(VG Size) - 10 Mi > < VG名稱 > -n < LV名稱 > $lvcreate -L 586.00Mi nexus_vg2 -n nexus_lg2 Rounding up size to full physical extent 588.00 MiB Logical volume "nexus_lg2" created. $ lvscan ACTIVE '/dev/nexus_vg/nexus_lg' [69.98 GiB] inherit ACTIVE '/dev/rhel/swap' [3.96 GiB] inherit ACTIVE '/dev/rhel/root' [<44.45 GiB] inherit ACTIVE '/dev/nexus_vg2/nexus_lg2' [588.00 MiB] inherit $ lvdisplay --- Logical volume --- LV Path /dev/nexus_vg2/nexus_lg2 LV Name nexus_lg2 VG Name nexus_vg2 LV UUID DvX8aJ-JV8c-CIpX-djb5-8c69-IX8r-UR6bpx LV Write Access read/write LV Creation host, time localhost.localdomain, 2021-08-22 22:18:46 -0400 LV Status available # open 0 LV Size 588.00 MiB Current LE 147 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 ``` ### 格式化為XFS格式 ``` $ mkfs.xfs /dev/nexus_vg2/nexus_lg2 meta-data=/dev/nexus_vg2/nexus_lg2 isize=512 agcount=4, agsize=37632 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=150528, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=1368, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 mkfs.xfs /dev/nexus_vg2/nexus_lg2 meta-data=/dev/nexus_vg2/nexus_lg2 isize=512 agcount=4, agsize=37632 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=150528, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=1368, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 ``` ### 查詢 UUID ``` $ lsblk -fp NAME FSTYPE LABEL UUID MOUNTPOINT /dev/sda ├─/dev/sda1 LVM2_member CrRIgS-NWo1-1aXa-KF0S-qdgo-BGwd-WA2JE0 │ └─/dev/mapper/nexus_vg2-nexus_lg2 xfs 85adf7a6-6209-454f-b7a9-8811e9b69292 ├─/dev/sda2 xfs 7cd41d7e-edab-4bd9-852a-087570b62c4c /boot └─/dev/sda3 LVM2_member 311bc2-STkt-AVdI-Svi6-VJVI-GMc0-IaLrok ├─/dev/mapper/rhel-root xfs 2f2e81ce-6f7f-4bdd-a67e-2186dcec0977 / └─/dev/mapper/rhel-swap swap 013bcacb-2e26-4b30-b0cc-4feddab6dc7e [SWAP] /dev/sdb ├─/dev/sdb1 LVM2_member 1Pf1ex-ZU2k-LGhQ-Q1qg-23BM-CZYA-BT6yAA │ └─/dev/mapper/nexus_vg-nexus_lg xfs 86513db9-1da4-4130-a6e5-72167e19dd23 /opt/sonatype └─/dev/sdb2 LVM2_member VGGQX0-d5Tu-GGD4-Z4DB-Lggi-FAry-7IJAvb └─/dev/mapper/nexus_vg-nexus_lg xfs 86513db9-1da4-4130-a6e5-72167e19dd23 /opt/sonatype /dev/sdc LVM2_member ZUJGea-9lsP-IOOu-q1ua-C8xw-XOUt-8WCpcW └─/dev/mapper/nexus_vg-nexus_lg xfs 86513db9-1da4-4130-a6e5-72167e19dd23 /opt/sonatype /dev/sdd LVM2_member cS8OfD-eWjH-THHk-8zMa-8qBH-wfo6-2GQ2dK └─/dev/mapper/nexus_vg-nexus_lg xfs 86513db9-1da4-4130-a6e5-72167e19dd23 /opt/sonatype /dev/sr0 ``` ### 掛載硬碟於指定位置 1. #### 創建要掛載的資料夾 ``` $ mkdir /opt/sonatype2/ ``` 2. #### 修改檔案 ``` ------------ 寫入剛剛的UUID、掛載的資料夾和檔案系統 -------------- $ vi /etc/fstab UUID=85adf7a6-6209-454f-b7a9-8811e9b69292 /opt/sonatype2 xfs defaults 0 0 ``` 3. #### mount /etc/fstab 下的所有內容 ``` $ mount -a $ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.8M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/rhel-root 45G 3.5G 41G 8% / /dev/sda2 1014M 197M 818M 20% /boot /dev/mapper/nexus_vg-nexus_lg 70G 532M 70G 1% /opt/sonatype tmpfs 374M 0 374M 0% /run/user/0 /dev/mapper/nexus_vg2-nexus_lg2 583M 34M 549M 6% /opt/sonatype2 ``` ## 擴大LVM磁碟 ### 查看硬碟 ``` $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 600M 0 part │ └─nexus_vg2-nexus_lg2 253:3 0 588M 0 lvm /opt/sonatype2 ├─sda2 8:2 0 1G 0 part /boot └─sda3 8:3 0 48.4G 0 part ├─rhel-root 253:0 0 44.5G 0 lvm / └─rhel-swap 253:1 0 4G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk ├─sdb1 8:17 0 30G 0 part │ └─nexus_vg-nexus_lg 253:2 0 70G 0 lvm /opt/sonatype └─sdb2 8:18 0 20G 0 part └─nexus_vg-nexus_lg 253:2 0 70G 0 lvm /opt/sonatype sdc 8:32 0 10G 0 disk └─nexus_vg-nexus_lg 253:2 0 70G 0 lvm /opt/sonatype sdd 8:48 0 10G 0 disk └─nexus_vg-nexus_lg 253:2 0 70G 0 lvm /opt/sonatype sr0 11:0 1 1024M 0 rom ``` ### 創建PV ``` $ pvcreate /dev/sda2 WARNING: xfs signature detected on /dev/sda2 at offset 0. Wipe it? [y/n]: y Wiping xfs signature on /dev/sda2. Physical volume "/dev/sda2" successfully created. $ pvscan PV /dev/sdb1 VG nexus_vg lvm2 [<30.00 GiB / 0 free] PV /dev/sdb2 VG nexus_vg lvm2 [<20.00 GiB / 0 free] PV /dev/sdc VG nexus_vg lvm2 [<10.00 GiB / 0 free] PV /dev/sdd VG nexus_vg lvm2 [<10.00 GiB / 4.00 MiB free] PV /dev/sda3 VG rhel lvm2 [48.41 GiB / 0 free] PV /dev/sda1 VG nexus_vg2 lvm2 [596.00 MiB / 8.00 MiB free] PV /dev/sda2 lvm2 [1.00 GiB] Total: 7 [<119.98 GiB] / in use: 6 [<118.98 GiB] / in no VG: 1 [1.00 GiB] $ pvdisplay --- NEW Physical volume --- PV Name /dev/sda2 VG Name PV Size 1.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID mR4n4V-0RBN-eFfo-Yi1r-DoYX-pARo-bnXNE2 ``` ### 擴大VG ``` $ vgscan Found volume group "nexus_vg" using metadata type lvm2 Found volume group "rhel" using metadata type lvm2 Found volume group "nexus_vg2" using metadata type lvm2 $ vgdisplay --- Volume group --- VG Name nexus_vg2 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size 596.00 MiB PE Size 4.00 MiB Total PE 149 Alloc PE / Size 147 / 588.00 MiB Free PE / Size 2 / 8.00 MiB VG UUID clHJKm-6PVy-Y7Cf-9c5Y-ymkA-iZMb-WR6fAz $ vgextend nexus_vg2 /dev/sda2 Volume group "nexus_vg2" successfully extended -------------- 查詢Free PE / (Size) -------------- $ vgdisplay --- Volume group --- VG Name nexus_vg2 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size <1.58 GiB PE Size 4.00 MiB Total PE 404 Alloc PE / Size 147 / 588.00 MiB Free PE / Size 257 / 1.00 GiB VG UUID clHJKm-6PVy-Y7Cf-9c5Y-ymkA-iZMb-WR6fAz ``` ### 擴大LV ``` -------------- 查詢LV Path -------------- $ lvdisplay --- Logical volume --- LV Path /dev/nexus_vg2/nexus_lg2 LV Name nexus_lg2 VG Name nexus_vg2 LV UUID DvX8aJ-JV8c-CIpX-djb5-8c69-IX8r-UR6bpx LV Write Access read/write LV Creation host, time localhost.localdomain, 2021-08-22 22:18:46 -0400 LV Status available # open 1 LV Size 588.00 MiB Current LE 147 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 -------------- lvextend -L +< 輸入 Free PE / (Size) - 10Mi > < 輸入 LV Path > -------------- $ lvextend -L +980Mi /dev/nexus_vg2/nexus_lg2 Size of logical volume nexus_vg2/nexus_lg2 changed from 588.00 MiB (147 extents) to 1.53 GiB (392 extents). Logical volume nexus_vg2/nexus_lg2 successfully resized. $ lvdisplay --- Logical volume --- LV Path /dev/nexus_vg2/nexus_lg2 LV Name nexus_lg2 VG Name nexus_vg2 LV UUID DvX8aJ-JV8c-CIpX-djb5-8c69-IX8r-UR6bpx LV Write Access read/write LV Creation host, time localhost.localdomain, 2021-08-22 22:18:46 -0400 LV Status available # open 1 LV Size 1.53 GiB Current LE 392 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 ``` ### 放大 File System ``` $ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.8M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/rhel-root 45G 3.5G 41G 8% / /dev/mapper/nexus_vg-nexus_lg 70G 532M 70G 1% /opt/sonatype tmpfs 374M 0 374M 0% /run/user/0 /dev/mapper/nexus_vg2-nexus_lg2 583M 34M 549M 6% /opt/sonatype2 -------------- ex2 為 resize2fs xfs_growfs < LV Path > -------------- $ xfs_growfs /dev/nexus_vg2/nexus_lg2 meta-data=/dev/mapper/nexus_vg2-nexus_lg2 isize=512 agcount=4, agsize=37632 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=150528, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=1368, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 150528 to 401408 $ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.8M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/rhel-root 45G 3.5G 41G 8% / /dev/mapper/nexus_vg-nexus_lg 70G 532M 70G 1% /opt/sonatype tmpfs 374M 0 374M 0% /run/user/0 /dev/mapper/nexus_vg2-nexus_lg2 1.6G 41M 1.5G 3% /opt/sonatype2 ``` # 參考資料 * ### [ PVcreate ERROR ](https://www.thegeekdiary.com/lvm-error-cant-open-devsdx-exclusively-mounted-filesystem/) * ### [ LVM ](https://hackmd.io/@cjXUmde9TDaRmm57zopgAw/B1FBYKvgF) * ### [LVM 基礎觀念](https://kknews.cc/zh-tw/news/k6l5vbq.html) * ### [Run as Service](https://help.sonatype.com/repomanager3/installation/run-as-a-service#RunasaService-systemd) * ### [創建 User](https://hackmd.io/WUDF20ARS82XpROK9i3OHg?view) * ### [File Descriptor](https://blog.csdn.net/createfly111/article/details/102821194)