日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

笔记:在CentOS上开始你的工作

發布時間:2024/3/12 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 笔记:在CentOS上开始你的工作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基本設置

聯網

CentOS安裝后默認是不聯網的,網卡處于down的狀態,可以通過下面的步驟啟動網卡。

# cd /etc/sysconfig/network-scripts # ls ifcfg-* | grep -v ifcfg-lo ifcfg-eno1 # ifup eno1

現在我們可以用過ip addr命令來驗證網卡的啟動情況了。

然而,這個設置只是臨時的,如果需要讓CentOS每次啟動時都會為我們自動啟動這塊網卡。我們可以修改/etc/sysconfig/network-scripts/ifcfg-eno1配置文件,將其中的ONBOOT=no改為ONBOOT=yes來實現網卡的自動啟動。

設置主機名

我們可以通過下面的命令完成對主機名的設置:

sudo hostname cheshi-desktop1.nay.redhat.com sudo sh -c "echo cheshi-desktop1.nay.redhat.com > /etc/hostname"

重新打開終端窗口后就可以看到變化。

設置時區

我們可以使用下面的命令將系統時區設置為中國:

# ls -la /etc/localtime lrwxrwxrwx. 1 root root 38 Jan 29 20:40 /etc/localtime -> ../usr/share/zoneinfo/America/New_York # rm -f /etc/localtime # ln -s ../usr/share/zoneinfo/Asia/Shanghai /etc/localtime # ls -la /etc/localtime lrwxrwxrwx. 1 root root 35 Jan 31 15:27 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

重啟系統后新的時區設置就會生效。

創建用戶

創建賬戶

添加一個名為cheshi的用戶,并為其設置密碼:

# useradd cheshi # passwd cheshi

刪除賬戶

此外,刪除一個名為cheshi的用戶,方法如下:

# userdel cheshi

userdel命令的-r參數用于同時刪除用戶的家目錄,-f參數用于強制刪除一個正在登錄的用戶。

設置為sudoer

使用visudoer命令,打開/etc/sudoers配置文件,找到名為root的用戶,并在其下方添加新用戶,保存后這個用戶就具有了sudo權限。

更改后的配置文件大約會是這個樣子:

## Allow root to run any commands anywhere root ALL=(ALL) ALL cheshi ALL=(ALL) ALL

配置VNC

安裝GUI界面

首先我們需要安裝桌面環境,也就是GUI界面,它是VNC的基礎,而默認最小安裝的CentOS是不帶GUI界面的。

但我們可以通過下面的命令來安裝GNOME桌面環境:

# yum groupinstall "GNOME Desktop" "Graphical Administration Tools"

安裝大概需要下載600MB左右的文件。

參考文獻:http://www.linuxidc.com/Linux/2017-03/141465.htm

安裝VNC Server

通過下面的命令安裝VNC Server:

$ sudo yum install tigervnc-server

配置VNC

配置VNC有兩種方法,一種是通過vncserver命令直接啟動,這個方法簡單直接,另一種是通過systemctl來啟動VNC服務,這個方法可以自動啟動VNC。

實測第二種方法啟動后的界面有些問題,無法正常使用,因此這里只介紹第一種方法。
有關這個問題的bug可以參見:https://github.com/TigerVNC/tigervnc/issues/577

首先使用vncpasswd命令設置VNC密碼,然后使用vncserver命令創建VNC桌面。一個VNC桌面對應一個VNC Server進程,也對應一個端口號。使用的時候通過在客戶端指定不同的端口號,連接不同的VNC桌面。

$ vncpasswd Password: Verify: Would you like to enter a view-only password (y/n)? y Password: Verify:$ vncserverNew 'dhcp-15-173.nay.redhat.com:1 (cheshi)' desktop is dhcp-15-173.nay.redhat.com:1Starting applications specified in /home/cheshi/.vnc/xstartup Log file is /home/cheshi/.vnc/dhcp-15-173.nay.redhat.com:1.log

首次運行vncserver命令,將會產生一個端口號為1的桌面(這個端口號是VNC虛擬的端口號,一般來說與真實的物理端口號相差5900,后面還會說到)。

設置防火墻

由于使用第一種方法,所以VNC Server并沒有對應的服務用于添加到防火墻的白名單里。所以我們可以找到VNC Server對應的端口,然后將其添加到防火墻的白名單,以達到相同的目的。

通過netstat -anotl命令或nmap命令(可通過sudo yum install nmap命令安裝),可以得到VNC桌面的對應端口號:

$ nmap localhostStarting Nmap 6.40 ( http://nmap.org ) at 2018-01-29 22:23 EST Nmap scan report for localhost (127.0.0.1) Host is up (0.00063s latency). Other addresses for localhost (not scanned): 127.0.0.1 Not shown: 994 closed ports PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp 111/tcp open rpcbind 631/tcp open ipp 5901/tcp open vnc-1 6001/tcp open X11:1Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

接下來我們把對應的端口號5901/tcp加入到防火墻的白名單中:

$ sudo firewall-cmd --get-zones block dmz drop external home internal public trusted work $ sudo firewall-cmd --get-default-zone public $ sudo firewall-cmd --add-port=5901/tcp success

連接VNC

通過另外一臺計算機上的VNC Viewer或者Remmina一類的軟件,連接我們前面配置好的VNC Server即可。

連接時直接指定VNC Server上的虛擬端口號即可,例如:vncviewer 10.0.0.1:1

重新配置VNC桌面

驗證過VNC一切正常后,下面就可以精心設置自己的VNC桌面了。為了避免資源浪費,我們首先需要剛才建立的VNC桌面:

$ vncserver -kill :1 Killing Xvnc process ID 3064

然后我們更改一下VNC桌面的配置。經過剛才的步驟,VNC應該已經為我們自動創建好了配置文件,它的位置應該是~/.vnc/config。我們需要向其中寫入默認的桌面大小,將geometry=1920x1080加入到配置文件中,這樣當我們沒有通過vncserver命令指定桌面大小時,VNC就會使用這個默認值。

可選的配置還有很多,這里就不再贅述。接下來,我們重新啟動剛才的桌面,這次我們可以通過指定端口號的方式,啟動一個VNC桌面:

$ vncserver :1New 'dhcp-15-173.nay.redhat.com:1 (cheshi)' desktop is dhcp-15-173.nay.redhat.com:1Starting applications specified in /home/cheshi/.vnc/xstartup Log file is /home/cheshi/.vnc/dhcp-15-173.nay.redhat.com:1.log

再次登錄這個桌面,應該就會看到效果。

高級設置

使用ZSH

安裝ZSH

ZSH就是”Z Shell”,最小化安裝的CentOS并不帶有這個shell,這一點可以通過zsh --version來驗證。它的安裝方法也很簡單:

$ sudo yum install zsh

參考文獻: https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH

配置ZSH

第一次運行時,ZSH會提示我們進行配置,所有的配置信息都會被保存到~/.zshrc中,但是由于一會兒我們要使用”Oh My Zsh”的模板覆蓋這個配置文件,因此這里我們選擇”0”以跳過設置。

$ zshThis is the Z Shell configuration function for new users, zsh-newuser-install. You are seeing this message because you have no zsh startup files (the files .zshenv, .zprofile, .zshrc, .zlogin in the directory ~). This function can help you with a few settings that should make your use of the shell easier.You can:(q) Quit and do nothing. The function will be run again next time.(0) Exit, creating the file ~/.zshrc containing just a comment.That will prevent this function being run again.(1) Continue to the main menu.--- Type one of the keys in parentheses ---

如果想要設置ZSH為當前用戶默認的Shell,可以執行chsh -s $(which zsh)這條命令。

使用”Oh My Zsh”

“Oh My Zsh”是一個開源項目,它提供了很多ZSH的主題,使得ZSH更加強大并易于使用。它的全部代碼和文檔都可以在GitHub上找到。

安裝”Oh My Zsh”最便捷的方式是執行官方提供的install.sh,不過在此之前我們需要執行sudo yum install -y git,來安裝腳本所需的git命令。

接下來,我們就可以開始安裝”Oh My Zsh”了:

$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" Cloning Oh My Zsh... Cloning into '/home/cheshi/.oh-my-zsh'... remote: Counting objects: 849, done. remote: Compressing objects: 100% (713/713), done. remote: Total 849 (delta 16), reused 769 (delta 10), pack-reused 0 Receiving objects: 100% (849/849), 578.52 KiB | 181.00 KiB/s, done. Resolving deltas: 100% (16/16), done. Looking for an existing zsh config... Found ~/.zshrc. Backing up to ~/.zshrc.pre-oh-my-zsh Using the Oh My Zsh template file and adding it to ~/.zshrc Time to change your default shell to zsh! Changing shell for cheshi. Password: Shell changed.__ __ ____ / /_ ____ ___ __ __ ____ _____/ /_ / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ / /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / \____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ /____/ ....is now installed!Please look over the ~/.zshrc file to select plugins, themes, and options.p.s. Follow us at https://twitter.com/ohmyzsh.p.p.s. Get stickers and t-shirts at https://shop.planetargon.com.→ ~

執行下面的命令以更改主題為”agnoster”,這是一款很酷的主題:

$ sed -i 's/^ZSH_THEME=.*/ZSH_THEME="agnoster"/' ~/.zshrc

當你下次進入ZSH的時候,可能會發現它變得一團糟,這是因為你還沒有安裝主題所需的字體,以及更改終端顏色。

為了配合ZSH的大部分主題,我們需要安裝Power Line字體。安裝的命令如下:

git clone https://github.com/powerline/fonts.git --depth=1 cd fonts && ./install.sh cd .. && rm -rf fonts

接下來,我們要設置終端的顏色,步驟略微有點復雜:
1. 點擊終端窗口菜單欄上的”Edit” > “Preferences”
2. 翻到”Profiles”選項卡,并點擊”Clone”按鈕
3. 在”General”選項中更改”Profile name”為自己喜歡的名字,例如”Profile for Zsh”
4. 勾選”Custom font”并將字體設置為”Monospace Regular - 11pt”(或者是”Noto Mono for Powerline Regular - 12pt”以及其他你喜歡的字體,只要顯示沒有亂碼即可)
5. 翻到”Colors”選項卡,取消勾選”Use colors from system theme”,并更改”Built-in schemes”為”Solarized dark”
8. 在下面設置”Palette”的地方,更改”Built-in schemes”為”Solarized”
9. 點擊最下面的”Close”按鈕完成設置
10. 回到之前的窗口,將”Profile used when launching a new terminal”選為剛剛創建的Profile
11. 點擊最下面的”Close”按鈕完成設置

現在,重新打開新的終端,就可以看到效果了。

提示:重啟系統或VNC桌面后,ZSH將變為當前用戶的默認Shell。

“Oh My Zsh”官方文檔:https://github.com/robbyrussell/oh-my-zsh/blob/master/README.md

使用EPEL

首先找到最新的EPEL安裝包,CentOS7對應的安裝包位于http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/下,我們可以通過下面的命令進行安裝:

$ wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm $ sudo rpm -ivh epel-release-7-11.noarch.rpm $ sudo yum-config-manager epel

常用工具

JSON分析工具 - jq

sudo yum install -y jq

總結

以上是生活随笔為你收集整理的笔记:在CentOS上开始你的工作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。