CentOS操作

606 阅读3分钟

软件安装

[需要添加到服务]MongoDB(数据库)

/*下载:因为我的服务器下载速度太慢,我在window上下载下来,安装[lrzsz],使用[Xshell]直接拖进去。*/

//直接下载
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.12.tgz

//解压:
tar -zxvf [包名]

//移动:我是准备将数据库放在:/usr/mongodb  目录下,因此会将文件移动到:/usr下,并重命名为 /usr/mongodb

//创建mongodb需要的文件和文件夹
mkdir -p /usr/mongodb/data/db
mkdir /usr/mongodb/logs
touch /usr/mongodb/logs/mongodb.log /usr/mongodb/mongodb.conf

//修改mongodb配置文件
vim /usr/mongodb/mongodb.conf

//写入内容:
#域名
bind_ip=0.0.0.0

#端口
port=8081

#数据库存文件存放目录  
dbpath=/usr/mongodb/data/db

#日志文件存放路径  
logpath=/usr/mongodb/logs/mongodb.log

#使用追加的方式写日志  
logappend=true

 #不以守护程序的方式启用,即不在后台运行  
fork=true

#最大同时连接数  
maxConns=100

#启用验证  
#我是先关闭验证,先连接增加账号密码,再回来设置为ture,重启mongodb.service
auth=true

#每次写入会记录一条操作日志(通过journal可以重新构造出写入的数据)。
journal=true

#即使宕机,启动时wiredtiger会先将数据恢复到最近一次的checkpoint点,然后重放后续的journal日志来恢复。
#存储引擎有mmapv1、wiretiger、mongorocks
storageEngine=wiredTiger
//写入内容结束

//配置环境变量:见配置环境变量一节

//将mongodb添加到系统服务并设置为开机启动
cd /usr/lib/systemd/system/
vim mongodb.service

//写入内容
[Unit]
Description=MongoDB
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
#User=root
#Group=root

Type=forking
#PIDFile=/mongodata/MongoDB.pid

ExecStart=/usr/mongodb/bin/mongod -f /usr/mongodb/mongodb.conf

ExecReload=/bin/kill HUP $MAINPID

ExecStop=/usr/mongodb/bin/mongod --shutdown -f /usr/mongodb/mongodb.conf

PrivateTmp=true


[Install]
WantedBy=multi-user.target
//写入内容结束

sudo systemctl enable mongodb.service
sudo systemctl start mongodb.service

centos安装Mongodb

centos将mongodb设置为服务

lrzsz(win和centos传输数据)

lrzsz是一个unix通信套件提供的X,Y,和ZModem文件传输协议 windows 需要向centos服务器上传文件,可直接在centos上执行命令yum -y install lrzsz 程序会自动安装好,然后如你要下载者sz [找到你要下载的文件] 如果你要上传,者rz 浏览找到你本机要上传的文件。需要注意的事这个命令无法在putty界面使用哦!

yum -y install lrzsz

[服务]SSH

//安装'policycoreutils-pythonopenssh-server'服务
sudo yum install -y curl policycoreutils-pythonopenssh-server

//将服务设置为开机启动
sudo systemctl enable sshd

//立马启动服务
sudo systemctl start sshd

[服务]firewall(防火墙)

//安装防火墙
yum install firewalld systemd -y

//启动防火墙
service firewalld start

//开启防火墙
systemctl start firewalld

//关闭防火墙
systemctl stop firewalld

//重启防火墙
sudo systemctl reload firewalld

//查看状态
systemctl status frewalld

//开机禁用
systemctl disable firewalld

//开机启用
systemctl enable firewalld

//添加http服务到防火墙 (permanent:表示永久生效,不添加则下一次开启失效)
sudo firewall-cmd --permanent --add-service=http

[服务]Postfix(发送邮件)

//安装
sudo yum install postfix

//设置为开机启动
sudo systemctl start postfix

//查看状态
ststemctl status postfix

wget(用于从外网下载插件)

//检测是否安装
wget -V

/**[出现如下信息,表示已经安装]
GNU Wget 1.14 built on linux-gnu.

+digest +https +ipv6 +iri +large-file +nls +ntlm +opie +ssl/openssl 

Wgetrc: 
    /etc/wgetrc (system)
Locale: /usr/share/locale 
Compile: gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/etc/wgetrc" 
    -DLOCALEDIR="/usr/share/locale" -I. -I../lib -I../lib -O2 -g -pipe 
    -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong 
    --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic 
Link: gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
    -fstack-protector-strong --param=ssp-buffer-size=4 
    -grecord-gcc-switches -m64 -mtune=generic -lssl -lcrypto 
    /usr/lib64/libssl.so /usr/lib64/libcrypto.so /usr/lib64/libz.so 
    -ldl -lz -lz -lidn -luuid -lpcre ftp-opie.o openssl.o http-ntlm.o 
    ../lib/libgnu.a 
*/

//安装
yum -y install wget

vim(编辑器)

yum install vim -y

Gitlab(代码托管: 最好是>1核,建议4核)

需要安装:SSH、Postfix、wget、vim

//添加gitlab镜像
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

//安装gilab
rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

/**
*	设置访问域名或ip
*/
vim  /etc/gitlab/gitlab.rb

//按i进入编辑内容模式, external_url(大概在第6行)
external_url 'http://localhost:8080'   
/**
*	8080是默认端口,如果想设置新端口,需要在防火墙开启新端口
* 	按esc退出编辑模式,再按:wq保存并退出
*/

//重置gitlab
gitlab-ctl reonfigure

//重启gitlab
gitlab-ctl restart

gitlab环境搭建

Git

sudo yum install git

sudo useradd git

gogs(代码托管: 适合1G1核的服务器)

//先安装git

//下载
wget https://dl.gogs.io/0.11.34/linux_amd64.tar.g

//解压、获得权限
sudo tar -xf linux_amd64.tar.gz -C /home/git
sudo chmod -R 700 /home/git/gogs
sudo chown -R git:git /home/git/gogs

//访问:localhost:3000,进行配置

//配置完,添加启动项和守护进程
sudo ln -sf /home/git/gogs/scripts/systemd/gogs.service /usr/lib/systemd/
sudo chmod u+x /home/git/gogs/scripts/systemd/gogs.service
sudo ln -sf /home/git/gogs/scripts/init/centos/gogs /etc/init.d/
sudo chmod u+x /home/git/gogs/scripts/init/centos/gogs
sudo /sbin/chkconfig gogs on
sudo service gogs restart

gogs安装

Center OS7 操作

环境变量设置

//进入用户环境变量设置文件
vim ~/.bash_profile

//比如加入2个环境变量(在打开的文件中输入):
export PATH=$PATH:/usr/mongodb/bin
export PATH=$PATH:/usr/git/bin

//使配置文件起作用
source ~/.bash_profile

 
//查看环境变量
printenv

进程命令

//查看目前在使用的端口
netstat -ntlp

//结束进程
kill [PID]

关于进程相关内容

防火墙命令

基本命令

//查看版本
firewall-cmd --version

//查看帮助
firewall-cmd --help

//显示状态
firewall-cmd --state

//查看所有打开的端口
firewall-cmd --zone=public --list-ports

//更新防火墙规则
firewall-cmd --reload

//查看区域信息
firewall-cmd --get-active-zones

//查看指定接口所属区域
firewall-cmd --get-zone-of-interface=eth0

//拒绝所有包
firewall-cmd --panic-on

//取消拒绝状态
firewall-cmd --panic-off

//查看是否拒绝
firewall-cmd --query-panic

端口操作

//添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

//重新载入
firewall-cmd --reload

//查看
firewall-cmd --zone= public --query-port=80/tcp

//删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent

防火墙操作

文件系统

文件夹

  • 创建
    • 单级:mkdir [文件夹名]
    • 多级:mkdir -p [多层文件夹名:a/b/c]
  • 删除文件夹
    • 空文件夹:rmdir [文件名]
    • 所有文件:rm -rf [文件名]
  • 重命名:mv [需要修改的目标] [新命名]
  • 移动:mv [需要移动的目标] [新路径]

文件

  • 创建:touch [文件名]
  • 删除:rm [文件名]
  • 重命名:mv [需要修改的目标] [新命名]
  • 移动:mv [需要移动的目标] [新路径]

服务命令

systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

开启服务

systemctl start [服务名]

关闭服务

systemctl stop [服务名]

查看状态

systemctl status [服务名]

开机禁用

sudo systemctl disable [服务名]

开机启用

sudo systemctl enable [服务名]

查看服务是否开机启动

systemctl is-enabled [服务名]

查看已启动项

systemctl list-unit-files|grep enabled

查看启动失败

systemctl --failed

vim的使用

进入vim编辑器: vim [文件名]

返回第一行g

去最后一行G

编辑内容: :i

推出编辑: esc键

保存并退出:wq

不保存退出:q!

无修改退出:q

搜索

命令模式下
:/字符串		//比如搜索'user'::/user

//下一个匹配
按下小写n

//上一个匹配
按下大写N

//取消匹配
nohlsearch
//or
set nohlseach
//or
noh
//or
set noh