2017年5月
Centos7 设置Mongodb开机启动-自定义服务
一.官网下载 mongodb,解压到指定目录
本机mongodb目录为:/home/apps/mongodb/
二 .编写配置文件,主要指定数据库文件,日志文件,以及一些启动参数.
(1).在mongodb下新建data文件夹,以及子文件夹db,logs, 在logs中新建mongodb.log日志文件,其中db文件夹用来存储数据库文件,logs用来存储日志文件
(2).在mongodb/bin/目录下新建mongodb.conf配置文件,内容如下
dbpath=/home/apps/mongodb/data logpath=/home/apps/mongodb/logs/mongodb.log logappend=true port=27018 fork=true auth=true logappend=true
dbpath:数据库文件路径
logpath:日志文件路径
logappend:是否追加日志
port:端口
fork:是否以后台进程启动
auth:是否启动授权认证
nohttpinterface:是否支持HTTP形式访问
三.编写自定义服务
(1).在/lib/systemd/system/目录下新建mongodb.service文件,内容如下
[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/home/apps/mongodb/data/bin/mongod --config /home/apps/mongodb/data/bin/mongodb.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/home/apps/mongodb/data/bin/mongod --shutdown --config /home/apps/mongodb/data/bin/mongodb.conf PrivateTmp=true [Install] WantedBy=multi-user.target
(2).设置权限
chmod 754 mongodb.service
(3).启动关闭服务,设置开机启动
#启动服务 systemctl start mongodb.service #关闭服务 systemctl stop mongodb.service #开机启动 systemctl enable mongodb.service
#开机不启动 systemctl disable mongodb.service
CentOS 7 vs CentOS 6的不同
(1)桌面系统
[CentOS6] GNOME 2.x
[CentOS7] GNOME 3.x(GNOME Shell)
(2)文件系统
[CentOS6] ext4
[CentOS7] xfs
(3)内核版本
[CentOS6] 2.6.x-x
[CentOS7] 3.10.x-x
(4)启动加载器
[CentOS6] GRUB Legacy (+efibootmgr)
[CentOS7] GRUB2
(5)防火墙
[CentOS6] iptables
[CentOS7] firewalld
(6)默认数据库
[CentOS6] MySQL
[CentOS7] MariaDB
(7)文件结构
[CentOS6] /bin, /sbin, /lib, and /lib64在/下
[CentOS7] /bin, /sbin, /lib, and /lib64移到/usr下
(8)主机名
[CentOS6] /etc/sysconfig/network
[CentOS7] /etc/hostname
(9)时间同步
[CentOS6]
$ ntp
$ ntpq -p
[CentOS7]
$ chrony
$ chronyc sources
(10)修改时间
[CentOS6]
$ vim /etc/sysconfig/clock
ZONE="Asia/Tokyo"
UTC=fales
$ sudo ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
[CentOS7]
$ timedatectl set-timezone Asia/Tokyo
$ timedatectl status
(11)修改地区
[CentOS6]
$ vim /etc/sysconfig/i18n
LANG="ja_JP.utf8"
$ /etc/sysconfig/i18n
$ locale
[CentOS7]
$ localectl set-locale LANG=ja_JP.utf8
$ localectl status
(12)服务相关
1)启动停止
[CentOS6]
$ service service_name start
$ service service_name stop
$ service sshd restart/status/reload
[CentOS7]
$ systemctl start service_name
$ systemctl stop service_name
$ systemctl restart/status/reload sshd
自启动
[CentOS6]
$ chkconfig service_name on/off
[CentOS7]
$ systemctl enable service_name
$ systemctl disable service_name
服务一览
[CentOS6]
$ chkconfig --list
[CentOS7]
$ systemctl list-unit-files
$ systemctl --type service
强制停止
[CentOS6]
$ kill -9 <PID>
[CentOS7]
$ systemctl kill --signal=9 sshd
(13)网络
1)网络信息
[CentOS6]
$ netstat
$ netstat -I
$ netstat -n
[CentOS7]
$ ip n
$ ip -s l
$ ss
2)IP地址MAC地址
[CentOS6]
$ ifconfig -a
[CentOS7]
$ ip address show
3)路由
[CentOS6]
$ route -n
$ route -A inet6 -n
[CentOS7]
$ ip route show
$ ip -6 route show
(14)重启关闭
1)关闭
[CentOS6]
$ shutdown -h now
[CentOS7]
$ poweroff
$ systemctl poweroff
2)重启
[CentOS6]
$ reboot
$ shutdown -r now
[CentOS7]
$ reboot
$ systemctl reboot
3)单用户模式
[CentOS6]
$ init S
[CentOS7]
$ systemctl rescue
4)启动模式
[CentOS6]
[GUICUI]
$ vim /etc/inittab
id:3:initdefault:
[CUIGUI]
$ startx
[CentOS7]
[GUICUI]
$ systemctl isolate multi-user.target
[CUIGUI]
$systemctl isolate graphical.target
默认
$ systemctl set-default graphical.target
$ systemctl set-default multi-user.target
当前
$ systemctl get-default
http://www.cnblogs.com/bethal/p/5945026.html
SSH keys生成
SSH
SSH keys
SSH key 可以让你在你的电脑和Code服务器之间建立安全的加密连接。 先执行以下语句来判断是否已经存在本地公钥:
cat ~/.ssh/id_rsa.pub
如果你看到一长串以 ssh-rsa
或 ssh-dsa
开头的字符串, 你可以跳过 ssh-keygen
的步骤。
提示: 最好的情况是一个密码对应一个ssh key,但是那不是必须的。你完全可以跳过创建密码这个步骤。请记住设置的密码并不能被修改或获取。
你可以按如下命令来生成ssh key:
ssh-keygen -t rsa -C "zrp1234@163.com"
这个指令会要求你提供一个位置和文件名去存放键值对和密码,你可以点击Enter键去使用默认值。
用以下命令获取你生成的公钥:
cat ~/.ssh/id_rsa.pub
复制这个公钥放到你的个人设置中的SSH/My SSH Keys下,请完整拷贝从ssh-
开始直到你的用户名和主机名为止的内容。
如果打算拷贝你的公钥到你的粘贴板下,请参考你的操作系统使用以下的命令:
Windows:
clip < ~/.ssh/id_rsa.pub
Mac:
pbcopy < ~/.ssh/id_rsa.pub
GNU/Linux (requires xclip):
xclip -sel clip < ~/.ssh/id_rsa.pub
Applications
Eclipse
如何在Eclipse中添加ssh key: https://wiki.eclipse.org/EGit/User_Guide#Eclipse_SSH_Configuration
Tip: Non-default OpenSSH key file names or locations
如果,不管你有什么理由,当你决定去用一个非默认的位置或文件名去存放你的ssh key。你必须配置好你的ssh客户端以找到你的ssh私钥去连接Code服务器,对于OpenSSH客户端,这个通常是在~/.ssh/config
类似的位置配置的:
#
# Our company's internal GitLab server
#
Host my-git.company.com
RSAAuthentication yes
IdentityFile ~/my-ssh-key-directory/company-com-private-key-filename