分类: Linux
Mac ssh使用pem文件登录远程服务器
Redis服务管理
Redis服务实例应当遵守以下规范:
-
实例的目录应当为 /srv/redis/{$端口}/
-
实例的配置文件、回写文件、pid文件、日志文件应当都保存于自已的目录中
-
实例应当使用systemctl统一管理,并开机自启动
-
实例应当尽量设置回写规则,避免纯内存的使用方式,除非数据完全可丢失
-
Redis添加实例流程:
到目标服务器的 /srv/redis 目录下创建新实例的目录:mkdir {$端口号}
-
创建配置文件:cp /etc/redis.conf /srv/redis/{$端口号}
-
修改配置文件,需要修改的配置项至少包括:port, pidfile, logfile, dir, save, maxmemory, maxmemory-policy, daemon(设置为1),还应当按情况考虑需要不需要修改 bind 配置项的值
-
修改新实例目录和配置文件的权限:chown -R redis:redis /srv/redis/{$端口号}
-
启动新实例:systemctl start redis@{$端口号}
-
将新实例注册为服务:systemctl enable redis@{$端口号}
-
如果是测试环境需要对内网开放端口,还需要将新实例的端口添加到防火墙规则中:firewall-cmd --add-port=6383/tcp --permanent
Redis多实例管理脚本:
使用systemctl管理多个redis实例需要使用redis@.service脚本,可复制192.168.0.212:/lib/systemd/system/redis@.service到目标服务器的相同位置。
文件内容
[Unit]
Description=Redis(Port %I)
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)
[Service]
Type=forking
ExecStart=/usr/bin/redis-server /srv/redis/%I/redis.conf
PIDFile=/srv/redis/%I/redis.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
ExecStartPre=-/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d
ExecStartPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-up.d
ExecStop=-/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d
ExecStop=/bin/kill -s TERM $MAINPID
ExecStopPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-down.d
PrivateTmp=yes
PrivateDevices=yes
ProtectHome=yes
#ReadOnlyDirectories=/ #打开这一行开启会导致进程无法启动!
ReadWriteDirectories=-/srv/redis/%I
CapabilityBoundingSet=~CAP_SYS_PTRACE
# redis-server writes its own config file when in cluster mode so we allow
# writing there (NB. ProtectSystem=true over ProtectSystem=full)
ProtectSystem=true
#ReadWriteDirectories=-/etc/redis
[Install]
WantedBy=multi-user.target
#Alias=redis.service
centos7 Firewall防火墙开启80端口
centos7 默认是FirewallD 提供支持网络/防火墙区域(zone)定义网络链接以及接口安全等级的动态防火墙管理工具,利用FirewallD开启80端口操作如下:
开启80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
- 1
- 1
出现success表明添加成功
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
systemctl restart firewalld.service
- 1
- 1
1、运行、停止、禁用firewalld
启动:# systemctl start firewalld
查看状态:# systemctl status firewalld 或者 firewall-cmd –state
停止:# systemctl disable firewalld
禁用:# systemctl stop firewalld
2、配置firewalld
查看版本:$ firewall-cmd –version
查看帮助:$ firewall-cmd –help
查看设置:
显示状态:$ firewall-cmd –state
查看区域信息: $ 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 –reload
firewall-cmd –complete-reload
两者的区别就是第一个无需断开连接,就是firewalld特性之一动态添加规则,第二个需要断开连接,类似重启服务
将接口添加到区域,默认接口都在public
firewall-cmd –zone=public –add-interface=eth0
永久生效再加上 –permanent 然后reload防火墙
设置默认接口区域
firewall-cmd –set-default-zone=public
立即生效无需重启
打开端口(貌似这个才最常用)
查看所有打开的端口:
firewall-cmd –zone=dmz –list-ports
加入一个端口到区域:
firewall-cmd –zone=dmz –add-port=8080/tcp
若要永久生效方法同上
打开一个服务,类似于将端口可视化,服务需要在配置文件中添加,/etc/firewalld 目录下有services文件夹,这个不详细说了,详情参考文档
firewall-cmd –zone=work –add-service=smtp
移除服务
firewall-cmd –zone=work –remove-service=smtp
原文链接:http://www.zhaokeli.com/article/6321.html
附:systemctl命令如下
systemctl is-enabled iptables.service
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl –failed #显示启动失败的服务
注:*代表某个服务的名字,如http的服务名为httpd
centos7 安装php7+mysql5.7+nginx+redis
1.先修改yum源 https://webtatic.com
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
linux编译安装时常见错误解决办法
文链接:http://www.bkjia.com/PHPjc/1008013.html
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
代码如下:
yum -y install libxslt-devel
configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
代码如下:
yum -y install net-snmp-devel 继续阅读“linux编译安装时常见错误解决办法”
PHP 7 编译安装 cannot stat ‘phar.phar’: No such file or directory
PHP 出来了应该尝尝鲜, 结果编译没问题, 安装的时候报了如下错误
cp -pR -f phar.phar /usr/local/php7/bin/phar cp: cannot stat 'phar.phar': No such file or directory make: *** [install-pharcmd] Error 1
解决方法很简单:
find . -name 'phar.phar'
找到 phar.phar 文件, 移动或者复制到安装指令执行的目录下就行了.
最后附上, 完成后的执行指令:
解决ln -s 软链接产生Too many levels of symbolic links
今天在服务器上给nginx下的www目录创建软链接,后来cd到软链接目录的时候,报错了:Too many levels of symbolic links
原来是建立软连接的时候采用的是相对路径,所以才会产生这样的错误。
解决方案:是采用绝对路径建立软链接
ln -s /alidata/www/ /root/www
这样问题就解决了.
VMware下centos7安装VMware Tools
右键虚拟机设置,找到CD/DVD,选择使用ISO映像文件,在VMware安装目录下找到linux.iso。
1
|
> mount -t auto /dev/cdrom /mnt/cdrom |
如果/mnt下没有cdrom文件夹,则创建
1
2
|
> cd /mnt > mkdir cdrom |
1
2
|
> cd /mnt/cdrom > cp VMwareTools-10.0.10-4301679.tar.gz /data |
1
2
3
|
> tar -zxvf VMwareTools-10.0.10-4301679.tar.gz > cd vmware-tools-distrib > ./vmware-install.pl |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
Do you still want to proceed with this legacy installer? yes 看到如下信息一路回车默认就好了 Installing VMware Tools. In which directory do you want to install the binary files? [/usr/bin] What is the directory that contains the init directories (rc0.d/ to rc6.d/)? [/etc/rc.d] What is the directory that contains the init scripts? [/etc/rc.d/init.d] In which directory do you want to install the daemon files? [/usr/sbin] In which directory do you want to install the library files? [/usr/lib/vmware-tools] |
如果一直提示如下信息
What is the location of the “ifconfig” program on your machine?
请安装ifconfig,重新执行vmware-install.pl
1
2
|
> yum search ifconfig > yum install net-tools.x86_64 |
如果一直提示如下信息
The path “” is not a valid path to the 3.10.0-327.el7.x86_64 kernel headers.
Would you like to change it?
则需要安装
1
|
> yum install kernel-devel |
然后在上面的步骤里输入内核头文件的目录
1
|
/usr/src/kernels/3.10.0-327.36.3.el7.x86_64/ include |
如果出现如下信息
The path “/usr/src/kernels/3.10.0-327.36.3.el7.x86_64/include” is not a valid
path to the 3.10.0-327.el7.x86_64 kernel headers
1
2
|
> ln -s /usr/src/kernels/3.10.0-327.36.3.el7.x86_64/ include /generated/uapi/linux/version.h /usr/src/kernels/3.10.0-327.36.3.el7.x86_64/ include /linux/version.h |
此时如果你的vmtools版本比较旧的话,还是会提示not a valid path。
这是因为3.x版本的内核version.h的路径变了,导致vmtools无法找到。
安装vmtools 时提示The path “” is not a valid path to the 3.10.0-229.el7.x86_64 kernel headers. Would you like to change it?[yes]
原因:没有找到kernel的头文件。
解决法案:/usr/src 目录下有要求的kernel源文件,没有的话使用命令 yum -y install kernel-devel
然后在Enter the path to the kernel header files for the 3.10.0-229.el7.x86_64 kernel?这一步输入内核头文件的目录,我的是/usr/src/kernels/3.10.0-229.el7.x86_64/include。
此时如果你的vmtools版本比较旧的话,还是会提示not a valid path。这是因为3.x版本的内核version.h的路径变了,导致vmtools无法找到。
用命令 sudo ln -s <内核头文件目录>/generated/uapi/linux/version.h <内核头文件目录>/include/linux/version.h
我的是 sudo ln -s /usr/src/kernels/3.10.0-229.el7.x86_64/include/generated/uapi/linux/version.h /usr/src/kernels/3.10.0-229.el7.x86_64/include/linux/version.h
然后再次运行vmtools安装程序此问题不在出现。
1
2
3
|
Enjoy, --the VMware team Found VMware Tools CDROM mounted at /mnt/cdrom. Ejecting device /dev/sr0 ... |
1
2
|
> umount /mnt/cdrom > reboot |
virtualbox下centos挂载共享文件夹
1.设备—>共享文件夹
宿主机 共享路径:E:\project, 共享文件夹名称project
2. mkdir /mnt/share //新建挂载点(mountpoint)
mount -t vboxsf project /mnt/share // 挂载共享文件夹
cd /mnt/share 进入共享文件夹
OK
3.实现 开机挂载:
vi ~/.bashrc
在最后添加
mount -t vboxsf sharing /mnt/share 挂载共享文件夹