挂载磁盘
参见文章https://www.psvmc.cn/article/2020-08-05-centos-disk.html
阿里YUM镜像
1) 备份
1 | mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup |
2) 下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 7
1
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
CentOS 6
1
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 5
1
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
3) 生成缓存
1 | yum makecache |
配置时间同步
- 安装chrony(时间同步客户端)
Centos/redhat/alios:
1 | yum install -y chrony |
ubuntu/debian:
1 | apt-get install chrony |
- 删除默认Server
1 | sed -i "/server/d" /etc/chrony.conf |
- 打开/etc/chrony.conf,新增一行
1 | vim /etc/chrony.conf |
添加
1 | server ntp.aliyun.com iburst |
- 重启chrony
1 | systemctl restart chronyd |
或者
1 | service chronyd restart |
- 查看是否正常
1 | chronyc tracking |
或
1 | date |
6.开机启动
CentOS7
1 | systemctl enable chronyd.service |
CentOS6
1 | chkconfig chronyd on |
服务操作命令
功能 | CentOS7 | CentOS6 |
---|---|---|
查看自启动服务 | ls /etc/systemd/system/multi-user.target.wants/ systemctl list-unit-files |
chkconfig –list |
开机自启 | systemctl enable nginx.service | chkconfig nginx on |
取消开机自启 | systemctl disable nginx.service | chkconfig nginx off |
启动服务 | systemctl start nginx.service | service nginx start |
停止服务 | systemctl stop nginx.service | service nginx stop |
重启服务 | systemctl restart nginx.service | service nginx restart |
加载失败的服务 | systemctl –failed | |
重新加载 | systemctl reload nginx.service | |
查看状态 | systemctl status nginx.service |
查看应用位置
1 | whereis nginx |
连接Linux
1 | ssh root@112.112.112.112 |
root
为用户名112.112.112.112
为服务器ip
重启系统
1 | reboot |
Memcached
安装Memcached
安装依赖
1 | yum install -y libevent libevent-deve |
安装MemCached
1 | yum install memcached |
运行Memcached
CentOS7
1 | systemctl restart memcached |
CentOS6
1 | service memcached start |
或者
1 | /usr/bin/memcached -p 11211 -u root -m 256 -c 10240 |
memcached的基本设置:
- -p 监听的端口
- -l 连接的IP地址, 默认是本机
- -d start 启动memcached服务
- -d restart 重起memcached服务
- -d stop|shutdown 关闭正在运行的memcached服务
- -d install 安装memcached服务
- -d uninstall 卸载memcached服务
- -u 以的身份运行 (仅在以root运行的时候有效)
- -m 最大内存使用,单位MB。默认64MB
- -M 内存耗尽时返回错误,而不是删除项
- -c 最大同时连接数,默认是1024
- -f 块大小增长因子,默认是1.25
- -n 最小分配空间,key+value+flags默认是48
- -h 显示帮助
配置路径
CentOS7
1 | vim /etc/sysconfig/memcached |
CentOS6
1 | vim /etc/init.d/memcached |
关闭
1 | pkill -9 memcached |
设置开机自启
CentOS7
1 | systemctl enable memcached.service |
CentOS6
1 | chkconfig memcached on |
取消开机启动
CentOS7
1 | systemctl disable memcached.service |
CentOS6
1 | chkconfig memcached off |
JDK
官方下载JDK 网址
或者 链接:https://pan.baidu.com/s/1JdPCMMEq178hXV5V4Ild3Q 密码:03l1
比如下载的文件为jdk-8u221-linux-x64.rpm
更改文件权限
1 | chmod 755 jdk-8u221-linux-x64.rpm |
安装
1 | rpm -ivh jdk-8u221-linux-x64.rpm |
安装后的路径为/usr/java/jdk1.8.0_221-amd64
删除文件
1 | rm -rf jdk-8u221-linux-x64.rpm |
查询java版本
1 | java -version |
查看java-home
1 | echo $JAVA_HOME |
为空的话要配置java-home
否则无法配置Tomcat
为服务
打开文件/etc/profile
1 | vi /etc/profile |
在profile
文件末尾加入:
1 | export JAVA_HOME=/usr/java/jdk1.8.0_221-amd64 |
配置立即生效
1 | source /etc/profile |
Tomcat7(yum方式)
查询
1 | yum list tomcat* |
安装
1 | yum -y install tomcat |
启动tomcat
1 | service tomcat start |
设为开机启动
1 | chkconfig tomcat on |
默认的tomcat文件夹路径
1 | cd /usr/share/tomcat |
Tomcat8(非yum方式)
(1)下载
下载地址不能用的话从http://tomcat.apache.org/
获取新地址
1 | wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz |
(2)安装
1 | tar -xzvf apache-tomcat-8.5.42.tar.gz |
运行
1 | cd /opt/tomcat8/bin |
(3)配置
在生产环境用 root 是不安全的,所以
1 | useradd -s /sbin/nologin tomcat |
为 service,和操作系统一起启动
1 | cd /opt/tomcat8/bin |
错误1
1 | configure: error: no acceptable C compiler found in $PATH |
解决1
1 | yum -y install gcc |
打开daemon.sh
1 | cd /opt/tomcat8/bin |
正文最开始也就是注释的下面增加下边五行内容
1 | # chkconfig: 2345 10 90 |
配置防止日志中文乱码
找到JAVA_OPTS=
修改为
1 | JAVA_OPTS="-Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8" |
保存并退出
1 | :wq |
增加到 service
1 | cp daemon.sh /etc/init.d/tomcat8 |
开机启动
1 | chkconfig tomcat8 on |
检查
1 | chkconfig --list|grep tomcat8 |
启动服务
1 | service tomcat8 start |
删除服务
1 | service tomcat8 stop |
防火墙添加信任规则
打开文件
1 | vim /etc/sysconfig/iptables |
添加规则
1 | -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT |
重启防火墙
1 | service iptables restart |
Apache
安装Apache
1 | yum install httpd httpd-devel |
卸载
1 | yum -y remove httpd* |
启动apache
1 | service httpd start |
设为开机启动
1 | chkconfig httpd on |
重新加载配置
1 | service httpd reload |
查看版本
1 | httpd -v |
配置 文件位置/etc/httpd/conf/httpd.conf
设置虚拟主机目录
在文件的最后添加
1 | Listen 9999 |
PHP5.4
添加源
1
wget -q -O - http://www.atomicorp.com/installers/atomic | sh
安装
1
yum install php php-cli php-gd php-mysql php-eaccelerator php-zend-optimizer php-pear php-snmp php-bcmath php-mcrypt php-mhash php-soap php-xml php-xmlrpc
查询版本
1
yum info php | grep Version
服务器安全软件(安装其一)
安全狗
下载并安装
1 | wget http://down.safedog.cn/safedog_linux64.tar.gz |
上一步中安装时缺少组件安装
- Need system command ‘locate’ to install safedog for linux.
yum install -y mlocate
- Need system command ‘lsof’ to install safedog for linux.
yum install -y lsof
- Need system command ‘dmidecode’ to install safedog for linux.
yum install -y dmidecode
- Need system command ‘lspci’ to install safedog for linux.
yum install -y pciutils
登录账号(暂时登不了)
1 | sdcloud -u 服云帐号 |
进入操作界面
1 | sdui |
悬镜
一键安装
1 | wget -O install.sh http://dl.xmirror.cn/a/install.sh && sh install.sh |