最小安裝: 1. 選擇English 2. DATE & TIME 修改好本地時間 SOFTWARE SELECTION默認的Minimal Install就好 INSTALLATION DESTINATION選一下 而後,Begin Installation 3. ROOT PASSWORD設置ROOT密碼 USER CREATION設置新用戶,勾選Make this user administrator 等待安裝完成,點Reboot按鈕。 配置靜態IPv4: $ systemctl status NetworkManager.service 檢查網絡管理器服務狀態 注1:建議使用nmtui的終端用戶界面代替下面到92行左右的網絡配置內容。 注2:Ubuntu 18.04 Server 使用了netplan進行網絡管理,包括nameservers配置,請搜索下面的「netplan配置」。 $ nmcli dev status DEVICE TYPE STATE CONNECTION ens33 ethernet disconnected -- lo loopback unmanaged -- 這裏須要配置ens33 $ su # cd /etc/sysconfig/network-scripts # ls ifcfg* # vi ifcfg-ens33 配置的ens33 將 BOOTPROTO=dhcp 改成 BOOTPROTO=static 而後在下行添加: IPADDR=192.168.48.10 NETMASK=225.225.225.0 NM_CONTROLLED=no (NM_CONTROLLED=no表示該接口經過該配置文件設置,而不是經過網絡管理器) 將 ONBOOT=no 改成 ONBOOT=yes (若是虛擬機NAT訪問,加入網關設置 GATEWAY=192.168.48.2 NETWORK=192.168.48.0 其餘配置: DHCP_HOSTNAME=192.168.48.254 BROADCAST=192.168.48.255 HWADDR=00:0C:29:56:BF:F7 ) 保存退出vi 注:若是使用dhcp動態IP 只要將 ONBOOT=no 改成 ONBOOT=yes 便可。 # systemctl restart network.service # ip add 查看ip信息 [ freeBSD # ifconfig // 查看可用的網卡名稱,例子裏看到了hn0 是以太網 # vi /etc/rc.conf // 編輯配置文件,配置靜態IP、路由IP並啓用ssh hostname="freebsd" #ifconfig_DEFAULT="DHCP inet6 accept_rtadv" ifconfig_hn0="inet 192.168.0.60 netmask 255.255.255.0" defaultrouter="192.168.0.1" sshd_enable="YES" # vi /etc/resolv.conf // 配置DNS nameserver 8.8.8.8 nameserver 8.8.4.4 # /etc/rc.d/netif restart // 重啓網絡 # adduser // 添加一個用戶,用於ssh鏈接 ] DNS配置 NMCLI方法: # nmcli connection show # nmcli con mod ens33 ipv4.dns "8.8.8.8 8.8.4.4" # nmcli con up ens33 # ping www.baidu.com -c 4 手動修改方法: # vim /etc/resolv.conf nameserver 8.8.8.8 nameserver 8.8.4.4 # vim /etc/NetworkManager/NetworkManager.conf 在[main]下加入: dns=none # systemctl restart NetworkManager # ping www.baidu.com -c 4 Debian配置網絡 # vi /etc/network/interfaces DHCP配置: auto eth0 allow-hotplug eth0 iface eth0 inet dhcp (IPv6追加:) iface eth0 inet6 dhcp (或者) iface eth0 inet6 auto 靜態IP配置: auto eth0 iface eth0 inet static address 192.0.2.7 netmask 255.255.255.0 gateway 192.0.2.254 (IPv6追加:) iface eth0 inet6 static address 2001:db8::c0ca:1eaf netmask 64 gateway 2001:db8::1ead:ed:beef 幫助:man interfaces # systemctl restart networking ------------------------------------------ netplan配置(Ubuntu 18.04 Server) $ netplan --help $ sudo vi /etc/netplan/50-cloud-init.yaml (yaml文件名不固定,內容以下) # This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: ethernets: eth0: addresses: - 192.168.0.50/24 gateway4: 192.168.0.1 nameservers: addresses: [8.8.8.8,8.8.4.4] search: [] optional: true version: 2 應用設置: $ sudo netplan apply 其餘見:https://netplan.io/examples ------------------------------------------ 配置光盤爲安裝源(注:後面有配置iso爲安裝源的,這裏僅光盤鏡像臨時做爲安裝源使用): $ sudo ssh 192.168.48.10 -l root # cat /etc/yum.repos.d/CentOS-Media.repo 基本內容以下: [c7-media] name=CentOS-$releasever - Media baseurl=file:///media/CentOS/ file:///media/cdrom/ file:///media/cdrecorder/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 文件頭的註釋部分提示能夠用命令 yum --enablerepo=c7-media [command] 或者 yum --disablerepo=\* --enablerepo=c7-media [command] 安裝軟件。 # ls /dev/cdrom # mkdir /media/cdrom # mount /dev/cdrom /media/cdrom 掛載cdrom [freeBSD 先載入光盤 或者掛載到/dist目錄: # mkdir -p /dist # mount -t iso9660 /dev/cd0 /dist 用bsdconfig命令 # bsdconfig 選擇 3.Packages 選擇 1.CD/DVD 選擇 FREEBSD_INSTALL ISO9660 file system 在其中選擇要安裝的軟件 ] 安裝vim、gcc、g++: # yum --disablerepo=\* --enablerepo=c7-media install vim -y # yum --disablerepo=\* --enablerepo=c7-media install gcc gcc-c++ -y ---------------- 安裝mysql 5.6: ---------------- 先將client和server兩個rpm安裝包複製到本機下載目錄,而後在mac終端輸入: $ sudo scp ~/Downloads/MySQL-*.rpm bob@192.168.48.10:/home/bob/ 複製client和server安裝文件到/home/bob/目錄下(注:也能夠複製到其餘目錄,好比root@192.168.48.10:/usr/local/) 回到ssh: # rpm -qa|grep -i mariadb 查詢mariadb,與mysql衝突,下面將查到的庫一併強制刪除(最小安裝只有mariadb-libs) # rpm -e --nodeps mariadb-libs # groupadd -r mysql # useradd -g mysql mysql -d /home/mysql -s /sbin/nologin (注:mysql 5.7論壇版安裝順序是:common、libs、client、server) (注2:mariadb 10.2須要一些依賴:yum --disablerepo=\* --enablerepo=c7-media install lsof perl rsync boost perl-DBI -y 而後安裝順序是:galera、MariaDB-10.2.10-centos73-x86_64-*(放在同一目錄下:compat、common、client、server) ) # yum --disablerepo=\* --enablerepo=c7-media install perl -y # rpm -ivh ./MySQL-client-5.6.34-1.el7.x86_64.rpm # yum --disablerepo=\* --enablerepo=c7-media install autoconf -y # rpm -ivh ./MySQL-server-5.6.34-1.el7.x86_64.rpm # rm -f MySQL-*.rpm # systemctl start mysql.service (注:mysql 5.7的啓動服務是mysqld.service) (注2:mariadb 10.2啓動服務是mysqld.service,mariadb也能夠) # cat /root/.mysql_secret The random password set for the root user at Tue Feb 21 13:55:26 2017 (local time): vZQwDJLbxm_zHno_ (注:mysql 5.7的初始密碼在log文件裏 $ grep "temporary password" /var/log/mysqld.log 而後在調用mysql_secure_installation前,手動修改安全策略: $ mysql -uroot -p mysql> set global validate_password_policy=0; mysql> set global validate_password_length=0; mysql> exit 或者編輯 /etc/my.cnf [mysqld] validate_password=off ) (注2:mariadb 10.2沒有初始密碼,能夠經過下面命令將密碼設置爲123456 /usr/bin/mysqladmin -u root password '123456' ) # /usr/bin/mysql_secure_installation 把隨機密碼粘貼到提示符,根據提示,改變root密碼,移除匿名帳戶,禁用root遠程登陸,移除測試數據庫,刷新權限。 (注:mysql 5.7在設置了前面的密碼策略後,可能要屢次輸入簡單的密碼來確認) # mysql -uroot -p 建立新用戶: mysql> create user 'bob'@'%' identified by '123456'; (若是用root帳戶遠程鏈接:mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';) mysql> flush privileges; mysql> exit # firewall-cmd --zone=public --add-port=3306/tcp --permanent # firewall-cmd --reload ------ mysql emoji ------ 注意:utf8mb4的最低mysql版本支持版本爲5.5.3+ 注意2:utf8mb4做爲索引列須要注意,在MySQL 5.7.7和MariaDB 10.2.2中支持3072個字節最大索引,而MySQL5.6僅支持767個字節, 因此在mysql5.6時,utf8mb4列的長度不要超過191(191*4<767),utf8能夠是255(255*3<767)。如要使用超過767個字節(升級到3072個),須要設置 SET GLOBAL innodb_file_per_table = ON, innodb_file_format = Barracuda, innodb_large_prefix = ON; 而且在創建表(包括ALTER)的時候,加上 ROW_FORMAT=DYNAMIC 或者 ROW_FORMAT=COMPRESSED CREATE TABLE _tablename_( `id` INT NOT NULL AUTO_INCREMENT, `hashtag` VARCHAR(255) NOT NULL COMMENT 'hashtag must be unique. Must be saved without #', PRIMARY KEY (`id`), UNIQUE INDEX `hashtags_hashtag` (`hashtag` ASC)) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8mb4 ROW_FORMAT = COMPRESSED; ALTER就是: ALTER TABLE _tablename_ ROW_FORMAT=DYNAMIC; (mysql 5.7.9是默認innodb_default_row_format=DYNAMIC,innodb_file_per_table = ON,innodb_file_format = Barracuda,innodb_large_prefix = ON) --- 若是建立數據庫、表、列時指定utf8mb4和utf8mb4_general_ci,下面應該能夠不用設置。 1) 設置my.cnf $ sudo vim /etc/my.cnf(ubuntu的位置 /etc/mysql/my.cnf) [client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4 [mysqld] default_authentication_plugin=mysql_native_password // mysql 8 默認 caching_sha2_password,這裏更改成原始的 character-set-client-handshake=FALSE character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4' skip-name-resolve 保存後重啓mysql $ systemctl restart mysql $ mysql -uroot -p mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8mb4 | | character_set_connection | utf8mb4 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | utf8mb4 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | | collation_connection | utf8mb4_general_ci | | collation_database | utf8mb4_unicode_ci | | collation_server | utf8mb4_unicode_ci | +--------------------------+----------------------------+ 11 rows in set 注:collation_connection、collation_database、collation_server是utf8mb4_general_ci沒有關係。 2) 修改Database、Table、Column字符集: ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE table_name CHANGE column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 修復優化表 REPAIR TABLE table_name; OPTIMIZE TABLE table_name; 也能夠用mysqlcheck命令優化全部數據庫 $ mysqlcheck -uroot -p --auto-repair --optimize --all-databases 3) 對於Java來講mysql connector版本需高於5.1.13。 ------------ 安裝gogs: ------------ 先將linux_amd64.zip包複製到本機下載目錄,而後在mac終端輸入: $ sudo scp ~/Downloads/linux_amd64.tar.gz root@192.168.48.10:/root/ 複製linux_amd64.tar.gz文件到/root/目錄下(注:也能夠複製到其餘目錄,好比root@192.168.48.10:/usr/local/) 回到ssh: # groupadd -r git # useradd -g git git -d /home/git # mv /root/linux_amd64.tar.gz /home/git/ # chown git:git /home/git/linux_amd64.tar.gz (若是是zip文件:yum --disablerepo=\* --enablerepo=c7-media install unzip -y) # su git $ cd ~ $ tar xvfz linux_amd64.tar.gz (若是是zip文件:unzip linux_amd64.zip) $ ls gogs linux_amd64.tar.gz $ rm -f linux_amd64.tar.gz $ cd gogs $ chmod +x ./gogs $ cat ./scripts/mysql.sql DROP DATABASE IF EXISTS gogs; CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; $ mysql -uroot -p < scripts/mysql.sql $ mysql -uroot -p mysql> grant all privileges on gogs.* to 'bob'@'%' identified by '123456'; mysql> flush privileges; mysql> exit $ exit # cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/ # cat /etc/systemd/system/gogs.service [Unit] Description=Gogs After=syslog.target After=network.target After=mariadb.service mysqld.service postgresql.service memcached.service redis.service [Service] # Modify these two values and uncomment them if you have # repos with lots of files and get an HTTP error 500 because # of that ### #LimitMEMLOCK=infinity #LimitNOFILE=65535 Type=simple User=git Group=git WorkingDirectory=/home/git/gogs ExecStart=/home/git/gogs/gogs web Restart=always Environment=USER=git HOME=/home/git [Install] WantedBy=multi-user.target 啓動服務,配置防火牆 # systemctl start gogs.service # systemctl enable gogs.service # firewall-cmd --zone=public --add-port=3000/tcp --permanent # firewall-cmd --reload (ubuntu系統配置防火牆命令: sudo ufw allow 3000 sudo ufw enable) (iptables: // 添加 iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT // 保存 service iptables save cat /etc/sysconfig/iptables // 重啓iptables service iptables restart iptables -nvL --line-number // 刪除 iptables -D INPUT 2 <--- line number // 修改 iptables -R INPUT 3 -j ACCEPT ) 而後在瀏覽器打開 http://192.168.48.10:3000 (注2:mariadb配置好後,主機也許不能用127.0.0.1鏈接,請用主機ip:192.168.48.10) 注:若是開啓了selinux,可能須要關閉。 # setenforce 0 # vim /etc/sysconfig/selinux 將SELINUX=enforce改成disabled 配置文件爲了保證重啓後生效。 沒法使用ssh進行clone和push數據 若是http方式沒問題,就是應爲gogs的帳戶(這裏是git帳戶)沒有指定shell, 解決辦法是: # cat /etc/shells /bin/sh /bin/bash ... # usermod -s /bin/bash git 升級gogs $ sudo service gogs stop $ sudo su - git $ cd ~ $ pwd /home/git $ ls gogs gogs-repositories $ mv gogs gogs_old $ wget https://dl.gogs.io/gogs_v$VERSION_$OS_$ARCH.tar.gz $ tar -zxvf gogs_v$VERSION_$OS_$ARCH.tar.gz $ ls gogs gogs_old gogs-repositories gogs_v$VERSION_$OS_$ARCH.tar.gz $ cp -R gogs_old/custom gogs $ cp -R gogs_old/data gogs $ cp -R gogs_old/log gogs $ sudo service gogs start 若是啓動失敗,多是權限的問題: # chmod +x /home/git/gogs/gogs # chown -R git:git /home/git/gogs # service gogs start --------- docker-ce --------- 方式一:在線安裝 https://docs.docker.com/engine/installation/linux/docker-ce/centos/#os-requirements 1. 卸載 # sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine 2. 安裝yum配置管理器 # yum install -y yum-utils device-mapper-persistent-data lvm2 3. 加入docker-ce repo # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 或者 wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo (若是採用清華大學鏡像,接着執行: # sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo ) (可選)而後能夠經過命令切換edge或者test # yum-config-manager --enable docker-ce-edge # yum-config-manager --enable docker-ce-test 禁用則返回標準 # yum-config-manager --disable docker-ce-edge 4. 安裝docker-ce # yum makecache fast (可選) # sudo yum install docker-ce (查看安裝docker的其餘版本版本 $ yum list docker-ce --showduplicates | sort -r # yum install <FULLY-QUALIFIED-PACKAGE-NAME>) 5. 啓動docker # systemctl start docker # systemctl enable docker 6. 測試 # docker run hello-world 方式二:rpm包 rpm方式的話,須要下載安裝的文件: 安裝依賴 # yum --disablerepo=\* --enablerepo=c7-media install libcgroup policycoreutils-python -y container-selinux http://mirror.centos.org/centos/7.4.1708/extras/x86_64/Packages/container-selinux-2.28-1.git85ce147.el7.noarch.rpm # rpm -ivh /root/container-selinux-2.28-1.git85ce147.el7.noarch.rpm 安裝docker-ce https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm rpm -ivh /root/docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm (debian: https://docs.docker.com/engine/installation/linux/docker-ce/debian/#install-docker-ce-1 若是不能用sudo apt-get install docker-ce直接安裝: $ sudo apt-get remove docker docker-engine docker.io $ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg2 \ software-properties-common (Wheezy及以前的版本用 $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ python-software-properties ) $ curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add - 如:curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - 官方倉庫: $ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \ $(lsb_release -cs) \ stable" 清華大學鏡像倉庫: $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/$(. /etc/os-release; echo "$ID") \ $(lsb_release -cs) \ stable" 注:add-apt-repository --remove <http或者ppa:....> 能夠刪除一個倉庫 清華大學鏡像倉庫的詳細使用方法:https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/ $ sudo apt-get update $ sudo apt-get install docker-ce ) (( manjaro $ sudo pacman -S docker docker-compose )) 將當前用戶添加到docker組 $ sudo usermod -aG docker $USER 從新登陸shell 啓動docker $ sudo systemctl start docker $ sudo systemctl enable docker 或者( $ sudo update-rc.d docker enable $ sudo service docker start ) $ docker version Client: Version: 17.09.0-ce API version: 1.32 Go version: go1.8.3 Git commit: afdb6d4 Built: Tue Sep 26 22:41:23 2017 OS/Arch: linux/amd64 Server: Version: 17.09.0-ce API version: 1.32 (minimum version 1.12) Go version: go1.8.3 Git commit: afdb6d4 Built: Tue Sep 26 22:42:49 2017 OS/Arch: linux/amd64 Experimental: false 卸載docker # yum remove docker-ce 刪除鏡像、容器、卷和自定義配置 # rm -rf /var/lib/docker 添加私有源 # vim /etc/docker/daemon.json { "insecure-registries": ["192.168.48.10:5000"] } 也能夠加入鏡像 "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/", "https://hub-mirror.c.163.com"] # systemctl daemon-reload && systemctl restart docker 查看insecure-registries和registry-mirrors # docker info 安裝docker-compose 方法一:安裝源(推薦) $ sudo yum makecache fast $ sudo yum install docker-compose (debian/ubuntu: $ sudo apt-get update $ sudo apt-get install docker-compose $ docker-compose --version 若是發生錯誤 $ pip install --upgrade docker-py 若是沒有安裝pip $ sudo apt-get install python-pip $ mkdir -p ~/.config/pip $ vim ~/.config/pip/pip.conf [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple 而後再執行 pip install --upgrade docker-py ) 方法二:經過github 注意版本號經過https://github.com/docker/compose/releases查看最新版,而後替換1.19.0 $ sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose $ sudo chmod +x /usr/local/bin/docker-compose $ docker-compose --version (卸載:sudo rm /usr/local/bin/docker-compose) ----------------------------------------------------------------------------- 啓動到命令行界面 graphical.target to multi-user.target $ systemctl get-default graphical.target $ sudo systemctl set-default multi-user.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target. $ sudo reboot // boot to graphical desktop $ startx 更改全部權 chown -R youruser:youruser /home/youruser/* 更換shell # cat /etc/shells # echo $SHELL # usermod -s /sbin/nologin youruser # usermod -s /sbin/bash youruser 設置iso做爲安裝源 查看網址 # ip add 遠程拷貝 $ scp ~/Desktop/CentOS-7-x86_64-Everything-1611.iso root@192.168.48.10:/usr/local/ 遠程登陸 $ ssh 192.168.48.10 -l root 移動文件到/usr/local/iso # mkdir /usr/local/iso # mv /usr/local/CentOS-7-x86_64-Everything-1611.iso /usr/local/iso/ 修改fstab,掛着iso到/mnt/centiso # vi /etc/fstab 追加: /usr/local/iso/CentOS-7-x86_64-Everything-1611.iso /mnt/centiso iso9660 defaults,ro,loop 0 0 建立掛載點並掛載: # mkdir /mnt/centiso # mount -a # ls /mnt/centiso CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL 記住這裏面的GPG-KEY的文件,將用在yum配置源上 查看yum源 # ls /etc/yum.repos.d/ CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo 新建一個cdrom.repo # vi cdrom.repo [CDROM] name=centiso baseurl=file:///mnt/centiso enabled=1 gpgcheck=0 gkgkey=file///mnt/centiso/RPM-GPG-KEY-CentOS-7 檢查安裝源 # yum list gcc Loaded plugins: fastestmirror CDROM | 3.6 kB 00:00 base | 3.6 kB 00:00 ... 能夠看見CDROM安裝源 更換鏡像源(https://mirrors.tuna.tsinghua.edu.cn/help/centos/) 以CentOS 7爲例 # mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak # vim /etc/yum.repos.d/CentOS-Base.repo ----------------------------------------------- # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 ----------------------------------------------- # sudo yum makecache (( manjaro 鏡像源 $ sudo pacman-mirrors -i -c China -m rank //更新鏡像排名 而後出現界面勾選某個鏡像源 $ sudo pacman -Syy //更新數據源 $ sudo pacman -S pacman $ sudo pacman -S vim yaourt $ sudo vim /etc/yaourtrc AURURL="https://aur.tuna.tsinghua.edu.cn" $ sudo yaourt -Syy 在包管理器的設置中,將AUR設置爲啓用。 而後能夠安裝Sogou等輸入法。 )) 安裝sudo [ freeBSD pkg install vim sudo ] $ su # vim /etc/sudoers [ freeBSD vim /usr/local/etc/sudoers ] 在 root ALL=(ALL) ALL後面添加相同一行,新行的root改爲當前用戶,而後w!寫入,退出vim # exit $ 就能夠了。 安裝vim # yum install vim 安裝deltarpm # yum provides '*/applydeltarpm' # yum install deltarpm 安裝開發組工具 # yum group list | grep "Development Tools" # yum group install "Development Tools" (debian: apt-get install build-essential) 安裝ack # yum install epel-release # yum install ack 其中epel-release指的是:Extra Packages for Enterprise Linux (EPEL) Fodera直接 # dnf install ack -y Debian $ sudo apt install ack-grep 安裝zsh # cat /etc/shells # yum install zsh [freeBSD #pkg install zsh] # zsh --version # echo $SHELL # chsh -s /bin/zsh (yum install util-linux-user) [freeBSD #chsh -s /usr/local/bin/zsh] 若是提示用戶名不存在,說明用戶不在/etc/passwd中,多是LDAP-base系統,能夠經過下面命令查看用戶信息 $ getent passwd $USER yourusername:*:700607997:700600513:somedomain.com:/home/yourusername:/bin/bash 能夠更改.profile或者.bashrc文件(由於上面寫了/bin/bash) if [ "$SHELL" != "/bin/zsh" ] then export SHELL="/bin/zsh" exec /bin/zsh -l # -l: login shell again fi # zsh 選擇2,生成默認配置文件~/.zshrc 若是改變失敗,能夠用usermod命令: $ sudo usermod -s /bin/zsh $USER ( 建立組和用戶 # groupadd -r bob # useradd -g bob bob -d /home/bob -s /bin/bash # passwd bob # mkdir /home/bob # chown -R bob:bob /home/bob # vi /etc/sudoer ... ) 安裝antigen(https://github.com/zsh-users/antigen) $ cd ~ [freeBSD #pkg install curl git] $ curl -L git.io/antigen > antigen.zsh $ vim ~/.antigenrc source $HOME/antigen.zsh antigen use oh-my-zsh antigen bundles <<EOBUNDLES git #gitfast #git-extras heroku sudo z history cp rsync #encode64 #osx #brew #brew-cask #command-not-found zsh-users/zsh-syntax-highlighting zsh-users/zsh-autosuggestions zsh-users/zsh-completions EOBUNDLES antigen theme clean #antigen theme ys antigen apply $ echo source \$HOME/.antigenrc>~/.zshrc ****若是不在zsh $ zsh $ chsh -s /bin/zsh ****若是在zsh $ source ~/.zshrc $ antigen list 若是出現問題能夠reset一下: $ antigen reset 注意:若是啓動zsh時候提示 zsh compinit: insecure directories, run compaudit for list. 輸入 compaudit 查看不安全的目錄,而後用chmod 755(或chown)命令改變這些目錄權限 $ compaudit There are insecure directories: /home/Bob/.antigen/bundles/robbyrussell/oh-my-zsh/lib /home/Bob/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/git ... $ ls -al /home/Bob/.antigen drwxrwxrwx 0 Bob Bob 4096 Dec 8 10:00 . drwxr-xr-x 0 Bob Bob 4096 Dec 8 10:09 .. drwxrwxrwx 0 Bob Bob 4096 Dec 8 09:46 bundles ... 看見.和bundles目錄的權限不是755 $ sudo chmod -R 755 /home/Bob/.antigen $ compaudit | xargs chmod -R 755 安裝oh-my-zsh(若是不喜歡antigen,能夠安裝oh-my-zsh) # sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" 或者 # sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" # vim ~/.zshrc plugins=(git z history sudo) 刪除oh-my-zsh # uninstall_oh_my_zsh # rm ~/.zshrc 安裝fzf(https://github.com/junegunn/fzf) $ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf $ ~/.fzf/install 更新 $ cd ~/.fzf && git pull && ./install 更改時區 # date -R # ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 或者 # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime yum清理命令 # yum autoremove 清除緩存目錄(/var/cache/yum)下的軟件包 # yum clean packages 清除緩存目錄(/var/cache/yum)下的 headers # yum clean headers 清除緩存目錄(/var/cache/yum)下舊的 headers # yum clean oldheaders 清除緩存目錄(/var/cache/yum)下的軟件包及舊的headers 命令:yum clean, yum clean all (= yum clean packages; yum clean oldheaders) 安裝yum管理工具 yum-utils(yum-config-manager,使用方法見docker-ce在線安裝部分) # yum --disablerepo=\* --enablerepo=c7-media install yum-utils -y 查看依賴 # rpm -qpR *.rpm Debian安裝deb文件 $ sudo dpkg -i code_1.19.3-1516876497_i386.deb Debian的apt命令 編輯源、更新源 # apt edit-sources 或者 # vi /etc/apt/sources.list # apt update 查詢、安裝 # apt search vsftpd # apt install git vim 刪除 apt-get remove vsftpd 安裝開發工具包 # apt-get install build-essential (centos: yum group install "Development Tools") dnf命令(替代yum的包管理工具) 查看系統中可用的 DNF 軟件庫 # dnf repolist 查看系統中可用和不可用的全部的 DNF 軟件庫 # dnf repolist all 列出全部 RPM 包 # dnf list 列出全部安裝了的 RPM 包 # dnf list installed 列出全部可供安裝的 RPM 包 # dnf list available 搜索軟件庫中的 RPM 包 # dnf search nano 查找某一文件的提供者 # dnf provides /bin/bash 查看軟件包詳情 # dnf info nano 安裝軟件包 # dnf install nano 升級軟件包 # dnf update systemd 檢查系統軟件包的更新 # dnf check-update 升級全部系統軟件包 # dnf update 或 # dnf upgrade 刪除軟件包 # dnf remove nano 或 # dnf erase nano 刪除無用孤立的軟件包 # dnf autoremove 刪除緩存的無用軟件包 # dnf clean all 獲取有關某條命令的使用幫助 # dnf help clean 查看全部的 DNF 命令及其用途 # dnf help 查看 DNF 命令的執行歷史 # dnf history 查看全部的軟件包組 # dnf grouplist 安裝一個軟件包組 # dnf groupinstall 'Educational Software' 升級一個軟件包組中的軟件包 # dnf groupupdate 'Educational Software' 刪除一個軟件包組 # dnf groupremove 'Educational Software' 從特定的軟件包庫安裝特定的軟件 # dnf –enablerepo=epel install phpmyadmin 更新軟件包到最新的穩定發行版 # dnf distro-sync 從新安裝特定軟件包 # dnf reinstall nano 回滾某個特定軟件的版本 # dnf downgrade acpid 關閉防火牆 # systemctl stop firewalld.service # systemctl disable firewalld.service 關閉selinux # setenforce 0 # vim /etc/sysconfig/selinux 將SELINUX=enforce改成disabled 改密碼: # passwd 查看/var/log/wtmp登陸日誌 # last 查看/var/log/btmp失敗的登陸日誌 # lastb 注:能夠用-f指定查看的文件名:last -f /var/log/btmp 查看最近10條登陸日誌,用dns代替ip地址 # last -10 -d 查找文件 $ sudo find / -name file.txt $ sudo find / -name file.txt 2>/dev/null 查找命令 $ which vi $ whereis vi CPU信息 # cat /proc/cpuinfo 物理CPU個數 # cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l 每一個物理CPU中core的個數 # cat /proc/cpuinfo| grep "cpu cores"| uniq 邏輯CPU的個數 # cat /proc/cpuinfo| grep "processor"| wc -l 總核數 = 物理CPU個數 x 每顆物理CPU的核數 總邏輯CPU數 = 物理CPU個數 x 每顆物理CPU的核數 x 超線程數 磁盤空間 # df -h 文件佔用空間 # du --max-depth=1 -h # du -sh # du -sh /opt/oracle 字體 在/usr/share/fonts/下面建立一個目錄, # mkdir -p /usr/share/fonts/winFonts 而後把字體複製到這個目錄裏, # cp ~/Desktop/font/*.ttf /usr/share/fonts/winFonts/ 設置權限最低444 # chown -R 444 /usr/share/fonts/winFonts/ 而後調用 # mkfontscale (建立新字體的fonts.scale文件,它用來控制字體旋轉縮放) # mkfontdir (建立新字體的fonts.dir文件,它用來控制字體粗斜體產生) # fc-cache -fv (創建字體緩存信息,也就是讓系統認識認識新字體) 刪除多餘內核 centos # uname -a (查看當前內核) # rpm -qa|grep kernel # yum remove kernel-2.6.32-279.9.1.el6.x86_64 debian $ uname -a (查看當前內核) $ dpkg --get-selections | grep linux $ sudo apt-get remove linux-image-2.6.32.21-generic $ sudo update-grub 主機名 $ hostname debian $ cat /etc/hostname debian 詳情 $ hostnamectl Static hostname: debian Icon name: computer-vm Chassis: vm Machine ID: 60ab99cf205c40cd9183a45dcfbd64b2 Boot ID: 5cf792f390204c8c85a06309335210e1 Virtualization: vmware Operating System: Debian GNU/Linux buster/sid Kernel: Linux 4.13.0-1-amd64 Architecture: x86-64 分別查看 $ hostnamectl --static debian $ hostnamectl --transient debian $ hostnamectl --pretty 更名 $ sudo hostnamectl set-hostname debian9 (所有設置) $ sudo hostnamectl --static set-hostname debian9 (單獨設置) 手動更名 $ sudo /etc/hostname debian9 $ sudo /etc/hosts debian9 127.0.0.1 臨時更名 $ hostname tempname 發行版本 $ cat /etc/os-release ------遠程鏈接------ sshd: 先查看運行狀態 # systemctl status sshd.service 若是未發現,須要手動安裝: # yum -qa|grep -i ssh (dnf list installed|grep -i ssh) openssh.x86_64 openssh-clients.x86_64 openssh-server.x86_64 # yum install openssh (ubuntu中已經安裝了openssh-client,所以安裝Server $ sudo apt install openssh-server ) 其配置文件在:/etc/ssh/sshd_config 最後記得將端口加入防火牆策略裏。 啓動sshd服務 # systemctl start sshd.service # systemctl enable sshd.service 遠程鏈接 $ ssh root@192.168.48.128 能夠用scp、sftp等命令進行文件傳輸,簡單格式如: $ scp [[user@]host1:]file1 ... [[user@]host2:]file2 xstart + ssh: 終端:/usr/bin/gnome-terminal 文件管理器:/usr/bin/nautilus 其餘能夠用whereis命令查詢 # where firefox # whereis firefox 配置SSH(在本機生成sshkey,而後將公鑰加入到遠程authorized_keys中) $ ssh-keygen -t rsa -b 4096 -C "bob@email.com" $ eval "$(ssh-agent -s)" Agent pid 28728 $ ssh-add -k ~/.ssh/id_rsa // ssh-add -K ~/.ssh/id_rsa $ clip < ~/.ssh/id_rsa.pub // pbcopy < ~/.ssh/id_rsa.pub 複製id_rsa.pub內容到遠程機器,追加到~/.ssh/authorized_keys 這個文件的權限是600 自動啓動ssh-agent和ssh-add # vim ~/.bash_profile // vim ~/.zshrc ------------------------ SSH_ENV="$HOME/.ssh/environment" function start_agent { echo "Initialising new SSH agent..." /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" echo succeeded chmod 600 "${SSH_ENV}" . "${SSH_ENV}" > /dev/null # /usr/bin/ssh-add -k ~/.ssh/your_id_rsa /usr/bin/ssh-add; } # Source SSH settings, if applicable if [ -f "${SSH_ENV}" ]; then . "${SSH_ENV}" > /dev/null #ps ${SSH_AGENT_PID} doesn't work under cywgin ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { start_agent; } else start_agent; fi 使用putty在pem和ppk之間轉換 *Windows https://putty.org/ https://the.earth.li/~sgtatham/putty/latest/w64/putty-64bit-0.70-installer.msi 使用puttygen能夠生成ppk的能夠,而後可經過菜單Conversions->Export OpenSSH key命令, 導出未 xxxx.gem *Linux $ sudo yum install putty (Dpkg-based: $ sudo apt-get install putty-tools ) // pem to ppk $ sudo puttygen xxxx.pem -o xxxx.ppk -O private // ppk to pem $ sudo puttygen xxxx.ppk -O private-openssh -o xxxx.pem ------tarball編譯 GnuPG (GPG)------ mac $ brew install gpg pinentry pinentry-mac $ echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf $ killall gpg-agent 若是使用期間發生錯誤,參考後面的 Inappropriate ioctl for device 配置環境變量。 SourceTree支持: $ ls -la /usr/local/bin/gpg lrwxr-xr-x /usr/local/bin/gpg -> ../Cellar/gnupg/2.2.10/bin/gpg $ ln -s /usr/local/bin/gpg /usr/local/bin/gpg2 在SourceTree的配置界面,點「高級」,更改「GPG程序」路徑爲 /usr/local/bin。 https://www.gnupg.org/download/ linux (tarball) $ mkdir ~/gnupg $ cd ~/gnupg $ wget https://www.gnupg.org/ftp/gcrypt/gnupg/gnupg-2.2.10.tar.bz2 wget https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.32.tar.bz2 wget https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.3.tar.bz2 wget https://www.gnupg.org/ftp/gcrypt/libksba/libksba-1.3.5.tar.bz2 wget https://www.gnupg.org/ftp/gcrypt/libassuan/libassuan-2.5.1.tar.bz2 wget https://www.gnupg.org/ftp/gcrypt/ntbtls/ntbtls-0.1.2.tar.bz2 wget https://www.gnupg.org/ftp/gcrypt/npth/npth-1.6.tar.bz2 wget https://www.gnupg.org/ftp/gcrypt/pinentry/pinentry-1.1.0.tar.bz2 // wget https://www.gnupg.org/ftp/gcrypt/gpgme/gpgme-1.11.1.tar.bz2 // wget https://www.gnupg.org/ftp/gcrypt/gpa/gpa-0.9.10.tar.bz2 $ tar xvjf gnupg-2.2.10.tar.bz2 tar xvjf libgpg-error-1.32.tar.bz2 tar xvjf libgcrypt-1.8.3.tar.bz2 tar xvjf libksba-1.3.5.tar.bz2 tar xvjf libassuan-2.5.1.tar.bz2 tar xvjf ntbtls-0.1.2.tar.bz2 tar xvjf npth-1.6.tar.bz2 tar xvjf pinentry-1.1.0.tar.bz2 // tar xvjf gpgme-1.11.1.tar.bz2 // tar xvjf gpa-0.9.10.tar.bz2 // 編譯安裝GnuPG組件 $ cd libgpg-error-1.32 $ ./configure $ sudo make && sudo make install $ cd ../libgcrypt-1.8.3 $ ./configure $ sudo make && sudo make install $ cd ../libksba-1.3.5 $ ./configure $ sudo make && sudo make install $ cd ../libassuan-2.5.1 $ ./configure $ sudo make && sudo make install $ cd ../ntbtls-0.1.2 $ ./configure $ sudo make && sudo make install $ cd ../npth-1.6 $ ./configure $ sudo make && sudo make install // 編譯安裝GnuPG $ cd ../gnupg-2.2.10 $ ./configure $ sudo make -j8 && sudo make install $ whereis gpg gpg: /usr/bin/gpg /usr/local/bin/gpg /usr/share/man/man1/gpg.1.gz $ /usr/local/bin/gpg --version /usr/local/bin/gpg: error while loading shared libraries: libgcrypt.so.20: cannot open shared object file: No such file or directory 正常會顯示版本信息,若是出現這個錯誤,先得到libgcrypt.so.20文件的位置,而後加入變量LD_LIBRARY_PATH中: $ whereis libgcrypt.so.20 libgcrypt.so: /usr/lib/libgcrypt.so.11 /usr/lib64/libgcrypt.so.11 /usr/local/lib/libgcrypt.so.20 /usr/local/lib/libgcrypt.so $ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH $ /usr/local/bin/gpg --version gpg (GnuPG) 2.2.10 libgcrypt 1.8.3 Copyright (C) 2018 Free Software Foundation, Inc. ... 將環境變量添加到啓動配置,如.bashrc中 $ echo export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH >> ~/.bashrc 同理檢查PATH環境變量,使/usr/local/bin在/usr/bin前,然gpg命令直接運行咱們編譯的版本。 從新進入會話,輸入 gpg --version 應該是剛纔安裝的版本。 必要組件安裝: --- // 用於輸入密碼保護(必須) $ cd ../pinentry-1.1.0 $ ./configure $ sudo make && sudo make install --- 下面兩個可選,可能須要修改庫的路徑,configure才能正確經過。 // GPGME is the standard library to access GnuPG functions from programming languages. $ cd ../gpgme-1.11.1 $ ./configure $ sudo make && sudo make install // GPA is a graphical frontend to GnuPG. $ cd ../gpa-0.9.10 $ ./configure $ sudo make && sudo make install --- 最後可刪除無用的源文件 $ cd ~ $ sudo rm -rf gnupg ----------------- 使用 ----------------- 1. 查看已有的GPG keys $ gpg --list-secret-keys --keyid-format LONG 2. 建立一個GPG key $ gpg --full-generate-key gpg (GnuPG) 2.2.10; Copyright (C) 2018 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) Your selection? RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (2048) Requested keysize is 2048 bits Please specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) Key does not expire at all Is this correct? (y/N) y GnuPG needs to construct a user ID to identify your key. Real name: yourname Email address: yourname@email.com Comment: demo You selected this USER-ID: "yourname (demo) <yourname@email.com>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. gpg: key F461FA2D923C3798 marked as ultimately trusted gpg: revocation certificate stored as '/home/yourname/.gnupg/openpgp-revocs.d/BA4CF1650621335540E42DB5F461FA2D923C3798.rev' public and secret key created and signed. pub rsa2048 2018-09-18 [SC] BA4CF1650621335540E42DB5F461FA2D923C3798 uid yourname (demo) <yourname@email.com> sub rsa2048 2018-09-18 [E] 3. 生成吊銷證書 $ gpg --list-secret-keys --keyid-format LONG /home/yourname/.gnupg/pubring.gpg ------------------------ sec rsa2048/F461FA2D923C3798 2018-09-18 [SC] BA4CF1650621335540E42DB5F461FA2D923C3798 uid [ultimate] yourname (demo) <yourname@email.com> ssb rsa2048/96E3D9B0C023B825 2018-09-18 [E] 記住sec中算法後面的值,輸入在下面 (說明:也能夠用郵箱地址替換這個KEY值) $ gpg --gen-revoke F461FA2D923C3798 4. 導出GPG key $ gpg --armor --export F461FA2D923C3798 -----BEGIN PGP PUBLIC KEY BLOCK----- mQENBFugt1QBCACpIrObmogNUtVRGogRUub4GmP+4IlZxu+Q5ExhGHFNhdTOEbii 9OT4Vy6snZoURWwxKPNu5/W35cs57+tv/FjVEqp1fDgnhK8YHo1AtfO5Yjqq/UR/ mPBdOBsKlstKl9+cCR/dv+uE23/fJnNqfbLZUyv8GRPwBh7OggX2MO4elzzzujnH ... -----END PGP PUBLIC KEY BLOCK----- 複製包括-----BEGIN PGP PUBLIC KEY BLOCK-----和-----END PGP PUBLIC KEY BLOCK-----的所有內容。 5. 添加一個user id到GPG key $ gpg --edit-key F461FA2D923C3798 > adduid Real name: myname Email address: myname@email.com Comment: You selected this USER-ID: "myname <myname@email.com>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o sec rsa2048/F461FA2D923C3798 created: 2018-09-18 expires: never usage: SC trust: ultimate validity: ultimate ssb rsa2048/96E3D9B0C023B825 created: 2018-09-18 expires: never usage: E [ultimate] (1) yourname (demo) <yourname@email.com> [ unknown] (2). myname <myname@email.com> > quit Save changes? (y/N) y 可使用help瞭解更多命令。 6. 應用 - 可在github設置 -> SSH and GPG keys裏,添加生成PGP KEY,注意使用對應的郵箱和user id的GPG KEY - 可用於git簽名,如 $ git config --global user.signingkey F461FA2D923C3798 提交的簽名 $ git config commit.gpgsign true $ git config --global commit.gpgsign true 而後提交代碼(-S): $ git commit -S -m your commit message tag的簽名(-s) $ git tag -s mytag 驗證(-v) $ git tag -v mytag - 使用gpg-agent幫助減小密碼輸入,可將下面命令寫入~/.xsession、 ~/.profile或者.bash_profile等啓動文件 eval $(gpg-agent --daemon) ----------------- 排除故障 ----------------- 故障:Inappropriate ioctl for device 解決: $ echo "test" | gpg --clearsign 若是提示 Inappropriate ioctl for device,設置變量指向tty $ export GPG_TTY=$(tty) $ echo 'export GPG_TTY=$(tty)' >> ~/.zshrc // 或者.bashrc, .bash_profile 故障:apt: Unknown error executing apt-key 解決: sudo apt-get clean sudo rm /var/lib/apt/lists/* sudo rm /var/lib/apt/lists/partial/* sudo apt-get clean sudo apt-get update ----------tarball編譯git---------- https://www.kernel.org/pub/software/scm/git/ **********centos命令以下: $ sudo su # yum install curl wget gcc gcc-c++ perl-ExtUtils-MakeMaker -y # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y 下載git源碼(curl和wget選一個便可) # wget -P /usr/src/git-2.19.0 https://www.kernel.org/pub/software/scm/git/git-2.19.0.tar.gz // # curl --create-dirs -o /usr/src/git-2.19.0/git-2.19.0.tar.gz https://www.kernel.org/pub/software/scm/git/git-2.19.0.tar.gz # chmod -R 755 /usr/src/git-2.19.0/ 解壓安裝 # cd /usr/src/git-2.19.0/ # tar zxf git-2.19.0.tar.gz # cd git-2.19.0 # ./configure --prefix=/usr/local/ # make install 查看結果,刪除yum的git和git-2.19.0.tar.gz # whereis git git: /usr/bin/git /usr/local/bin/git /usr/share/man/man1/git.1.gz # /usr/local/bin/git --version git version 2.19.0 # rm -f /usr/src/git-2.19.0/git-2.19.0.tar.gz # yum remove git -y # yum autoremove -y # exit $ git version git version 2.19.0 **********debian命令以下: $ sudo apt update $ sudo apt install -y build-essential $ sudo apt install -y libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev $ sudo curl --create-dirs -o /usr/src/git-2.19.0/git-2.19.0.tar.gz https://www.kernel.org/pub/software/scm/git/git-2.19.0.tar.gz (或) $ sudo wget -P /usr/src/git-2.19.0 https://www.kernel.org/pub/software/scm/git/git-2.19.0.tar.gz $ cd /usr/src/git-2.19.0/ $ sudo tar zxf git-2.19.0.tar.gz $ cd git-2.19.0 $ sudo ./configure --prefix=/usr/local/ $ sudo make install $ whereis git git: /usr/bin/git /usr/local/bin/git /usr/share/man/man1/git.1.gz $ /usr/local/bin/git version git version 2.15.1 $ sudo rm -f /usr/src/git-2.19.0/git-2.19.0.tar.gz $ sudo apt remove git $ sudo apt autoremove -------------------------- git lfs -------------------------- MacOS $ brew install git-lfs Linux $ mkdir git-lfs $ cd git-lfs $ wget https://github.com/git-lfs/git-lfs/releases/download/v2.5.1/git-lfs-linux-amd64-v2.5.1.tar.gz $ tar xvzf git-lfs-linux-amd64-v2.5.1.tar.gz $ sudo ./install.sh $ git lfs version $ cd .. $ rm -rf git-lfs -------------------------- git flow -------------------------- https://github.com/nvie/gitflow https://github.com/nvie/gitflow/wiki/Linux 安裝方式一: MacOS $ brew install git-flow 或者 $ wget --no-check-certificate -q -O - https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | sudo bash Debian $ apt-get install git-flow Fedora $ yum install gitflow 安裝方式二:手動安裝 手動安裝方法1(推薦) $ git clone --recursive git://github.com/nvie/gitflow.git $ cd gitflow $ sudo make install 若是安裝到其餘目錄,能夠 $ sudo make prefix=/opt/local install $ git flow version $ cd .. $ rm -rf gitflow 手動安裝方法2 $ wget -q -O - https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | sh 刪除 $ sudo ./gitflow-installer.sh uninstall 版本:git flow version zsh插件:git-flow、bobthecow/git-flow-completion 若是提示zsh compinit: insecure directories, run compaudit for list. 能夠用下面命令更改權限 compaudit | xargs chmod -R 755 使用:分支feature/demo1,修改後合併到develop分支 $ git clone ... $ cd ... $ git flow init -d $ git flow feature start demo1 // 修改代碼 $ git flow feature finish demo1 分支模式學習文檔: https://danielkummer.github.io/git-flow-cheatsheet/index.html https://nvie.com/posts/a-successful-git-branching-model/ ----------Debian 安裝圖形界面---------- $ sudo apt edit-sources deb http://ftp2.cn.debian.org/debian/ testing main non-free contrib deb-src http://ftp2.cn.debian.org/debian/ testing main non-free contrib deb http://ftp2.cn.debian.org/debian/ testing-updates main non-free contrib deb-src http://ftp2.cn.debian.org/debian/ testing-updates main non-free contrib deb http://ftp2.cn.debian.org/debian-security/ testing/updates main deb-src http://ftp2.cn.debian.org/debian-security/ testing/updates main 注:更多鏡像源列表: https://www.debian.org/mirror/list 官方一直維護着至少三個發行版本:"穩定版(stable)","測試版(testing)"和"不穩定版(unstable)"。 穩定版的版本代號: https://www.debian.org/releases/index.zh-cn.html 下一代 Debian 正式發行版的代號爲 "buster" — 發佈時間還沒有肯定 Debian 9("stretch") — 當前的穩定版 Debian 8("jessie") — 被淘汰的穩定版 Debian 7("wheezy") — 被淘汰的穩定版 Debian 6.0("squeeze") — 被淘汰的穩定版 Debian GNU/Linux 5.0("lenny") — 被淘汰的穩定版 Debian GNU/Linux 4.0("etch") — 被淘汰的穩定版 Debian GNU/Linux 3.1("sarge") — 被淘汰的穩定版 Debian GNU/Linux 3.0("woody") — 被淘汰的穩定版 Debian GNU/Linux 2.2("potato") — 被淘汰的穩定版 Debian GNU/Linux 2.1("slink") — 被淘汰的穩定版 Debian GNU/Linux 2.0("hamm") — 被淘汰的穩定版 更新所有軟件 $ sudo apt update $ sudo apt list --upgradable $ sudo apt upgrade $ sudo autoremove *** 一鍵安裝推薦的Gnome Desktop或KDE *** $ sudo apt install task-gnome-desktop $ sudo apt install task-kde-desktop 參見: https://wiki.debian.org/Gnome https://wiki.debian.org/KDE [freeBSD # pkg update # pkg upgrade # pkg autoremove --- Gnome 3 --- https://www.freebsd.org/doc/handbook/x11-wm.html # pkg install gnome3 # vi /etc/fstab proc /proc procfs rw 0 0 # vi /etc/rc.conf dbus_enable="YES" hald_enable="YES" gdm_enable="YES" gnome_enable="YES" % echo "exec /usr/local/bin/gnome-session" > ~/.xinitrc 若是使用XDM,用下面代替 % echo ". /usr/local/etc/xdg/xfce4/xinitrc" > ~/.xsession --- KDE 4 --- # pkg install x11/kde4 # vi /etc/fstab proc /proc procfs rw 0 0 # vi /etc/rc.conf dbus_enable="YES" hald_enable="YES" kdm4_enable="YES" % echo "exec /usr/local/bin/startkde" > ~/.xsession --- Xfce --- # pkg install xfce # vi /etc/rc.conf dbus_enable="YES" % echo ". /usr/local/etc/xdg/xfce4/xinitrc" > ~/.xinitrc 若是使用XDM,用下面代替 % echo ". /usr/local/etc/xdg/xfce4/xinitrc" > ~/.xsession ] (( manjaro https://wiki.manjaro.org/index.php/Install_Desktop_Environments $ sudo pacman -S plasma kio-extras // 必須 $ sudo pacman -S kde-applications $ sudo systemctl enable sddm.service --force // 建議使用SDDM $ reboot $ sudo pacman -S manjaro-kde-settings sddm-breath-theme manjaro-settings-manager-knotifier manjaro-settings-manager-kcm $ /usr/bin/cp -rf /etc/skel/. ~ )) *** 手動安裝KDE(wayland)*** $ sudo apt install plasma-workspace-wayland/testing $ sudo apt install lightdm $ sudo reboot now 若是「開始」菜單異常,窗口沒有邊框,嘗試移除kwin-wayland $ sudo remove kwin-wayland $ sudo autoremove 終端模擬器 Kconsole,按Alt+F2輸入terminal,最下面的就是,若是沒有,手動安裝。 $ sudo apt install net-tools $ sudo apt install ttf-mscorefonts-installer 若是打開Trash有問題 $ sudo apt install konqueror 而後在System Settings的Default Applications裏選擇File Manager爲Konqueror $ sudo apt search firefox $ sudo apt install firefox-esr-l10n-zh-cn 輸入法 $ sudo apt install fcitx fcitx-googlepinyin (( manjaro $ sudo pacman -S fcitx fcitx-configtool fcitx-googlepinyin fcitx-gtk2 fcitx-gtk3 fcitx-m17n fcitx-qt4 fcitx-qt5 $ vim ~/.xprofile export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export XMODIFIERS=@im=fcitx $ sudo reboot )) 中文字體 $ sudo yum install fontconfig mkfontscale $ sudo yum install google-noto-sans-simplified-chinese-fonts google-noto-sans-traditional-chinese-fonts ------------------------ 啓動到命令行 1) 修改Grub爲命令行方式 $ sudo vim /etc/default/grub 更改GRUB_CMDLINE_LINUX值爲text: GRUB_CMDLINE_LINUX_DEFAULT="quiet" GRUB_CMDLINE_LINUX="" 爲 GRUB_CMDLINE_LINUX_DEFAULT="quiet" GRUB_CMDLINE_LINUX="text" 反註釋 GRUB_TERMINAL=console $ sudo /usr/sbin/update-grub 2) 修改系統爲命令行方式 $ sudo systemctl set-default multi-user.target 改回圖形界面的方式 $ sudo systemctl set-default graphical.target ------- fish-shell ------- fish-shell(https://github.com/fish-shell/fish-shell) centos 7: $ cd /etc/yum.repos.d/ $ wget https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_7/shells:fish:release:2.repo $ yum install fish debian 9: $ echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/2/Debian_9.0/ /' > /etc/apt/sources.list.d/fish.list $ apt-get update $ apt-get install fish fedora 26: $ dnf config-manager --add-repo https://download.opensuse.org/repositories/shells:fish:release:2/Fedora_26/shells:fish:release:2.repo $ dnf install fish ubuntu fish PPA: $ sudo apt-add-repository ppa:fish-shell/release-2 $ sudo apt-get update $ sudo apt-get install fish Oh-my-fish(https://github.com/oh-my-fish/oh-my-fish) $ curl -L https://get.oh-my.fish | fish $ echo $OMF_CONFIG ~/.config/omf $ omf list Plugins fish-spec omf Themes default $ omf install eden $ omf theme eden ------- vim spf13 插件 ------- ** ubuntu: VIM插件spf13-vim 由於spf13-vim 中的neocomplete.vim插件須要lua支持,因此要卸載vim,下載源代碼,而後+lua編譯vim vim with lua: $ cd ~ $ sudo apt-get remove --purge vim $ sudo apt-get autoclean $ sudo apt-get install python-dev python3-dev ruby-dev luajit liblua5.1-dev libluajit-5.1 libperl-dev libncurses5-dev $ sudo rm -rf /usr/local/share/vim $ sudo rm /usr/bin/vim $ sudo mkdir -p /usr/include/lua5.1/include $ sudo cp /usr/include/lua5.1/*.h /usr/include/lua5.1/include/ $ cd ~ $ git clone --depth 1 https://github.com/vim/vim.git $ cd ~/vim/src $ make distclean $ ./configure --with-features=huge \ --enable-largefile \ --enable-multibyte \ --enable-perlinterp \ --enable-rubyinterp \ --enable-luainterp \ --enable-python3interp \ --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu \ --with-luajit \ --enable-fail-if-missing \ --with-lua-prefix=/usr/include/lua5.1 \ --enable-cscope \ --enable-gui=auto 注意:python3 和 python 同時給定,優先會使用python --enable-pythoninterp \ --with-python-config-dir=/usr/lib/python2.7/config \ $ make -j8 $ sudo make install $ whereis vim vim: /usr/local/bin/vim /usr/share/man/man1/vim.1 $ vim --version ** centos: $ sudo yum remove vim $ sudo yum install -y ruby ruby-devel lua lua-devel luajit luajit-devel ctags mercurial python python-devel python3 python3-devel tcl-devel perl perl-devel perl-ExtUtils-ParseXS perl-ExtUtils-XSpp perl-ExtUtils-CBuilder perl-ExtUtils-Embed ncurses-devel $ git clone --depth 1 https://github.com/vim/vim.git $ cd vim $ sudo make distclean $ ./configure --with-features=huge --enable-multibyte --enable-rubyinterp --enable-pythoninterp --enable-perlinterp --enable-luainterp --enable-gui=gtk2 --enable-cscope --with-tlib=ncurses --prefix=/usr $ sudo make install $ vim ~/.zshrc ; 若是vi沒有指向咱們編譯的vim,能夠將vi別名vim 在結尾加入: alias vi=vim $ source ~/.zshrc ** mac: macvim brew install macvim --with-cscope --with-lua --with-override-system-vim brew linkapps macvim #將MacVim程序加入到Launchpad中 終端運行macvim:(位置:/usr/local/bin/mvim) mvim #會打開macvim新窗口 mvim -v #會在當前終端中運行 (( manjaro $ sudo pacman -S vim 而後安裝spf13便可 )) 安裝spf13-vim(https://github.com/spf13/spf13-vim): $ cd ~ $ sudo apt-get install curl exuberant-ctags //ubuntu -可用- $ curl https://raw.githubusercontent.com/m2nlight/spf13-vim/3.0/bootstrap.sh -L > spf13-vim.sh && sh spf13-vim.sh -代替下面的內容- $ curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh 或者 $ curl https://raw.githubusercontent.com/spf13/spf13-vim/3.0/bootstrap.sh -L > spf13-vim.sh && sh spf13-vim.sh 或者 $ git clone --depth 1 https://github.com/spf13/spf13-vim.git $ mv spf13-vim ~/.spf13-vim-3 $ ~/.spf13-vim-3/bootstrap.sh 等待插件安裝完成。 當出現amirh/HTML-AutoCloseTag錯誤(提示是登錄github),按Ctrl+w,jj跳過這個錯誤 所有安裝後 $ vim ~/.vimrc.bundles 找到amirh,替換爲okayliao,保存退出後用下面命令從新安裝一遍插件。 $ vim +BundleInstall! +BundleClean +q ----顯示用戶和組---- cat /etc/passwd cat /etc/group 查看用戶: cut -d : -f 1 /etc/passwd getent passwd $USER 能夠登陸的用戶: cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1 ----清華大學鏡像源---- https://mirrors.tuna.tsinghua.edu.cn/help/centos/ https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ https://mirrors.tuna.tsinghua.edu.cn/help/pypi/ ... ----VNC---- VNC,在Windows端可使用TightVNC/UltraVNC來鏈接Linux gnome桌面。 以ubuntu爲例,在程序裏打開Desktop Sharing程序,便可進行VNC配置, 默認是安全鏈接的,若是使用TightVNC鏈接,則須要關閉其安全鏈接,命令: $ gsettings get org.gnome.Vino require-encryption true $ gsettings set org.gnome.Vino require-encryption false 另外,Ubuntu gnome還有一個Remmina Remote Desktop Client軟件,用來鏈接包括VNC方法在內的客戶端工具。 ----重置root密碼---- 適用於systemd的centos等發行版本。若是啓用了LUKS等加密硬盤,須要輸入LUKS密碼。 1. 在GRUB引導界面,輸入e,進入編輯界面 2. 將光標移動到Linux16這行,刪除rhgb quiet,替換爲rd.break enforcing=0 而後按下Ctrl+X啓動,系統進入緊急模式 3. 掛載硬盤而後修改密碼: # mount -o remount,rw /sysroot # chroot /sysroot # passwd 修改後輸入兩次exit重啓系統 4. 用root身份登錄恢復/etc/shadow的SELinux標籤 # restorecon -v /etc/shadow # setenforce 1 ----pacman---- *自升級 pacman -S pacman *查詢 pacman -Ss yaourt *安裝 pacman -S yaourt vim curl git *刪除 pacman -R yaourt pacman -Rs yaourt // 同時刪除無用的依賴 *刪除無用的包 sudo pacman -Rcs $(pacman -Qdtq) // 比-R移除,包括遞歸軟件包 sudo pacman -R $(pacman -Qdtq) *所有升級 pacman -Syu 或者pacman -Syyu *清理和回滾 以根用戶權限執行降級系統命令。爲了順利執行,可能須要先清除系統緩存 緩存位置:/var/cache/pacman/pkg pacman -Scc # 啓用降級 pacman -Syyuu ----工具---- *7Z sudo yum install p7zip sudo apt install p7zip-full sudo pacman -S p7zip * HTOP (若是安裝了linuxbrew,也能夠用brew命令安裝) sudo yum install htop sudo apt install htop sudo dnf install htop sudo pacman -S htop brew install htop * HTTPIE sudo pip3 install httpie brew install httpie * CHT.SH curl cht.sh/:help sudo pacman -S xsel rlwrap mkdir -p ~/bin curl https://cht.sh/:cht.sh > ~/bin/cht.sh chmod +x ~/bin/cht.sh ~/bin/cht.sh python :learn ~/bin/cht.sh --shell * AXEL sudo apt install axel sudo pacman -S axel * Google Chrome Browser (注意不支持32位) ***rhel/centos/fedora # vim /etc/yum.repos.d/google-chrome.repo [google-chrome] name=google-chrome baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch enabled=1 gpgcheck=1 gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub # yum info google-chrome-stable # yum install google-chrome-stable // 更新 # yum update google-chrome-stable ***debian/ubuntu # echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/google-chrome.list 或者編輯/etc/apt/sources.list,加入 deb http://dl.google.com/linux/chrome/deb/ stable main # wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 或者 wget https://dl-ssl.google.com/linux/linux_signing_key.pub apt-key add linux_signing_key.pub # apt-get update # apt-get install google-chrome-stable ***arch/manjaro (編譯離線版本) 方法一(推薦):yaourt # yaourt -S google-chrome 按提示輸入以下: Edit PKGBUILD ? n Edit google-chrome.install ? n Continue building google-chrome ? y 等待打包完成,提示導出 google-chrome 到 /var/cache/pacman/pkg/ 目錄,可能要輸入密碼。 Continue installing google-chrome ? y ::Proceed with installation? y 等待安裝完成。 方法二:不使用yaourt 打開 https://aur.archlinux.org/packages/google-chrome/ 複製 Git Clone URL: https://aur.archlinux.org/google-chrome.git $ git clone --depth 1 https://aur.archlinux.org/google-chrome.git $ cd google-chrome $ makepkg -s 等待下載打包完成,會獲得 google-chrome-69.0.3497.92-1-x86_64.pkg.tar.xz 而後用pacman安裝 $ sudo pacman -U google-chrome-69.0.3497.92-1-x86_64.pkg.tar.xz 安裝完成後可刪除不要的文件 $ cd .. $ rm -rf google-chrome * Linuxbrew sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)" 會提示建立的目錄,包括(/home/linuxbrew),輸入enter繼續安裝,其餘鍵中止安裝。 若是出現錯誤:Error: Git must be installed and in your PATH! 設置環境變量(注意:這裏所有以zsh shell爲例): echo "export HOMEBREW_NO_ENV_FILTERING=1" >> ~/.zshrc 重啓shell後再次執行 /home/linuxbrew/.linuxbrew/bin/brew update --force 而後執行配置 test -d ~/.linuxbrew && PATH="$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin:$PATH" test -d /home/linuxbrew/.linuxbrew && PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH" test -r ~/.bash_profile && echo "export PATH='$(brew --prefix)/bin:$(brew --prefix)/sbin'":'"$PATH"' >>~/.bash_profile echo "export PATH='$(brew --prefix)/bin:$(brew --prefix)/sbin'":'"$PATH"' >>~/.zshrc 重啓shell 安裝經常使用工具 brew install bat echo "alias cat='bat'" >> ~/.zshrc brew install fzf $(brew --prefix)/opt/fzf/install vim ~/.zshrc alias preview="fzf --preview 'bat --color \"always\" {}'" # 支持在 VS Code 裏用 ctrl+o 來打開選擇的文件 export FZF_DEFAULT_OPTS="--bind='ctrl-o:execute(code {})+abort'" 重啓shell brew install prettyping echo "alias ping='prettyping --nolegend'" >> ~/.zshrc brew install htop brew install diff-so-fancy vim ~/.gitconfig [pager] diff = diff-so-fancy | less --tabs=1,5 -RFX show = diff-so-fancy | less --tabs=1,5 -RFX brew install ncdu echo 'alias du="ncdu --color dark -rr -x --exclude .git --exclude node_modules"' >> ~/.zshrc brew install tldr echo "alias help='tldr'" >> ~/.zshrc tldr bat 安裝ack和ng brew install ack brew install the_silver_searcher 安裝fd brew install fd 注意:會自動檢查依賴並安裝編譯,其中rust,會很是慢(超過一個小時)。 例子: $ fd cli # 全部包含 "cli" 的文件名 $ fd -e md # 全部以 .md 做爲擴展名的文件 $ fd cli -x wc -w # 搜索 "cli" 而且在每一個搜索結果上運行 `wc -w`