背景
好久没有装过系统和开发环境了,今天在重新学习一下,把坑踩一下
环境
操作系统:centos7.6(在vmware12 pro安装的虚拟机)
nginx版本:1.14.0
mysql版本:5.7.20
php版本:7.2.6
操作系统安装完成后的问题
- ping或者wget网址时,发现总是报错:未解析的域名,刚开始以为是dns有问题,后来发现是nat网络模式下网卡没有开启导致的(因为我是先按照网上修改的dns然后发现不行,然后开启的网卡,如果你们发现网卡设置不行,就把dns设置一下),
// 开启网卡的办法 1. ifconfig // 查看网卡名是什么,我这里是ens33 2. cd /etc/sysconfig/network-scripts/ // 在该目录下找到ifcfg-ens33 3. vi ifcfg-ens33 // 将里面的配置的onboot="no" 改为yes 4. service network restart 5. ping www.baidu.com //测试一下网络可以没有 // 设置dns 1. vi /etc/resolv.conf 2. 添加 nameserver 8.8.8.8 //这里可以添加你的网络服务商的dns
- 设置yum的软件源,在安装系统时,忘记设置软件源了,所以无法安装和更新软件,我设置的时阿里云的软件源,参考文章:https://www.cnblogs.com/wyt007/p/9080372.html
// 安装base reop源 1. cd /etc/yum.repos.d 2. sudo mv CentOS-Base.repo CentOS-Base.repo.bak 3. sudo wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo // 安装epel repo源 选择其中一条执行(我三条都执行了,最后执行的RHEL 5,但是阿里云没有5的xml文件了,导致一直安装软件失败,因为下面三条语句都是设置相同的文件内容,只是版本不一样,我后来又把7执行以下就好了) epel(RHEL 7): wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo epel(RHEL 6): wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo epel(RHEL 5): wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo // 清理缓存 yum clean all // 重新生成缓存 yum makecache
安装gperftools(TCMalloc)来优化nginx和mysql
-
简介
TCMalloc(Thread-Caching Malloc)与标准glibc库的malloc实现一样的功能,但是TCMalloc在效率和速度效率都比标准malloc高很多。TCMalloc是google-perftools工具中的一个(gperftools四个工具分别是:TCMalloc、heap-checker、heap-profiler和cpu-profiler),这个工具是开源的,以源码形式发布。如果觉得自己维护一个内存分配器麻烦的话,可以考虑将TCMalloc静态库连接到你的程序中。使用的时候和glibc中的malloc调用方式一模一样。你需要做的只是把TCMalloc的动态库或者静态库连接进你的程序中,你就可以获得一个高效,快速,安全的内存分配器。与标准的glibc库的malloc相比,TCMalloc在内存的分配效率和速度要高,可以在高并发的情况下很好的控制内存的使用,提高服务器的性能,降低负载。
-
安装
- 如果系统是64位的需要先安装libunwind库,32位系统则不需要安装。
[root@ ~]# wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz [root@ ~]# tar zxf libunwind-1.1.tar.gz [root@ ~]# cd libunwind-1.1 [root@ libunwind-1.1]# CFLAGS=-fPIC ./configure [root@ libunwind-1.1]# make CFLAGS=-fPIC [root@ libunwind-1.1]# make CFLAGS=-fPIC install
- 安装gperftools
[root@ ~]# wget http://gperftools.googlecode.com/files/gperftools-2.1.tar.gz
[root@ ~]# tar xzf gperftools-2.1.tar.gz
[root@ ~]# cd gperftools-2.1
[root@ gperftools-2.1]#./configure
[root@ gperftools-2.1]#make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
[root@ gperftools-2.1]# ldconfig
上面再使用wget获取tar包时,因为没有代理,无法访问谷歌,所以使用github上面的包,如下命令
git clone https://github.com/gperftools/gperftools.git
./autogen.sh
./configure # 这里可能报错:configure.ac:17: error: possibly undefined macro: AC_PROG_LIBTOOL,执行yum install -y libtool libsysfs-dev
make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.