Linux系統安裝及設置

1、開啓root賬號
sudo passwd root #啓用root賬號並設置密碼,根據提示輸入2次密碼
su root #從普通用戶切換到root用戶,根據提示輸入root密碼
sudo passwd -l root #禁用root賬號,如果要啓用,輸入sudo passwd root再次設置root密碼

2、永久設置靜態IP
cd /etc/sysconfig/network-scripts

vi ifcfg-網卡名
ONBOOT=yes
BOOTTPROTO=static 
IPADDR=192.168.9.10
NETMASK=255.0.0.0
GATEWAY=192.168.9.2

3、重啓網卡
service network restart
重新加載eth3網卡
ifconfig eth3 up

4、更新系統方法
yum -y update

5、查看防火牆狀態
firewall-cmd --state

6、停止firewall
systemctl stop firewalld.service

7、禁止firewall開機啓動
systemctl disable firewalld.service 

8、重啓
reboot
shutdown -r now(root用戶使用)

9、關機
halt 
poweroff 
shutdown -h now(root用戶使用)


10、設置開啓關閉圖形化界面
cat /etc/inittab       (顯示的內容中有設置命令提示)
multi-user.target 無圖形的
graphical.target 有圖形化的

11、添加自啓動方法
systemctl list-units --all --type=service #查看所有服務
systemctl list-units --type=service #查看所有已經啓動的服務

systemctl enable crond ##設置開機啓動crond服務或工具
systemctl disable crond ##設置關閉開機啓動crond服務或工具
systemctl status crond ##查看crond服務當前狀態,如是否運行
systemctl stop crond ##停止crond服務是,但開機仍會運行
systemctl start crond ##開啓crond服務
systemctl restart crond ##重啓crond服務
systemctl is-enabled crond ##檢查crond服務是否開機啓動

添加自啓服務,以ngix爲例
cd /lib/systemd/system
touch nginx.service
vim nginx.service #在系統服務目錄裏創建nginx.service文件

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

說明:
[Unit]:服務的說明
Description:描述服務
After:描述服務類別
[Service]服務運行參數的設置
Type=forking是後臺運行的形式
ExecStart爲服務的具體運行命令
ExecReload爲重啓命令
ExecStop爲停止命令
PrivateTmp=True表示給服務分配獨立的臨時空間
注意:[Service]的啓動、重啓、停止命令全部要求使用絕對路徑
[Install]運行級別下服務安裝的相關設置,可設置爲多用戶,即系統運行級別爲3
保存退出。

systemctl enable nginx.service #設置開機啓動
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章