概述
整理的一份简单搭建通用流程,都可以实际运营使用,读者可以自取自己需要的部分
cd /usr/local
#安装nginx1.14
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y nginx
systemctl start nginx
systemctl enable nginx
#安装php7.2
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
yum install mod_php72w.x86_64 php72w-fpm.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysqlnd.x86_64 php72w-pdo.x86_64 php72w-pecl-redis.x86_64 php72w-pecl-mongodb.x86_64 php72w-opcache.x86_64 php72w-devel.x86_64 php72w-bcmath.x86_64
y
y
y
y
systemctl start php-fpm
systemctl enable php-fpm
如果rpm依赖错误可以尝试 --force --nodeps
#安装mysql5.7
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
systemctl start mysqld
systemctl enable mysqld
#mysql初始密码在/var/log/mysqld.log
grep "password" /var/log/mysqld.log #记住初始密码,示例sIZyvN5gWt<<
rm -f mysql57-community-release-el7-10.noarch.rpm
#安装redis5
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar zxf redis-5.0.3.tar.gz
yum install gcc
y
cd redis-5.0.3/
make
cd src && make install
cd /etc
mkdir redis
cp /usr/local/redis-5.0.3/redis.conf /etc/redis/6379.conf
cp /usr/local/redis-5.0.3/utils/redis_init_script /etc/init.d/redis
chkconfig redis on
cd /usr/local
rm -f redis-5.0.3.tar.gz
#安装vim
yum -y install vim
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#调整时间
yum -y install ntp
timedatectl set-timezone Asia/Shanghai #时区设置为上海
#自动调整时间
timedatectl set-ntp yes
#安装git
yum install git
adduser git
usermod -a -G root git
passwd git #为git设置密码
#建立若干个仓库
cd /home/git
mkdir simple.git
cd simple.git
git init --bare
cd ..
chown git:git * -R
#建立web运行环境
cd /usr
mkdir www
cd www
mkdir log
mkdir simple
#修改权限
cd /usr
chown git:git www -R
chmod 755 www -R
#将nginx的运行者改为git
###在nginx.conf中修改
user git; #以git身份运行
#测试配置
nginx -t
#测试成功重启
systemctl restart nginx
#将php-fpm的运行者改为git
cd /etc/php-fpm.d/
ll
##显示出www.conf文件
vim www.conf
#找到user和group改为:
user = git
group = git
#重启php-fpm
systemctl start php-fpm
#修改mysql默认密码
mysql -uroot -p
#输入默认密码进入mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password'; #设置密码,组合过于简单会报错
#修改一些常用配置,仅供参考:
[mysqld]
# 设置mysql数据库的数据的存放目录
datadir=/var/lib/mysql
# socket文件是在Linux环境下特有的,用户的客户端软件连接可以不通过TCP/IP网络而直接使用unix socket连接到Mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
group_concat_max_len = 102400
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 提高innodb引擎写入的效率
innodb_flush_log_at_trx_commit=2
# mysql不使用严格模式
# sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql_mode=NO_ENGINE_SUBSTITUTION
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
#将redis改为后台运行,配置文件etc/redis/6379.conf修改常用项,仅供参考:
daemonize yes #后台运行
# bind 127.0.0.1 #允许访问的ip,注释后运行所有
requirepass your@password #密码,注释掉或者留空将会无密码
protected-mode no
#重启redis
systemctl restart redis
#建立git免密连接
su - git #切换为git用户
cd /home/git
ssh-keygen -C 'viba_front@email.com' -t rsa #为你生成rsa密钥,可以直接一路回车,执行默认操作
vim /home/git/.ssh/authorized_keys #创建authorized_keys文件
###将需要连接的用户id_rsa.pub中的内容全部粘贴进去,保存
chmod 600 /home/git/.ssh/authorized_keys #修改权限
#重新连接切换为root用户,此处要确保RSA认证是打开的!
vim /etc/ssh/sshd_config #确保这三项是打开的:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#重启sshd
systemctl restart sshd
#建立git钩子自动部署,配置文件home/git/simple.git/hooks/post-receive,仅供参考
#!/bin/bash
DIR=/usr/www/simple #指定代码自动检出目录
git --work-tree=${DIR} clean -fd
git --work-tree=${DIR} checkout --force #直接强制检出默认分支
#给post-receive赋予执行权限
chmod +x /home/git/simple.git/hooks/post-receive
###以下根据需要安装
#安装composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
#安装mongodb
vim /etc/yum.repos.d/mongodb-org-4.2.repo
#按ESC+i 写入以下内容
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/
gpgcheck=0
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
#按ESC
:wq #回车键
yum makecache
yum -y install mongodb-org
systemctl start mongod
systemctl enable mongod
cd /usr/local
#安装C++(如果没有的话)
yum install gcc-c++
#安装openssl(如果没有的话)
yum install openssl openssl-devel
#安装rabbitmq
yum install erlang
y
wget -c http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-3.6.6-1.el7.noarch.rpm
yum -y install rabbitmq-server-3.6.6-1.el7.noarch.rpm
rm -f rabbitmq-server-3.6.6-1.el7.noarch.rpm
systemctl start rabbitmq-server
systemctl enable rabbitmq-server
#安装rabbitmq-c
yum install cmake
y
wget -c https://github.com/alanxz/rabbitmq-c/releases/download/v0.8.0/rabbitmq-c-0.8.0.tar.gz
tar zxf rabbitmq-c-0.8.0.tar.gz
cd rabbitmq-c-0.8.0/
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rabbitmq-c-0.8.0/ ..
cmake --build . --target install
cd /usr/local/rabbitmq-c-0.8.0
ln -s lib64 lib
cd /usr/local
rm -f rabbitmq-c-0.8.0.tar.gz
#安装php amq扩展
wget https://pecl.php.net/get/amqp-1.9.3.tgz
tar zxf amqp-1.9.3.tgz
cd amqp-1.9.3/
phpize
whereis php-config #查看php-config路径写入对应路径
./configure --with-php-config=/usr/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.8.0/
make && make install
vim /etc/php.ini
#添加 extension=amqp.so
rm -f amqp-1.9.3.tgz
#安装php yaf扩展
wget -c https://github.com/laruence/yaf/archive/yaf-3.0.7.tar.gz
tar xzvf yaf-3.0.7.tar.gz
cd yaf-yaf-3.0.7
phpize
./configure
make
make install
cd /usr/local/
rm -f yaf-3.0.7.tar.gz
rm -rf yaf-yaf-3.0.7
#安装swoole扩展
pecl install swoole
编译安装成功后,修改php.ini
加入
extension=swoole.so
通过php -m
或phpinfo()
来查看是否成功加载了swoole.so
如果出现错误找不到swoole.so,进入/etc/php.d/
vim sockets.ini
###加入如下内容###
extension=swoole.so
#安装php event扩展,为了workerman,**要先安装openssl!!!(文档中有写)**
yum install -y libevent-devel
pecl install event
#会出来很多选项,没把握的话一路回车选默认即可
###在php.ini添加下面配置,注意一定要把extension=sockets.so放在extension=event.so前面,否则会报错
[sockets]
extension=sockets.so #sockets.so要在event.so前面!!!
[event]
extension=event.so
#python3.7安装
cd /usr/local/
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar zxvf Python-3.7.5.tgz
cd Python-3.7.5
./configure --prefix=/usr/local/bin/python3
make
yum install libffi-devel #安装必要组件
make install
#添加软链接
方式1:python2和python3共存
ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip3
方式2:默认改为python3(不推荐)
rm -rf /usr/bin/python
ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip
#由于yum依赖python2.7,修复yum
#vim /usr/bin/yum将文件第一行改为/usr/bin/python2.7。(2.7.x也改为2.7)
#vim /usr/libexec/urlgrabber-ext-down 将文件第一行改为/usr/bin/python2.7。
##安装pip2
yum install python-pip
##安装爬虫插件Scrapy
pip install Scrapy
#安装supervisor
yum install epel-release
yum install -y supervisor
systemctl enable supervisord # 开机自启动
systemctl start supervisord # 启动supervisord服务
systemctl status supervisord # 查看supervisord服务状态
ps -ef|grep supervisord # 查看是否存在supervisord进程
supervisorctl reload # 重载配置
#go语言安装,版本可以自己去官网选择
cd /usr/local/
wget -i -c https://studygolang.com/dl/golang/go1.13.3.linux-amd64.tar.gz
tar -zxvf go1.13.3.linux-amd64.tar.gz
vim /etc/profile
###底部写入:
export GOROOT=/usr/local/go
export GOPATH=/usr/gopath
export PATH=$PATH:$GOROOT/bin
#让配置文件的环境变量立刻生效
source /etc/profile
go version
###显示版本
go version go1.13.3 linux/amd64
#基于go语言的beego框架安装
go get -u github.com/astaxie/beego
go get -u github.com/beego/bee
vim /etc/profile
###底部写入:
export PATH=$PATH:$GOPATH/bin
#让配置文件的环境变量立刻生效
source /etc/profile
#基于go语言的gin框架安装
go get -u github.com/gin-gonic/gin
最后
以上就是从容诺言为你收集整理的基于Centos7的web环境的简单搭建的全部内容,希望文章能够帮你解决基于Centos7的web环境的简单搭建所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复